]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.3-201303190012.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.3-201303190012.patch
CommitLineData
2d758307
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 8c49fc9b..9a2af09 100644
263--- a/Makefile
264+++ b/Makefile
265@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
266
267 HOSTCC = gcc
268 HOSTCXX = g++
269-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
270-HOSTCXXFLAGS = -O2
271+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
272+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
273+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
274
275 # Decide whether to build built-in, modular, or both.
276 # Normally, just do built-in.
277@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
278 # Rules shared between *config targets and build targets
279
280 # Basic helpers built in scripts/
281-PHONY += scripts_basic
282-scripts_basic:
283+PHONY += scripts_basic gcc-plugins
284+scripts_basic: gcc-plugins
285 $(Q)$(MAKE) $(build)=scripts/basic
286 $(Q)rm -f .tmp_quiet_recordmcount
287
288@@ -575,6 +576,62 @@ else
289 KBUILD_CFLAGS += -O2
290 endif
291
292+ifndef DISABLE_PAX_PLUGINS
293+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
294+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
295+else
296+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
297+endif
298+ifneq ($(PLUGINCC),)
299+ifndef CONFIG_UML
300+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
301+endif
302+ifdef CONFIG_PAX_MEMORY_STACKLEAK
303+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
304+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
305+endif
306+ifdef CONFIG_KALLOCSTAT_PLUGIN
307+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
308+endif
309+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
310+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
311+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
312+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
313+endif
314+ifdef CONFIG_CHECKER_PLUGIN
315+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
316+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
317+endif
318+endif
319+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
320+ifdef CONFIG_PAX_SIZE_OVERFLOW
321+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
322+endif
323+ifdef CONFIG_PAX_LATENT_ENTROPY
324+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
325+endif
326+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
327+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
328+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
329+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
330+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
331+ifeq ($(KBUILD_EXTMOD),)
332+gcc-plugins:
333+ $(Q)$(MAKE) $(build)=tools/gcc
334+else
335+gcc-plugins: ;
336+endif
337+else
338+gcc-plugins:
339+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
340+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
341+else
342+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
343+endif
344+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
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..a06a6f5 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,27 @@ 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+<<<<<<< HEAD
3698+ if (current->signal->curr_ip)
3699+ 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),
3700+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3701+ else
3702+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3703+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3704+=======
3705+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3706+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3707+>>>>>>> c57d8557f5f2d77c2c7fa1f58316819a5e1f9293
3708+ goto die;
3709+ }
3710+#endif
3711+
3712 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3713 return;
3714
3715+die:
3716 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3717 inf->name, fsr, addr);
3718
3719@@ -575,9 +642,58 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3720 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3721 struct siginfo info;
3722
3723+ if (user_mode(regs)) {
3724+ if (addr == 0xffff0fe0UL) {
3725+ /*
3726+ * PaX: __kuser_get_tls emulation
3727+ */
3728+ regs->ARM_r0 = current_thread_info()->tp_value;
3729+ regs->ARM_pc = regs->ARM_lr;
3730+ return;
3731+ }
3732+ }
3733+
3734+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3735+<<<<<<< HEAD
3736+ if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3737+ if (current->signal->curr_ip)
3738+ 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),
3739+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3740+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3741+ else
3742+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3743+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3744+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3745+=======
3746+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3747+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
3748+ current->comm, task_pid_nr(current),
3749+ from_kuid_munged(&init_user_ns, current_uid()),
3750+ from_kuid_munged(&init_user_ns, current_euid()),
3751+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3752+>>>>>>> c57d8557f5f2d77c2c7fa1f58316819a5e1f9293
3753+ goto die;
3754+ }
3755+#endif
3756+
3757+#ifdef CONFIG_PAX_REFCOUNT
3758+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3759+ unsigned int bkpt;
3760+
3761+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3762+ current->thread.error_code = ifsr;
3763+ current->thread.trap_no = 0;
3764+ pax_report_refcount_overflow(regs);
3765+ fixup_exception(regs);
3766+ return;
3767+ }
3768+ }
3769+#endif
3770+
3771 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3772 return;
3773
3774+die:
3775 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3776 inf->name, ifsr, addr);
3777
3778diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3779index cf08bdf..772656c 100644
3780--- a/arch/arm/mm/fault.h
3781+++ b/arch/arm/mm/fault.h
3782@@ -3,6 +3,7 @@
3783
3784 /*
3785 * Fault status register encodings. We steal bit 31 for our own purposes.
3786+ * Set when the FSR value is from an instruction fault.
3787 */
3788 #define FSR_LNX_PF (1 << 31)
3789 #define FSR_WRITE (1 << 11)
3790@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3791 }
3792 #endif
3793
3794+/* valid for LPAE and !LPAE */
3795+static inline int is_xn_fault(unsigned int fsr)
3796+{
3797+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3798+}
3799+
3800+static inline int is_domain_fault(unsigned int fsr)
3801+{
3802+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3803+}
3804+
3805 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3806 unsigned long search_exception_table(unsigned long addr);
3807
3808diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3809index ad722f1..763fdd3 100644
3810--- a/arch/arm/mm/init.c
3811+++ b/arch/arm/mm/init.c
3812@@ -30,6 +30,8 @@
3813 #include <asm/setup.h>
3814 #include <asm/tlb.h>
3815 #include <asm/fixmap.h>
3816+#include <asm/system_info.h>
3817+#include <asm/cp15.h>
3818
3819 #include <asm/mach/arch.h>
3820 #include <asm/mach/map.h>
3821@@ -736,7 +738,46 @@ void free_initmem(void)
3822 {
3823 #ifdef CONFIG_HAVE_TCM
3824 extern char __tcm_start, __tcm_end;
3825+#endif
3826
3827+#ifdef CONFIG_PAX_KERNEXEC
3828+ unsigned long addr;
3829+ pgd_t *pgd;
3830+ pud_t *pud;
3831+ pmd_t *pmd;
3832+ int cpu_arch = cpu_architecture();
3833+ unsigned int cr = get_cr();
3834+
3835+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3836+ /* make pages tables, etc before .text NX */
3837+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3838+ pgd = pgd_offset_k(addr);
3839+ pud = pud_offset(pgd, addr);
3840+ pmd = pmd_offset(pud, addr);
3841+ __section_update(pmd, addr, PMD_SECT_XN);
3842+ }
3843+ /* make init NX */
3844+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3845+ pgd = pgd_offset_k(addr);
3846+ pud = pud_offset(pgd, addr);
3847+ pmd = pmd_offset(pud, addr);
3848+ __section_update(pmd, addr, PMD_SECT_XN);
3849+ }
3850+ /* make kernel code/rodata RX */
3851+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3852+ pgd = pgd_offset_k(addr);
3853+ pud = pud_offset(pgd, addr);
3854+ pmd = pmd_offset(pud, addr);
3855+#ifdef CONFIG_ARM_LPAE
3856+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3857+#else
3858+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3859+#endif
3860+ }
3861+ }
3862+#endif
3863+
3864+#ifdef CONFIG_HAVE_TCM
3865 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3866 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3867 __phys_to_pfn(__pa(&__tcm_end)),
3868diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3869index 88fd86c..7a224ce 100644
3870--- a/arch/arm/mm/ioremap.c
3871+++ b/arch/arm/mm/ioremap.c
3872@@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3873 unsigned int mtype;
3874
3875 if (cached)
3876- mtype = MT_MEMORY;
3877+ mtype = MT_MEMORY_RX;
3878 else
3879- mtype = MT_MEMORY_NONCACHED;
3880+ mtype = MT_MEMORY_NONCACHED_RX;
3881
3882 return __arm_ioremap_caller(phys_addr, size, mtype,
3883 __builtin_return_address(0));
3884diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3885index 10062ce..aa96dd7 100644
3886--- a/arch/arm/mm/mmap.c
3887+++ b/arch/arm/mm/mmap.c
3888@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3889 struct vm_area_struct *vma;
3890 int do_align = 0;
3891 int aliasing = cache_is_vipt_aliasing();
3892+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3893 struct vm_unmapped_area_info info;
3894
3895 /*
3896@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3897 if (len > TASK_SIZE)
3898 return -ENOMEM;
3899
3900+#ifdef CONFIG_PAX_RANDMMAP
3901+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3902+#endif
3903+
3904 if (addr) {
3905 if (do_align)
3906 addr = COLOUR_ALIGN(addr, pgoff);
3907@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3908 addr = PAGE_ALIGN(addr);
3909
3910 vma = find_vma(mm, addr);
3911- if (TASK_SIZE - len >= addr &&
3912- (!vma || addr + len <= vma->vm_start))
3913+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3914 return addr;
3915 }
3916
3917@@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3918 unsigned long addr = addr0;
3919 int do_align = 0;
3920 int aliasing = cache_is_vipt_aliasing();
3921+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3922 struct vm_unmapped_area_info info;
3923
3924 /*
3925@@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3926 return addr;
3927 }
3928
3929+#ifdef CONFIG_PAX_RANDMMAP
3930+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3931+#endif
3932+
3933 /* requesting a specific address */
3934 if (addr) {
3935 if (do_align)
3936@@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3937 else
3938 addr = PAGE_ALIGN(addr);
3939 vma = find_vma(mm, addr);
3940- if (TASK_SIZE - len >= addr &&
3941- (!vma || addr + len <= vma->vm_start))
3942+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3943 return addr;
3944 }
3945
3946@@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3947 VM_BUG_ON(addr != -ENOMEM);
3948 info.flags = 0;
3949 info.low_limit = mm->mmap_base;
3950+
3951+#ifdef CONFIG_PAX_RANDMMAP
3952+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3953+ info.low_limit += mm->delta_mmap;
3954+#endif
3955+
3956 info.high_limit = TASK_SIZE;
3957 addr = vm_unmapped_area(&info);
3958 }
3959@@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3960 {
3961 unsigned long random_factor = 0UL;
3962
3963+#ifdef CONFIG_PAX_RANDMMAP
3964+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3965+#endif
3966+
3967 /* 8 bits of randomness in 20 address space bits */
3968 if ((current->flags & PF_RANDOMIZE) &&
3969 !(current->personality & ADDR_NO_RANDOMIZE))
3970@@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3971
3972 if (mmap_is_legacy()) {
3973 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3974+
3975+#ifdef CONFIG_PAX_RANDMMAP
3976+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3977+ mm->mmap_base += mm->delta_mmap;
3978+#endif
3979+
3980 mm->get_unmapped_area = arch_get_unmapped_area;
3981 mm->unmap_area = arch_unmap_area;
3982 } else {
3983 mm->mmap_base = mmap_base(random_factor);
3984+
3985+#ifdef CONFIG_PAX_RANDMMAP
3986+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3987+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3988+#endif
3989+
3990 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3991 mm->unmap_area = arch_unmap_area_topdown;
3992 }
3993diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3994index ce328c7..35b88dc 100644
3995--- a/arch/arm/mm/mmu.c
3996+++ b/arch/arm/mm/mmu.c
3997@@ -35,6 +35,23 @@
3998
3999 #include "mm.h"
4000
4001+
4002+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4003+void modify_domain(unsigned int dom, unsigned int type)
4004+{
4005+ struct thread_info *thread = current_thread_info();
4006+ unsigned int domain = thread->cpu_domain;
4007+ /*
4008+ * DOMAIN_MANAGER might be defined to some other value,
4009+ * use the arch-defined constant
4010+ */
4011+ domain &= ~domain_val(dom, 3);
4012+ thread->cpu_domain = domain | domain_val(dom, type);
4013+ set_domain(thread->cpu_domain);
4014+}
4015+EXPORT_SYMBOL(modify_domain);
4016+#endif
4017+
4018 /*
4019 * empty_zero_page is a special page that is used for
4020 * zero-initialized data and COW.
4021@@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
4022 }
4023 #endif
4024
4025-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4026+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4027 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4028
4029-static struct mem_type mem_types[] = {
4030+#ifdef CONFIG_PAX_KERNEXEC
4031+#define L_PTE_KERNEXEC L_PTE_RDONLY
4032+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4033+#else
4034+#define L_PTE_KERNEXEC L_PTE_DIRTY
4035+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4036+#endif
4037+
4038+static struct mem_type mem_types[] __read_only = {
4039 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4040 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4041 L_PTE_SHARED,
4042@@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
4043 [MT_UNCACHED] = {
4044 .prot_pte = PROT_PTE_DEVICE,
4045 .prot_l1 = PMD_TYPE_TABLE,
4046- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4047+ .prot_sect = PROT_SECT_DEVICE,
4048 .domain = DOMAIN_IO,
4049 },
4050 [MT_CACHECLEAN] = {
4051- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4052+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4053 .domain = DOMAIN_KERNEL,
4054 },
4055 #ifndef CONFIG_ARM_LPAE
4056 [MT_MINICLEAN] = {
4057- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4058+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4059 .domain = DOMAIN_KERNEL,
4060 },
4061 #endif
4062@@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
4063 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4064 L_PTE_RDONLY,
4065 .prot_l1 = PMD_TYPE_TABLE,
4066- .domain = DOMAIN_USER,
4067+ .domain = DOMAIN_VECTORS,
4068 },
4069 [MT_HIGH_VECTORS] = {
4070 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4071- L_PTE_USER | L_PTE_RDONLY,
4072+ L_PTE_RDONLY,
4073 .prot_l1 = PMD_TYPE_TABLE,
4074- .domain = DOMAIN_USER,
4075+ .domain = DOMAIN_VECTORS,
4076 },
4077- [MT_MEMORY] = {
4078+ [MT_MEMORY_RWX] = {
4079 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4080 .prot_l1 = PMD_TYPE_TABLE,
4081 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4082 .domain = DOMAIN_KERNEL,
4083 },
4084+ [MT_MEMORY_RW] = {
4085+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4086+ .prot_l1 = PMD_TYPE_TABLE,
4087+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4088+ .domain = DOMAIN_KERNEL,
4089+ },
4090+ [MT_MEMORY_RX] = {
4091+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4092+ .prot_l1 = PMD_TYPE_TABLE,
4093+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4094+ .domain = DOMAIN_KERNEL,
4095+ },
4096 [MT_ROM] = {
4097- .prot_sect = PMD_TYPE_SECT,
4098+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4099 .domain = DOMAIN_KERNEL,
4100 },
4101- [MT_MEMORY_NONCACHED] = {
4102+ [MT_MEMORY_NONCACHED_RW] = {
4103 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4104 L_PTE_MT_BUFFERABLE,
4105 .prot_l1 = PMD_TYPE_TABLE,
4106 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4107 .domain = DOMAIN_KERNEL,
4108 },
4109+ [MT_MEMORY_NONCACHED_RX] = {
4110+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4111+ L_PTE_MT_BUFFERABLE,
4112+ .prot_l1 = PMD_TYPE_TABLE,
4113+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4114+ .domain = DOMAIN_KERNEL,
4115+ },
4116 [MT_MEMORY_DTCM] = {
4117- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4118- L_PTE_XN,
4119+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4120 .prot_l1 = PMD_TYPE_TABLE,
4121- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4122+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4123 .domain = DOMAIN_KERNEL,
4124 },
4125 [MT_MEMORY_ITCM] = {
4126@@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
4127 },
4128 [MT_MEMORY_SO] = {
4129 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4130- L_PTE_MT_UNCACHED | L_PTE_XN,
4131+ L_PTE_MT_UNCACHED,
4132 .prot_l1 = PMD_TYPE_TABLE,
4133 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4134- PMD_SECT_UNCACHED | PMD_SECT_XN,
4135+ PMD_SECT_UNCACHED,
4136 .domain = DOMAIN_KERNEL,
4137 },
4138 [MT_MEMORY_DMA_READY] = {
4139@@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
4140 * to prevent speculative instruction fetches.
4141 */
4142 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4143+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4144 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4145+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4146 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4147+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4148 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4149+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4150+
4151+ /* Mark other regions on ARMv6+ as execute-never */
4152+
4153+#ifdef CONFIG_PAX_KERNEXEC
4154+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4155+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4156+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4157+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4158+#ifndef CONFIG_ARM_LPAE
4159+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4160+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4161+#endif
4162+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4163+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4164+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4165+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4166+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4167+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4168+#endif
4169+
4170+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4171+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4172 }
4173 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4174 /*
4175@@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
4176 * from SVC mode and no access from userspace.
4177 */
4178 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4179+#ifdef CONFIG_PAX_KERNEXEC
4180+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4181+#endif
4182 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4183 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4184 #endif
4185@@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
4186 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4187 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4188 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4189- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4190- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4191+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4192+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4193+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4194+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4195+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4196+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4197 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4198- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4199- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4200+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4201+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4202+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4203+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4204 }
4205 }
4206
4207@@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
4208 if (cpu_arch >= CPU_ARCH_ARMv6) {
4209 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4210 /* Non-cacheable Normal is XCB = 001 */
4211- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4212+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4213+ PMD_SECT_BUFFERED;
4214+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4215 PMD_SECT_BUFFERED;
4216 } else {
4217 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4218- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4219+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4220+ PMD_SECT_TEX(1);
4221+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4222 PMD_SECT_TEX(1);
4223 }
4224 } else {
4225- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4226+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4227+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4228 }
4229
4230 #ifdef CONFIG_ARM_LPAE
4231@@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
4232 vecs_pgprot |= PTE_EXT_AF;
4233 #endif
4234
4235+ user_pgprot |= __supported_pte_mask;
4236+
4237 for (i = 0; i < 16; i++) {
4238 pteval_t v = pgprot_val(protection_map[i]);
4239 protection_map[i] = __pgprot(v | user_pgprot);
4240@@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
4241
4242 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4243 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4244- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4245- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4246+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4247+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4248+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4249+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4250+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4251+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4252 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4253- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4254+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4255+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4256 mem_types[MT_ROM].prot_sect |= cp->pmd;
4257
4258 switch (cp->pmd) {
4259@@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
4260 * called function. This means you can't use any function or debugging
4261 * method which may touch any device, otherwise the kernel _will_ crash.
4262 */
4263+
4264+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4265+
4266 static void __init devicemaps_init(struct machine_desc *mdesc)
4267 {
4268 struct map_desc map;
4269 unsigned long addr;
4270- void *vectors;
4271
4272- /*
4273- * Allocate the vector page early.
4274- */
4275- vectors = early_alloc(PAGE_SIZE);
4276-
4277- early_trap_init(vectors);
4278+ early_trap_init(&vectors);
4279
4280 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4281 pmd_clear(pmd_off_k(addr));
4282@@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4283 * location (0xffff0000). If we aren't using high-vectors, also
4284 * create a mapping at the low-vectors virtual address.
4285 */
4286- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4287+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4288 map.virtual = 0xffff0000;
4289 map.length = PAGE_SIZE;
4290 map.type = MT_HIGH_VECTORS;
4291@@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
4292 map.pfn = __phys_to_pfn(start);
4293 map.virtual = __phys_to_virt(start);
4294 map.length = end - start;
4295- map.type = MT_MEMORY;
4296
4297+#ifdef CONFIG_PAX_KERNEXEC
4298+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4299+ struct map_desc kernel;
4300+ struct map_desc initmap;
4301+
4302+ /* when freeing initmem we will make this RW */
4303+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4304+ initmap.virtual = (unsigned long)__init_begin;
4305+ initmap.length = _sdata - __init_begin;
4306+ initmap.type = MT_MEMORY_RWX;
4307+ create_mapping(&initmap);
4308+
4309+ /* when freeing initmem we will make this RX */
4310+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4311+ kernel.virtual = (unsigned long)_stext;
4312+ kernel.length = __init_begin - _stext;
4313+ kernel.type = MT_MEMORY_RWX;
4314+ create_mapping(&kernel);
4315+
4316+ if (map.virtual < (unsigned long)_stext) {
4317+ map.length = (unsigned long)_stext - map.virtual;
4318+ map.type = MT_MEMORY_RWX;
4319+ create_mapping(&map);
4320+ }
4321+
4322+ map.pfn = __phys_to_pfn(__pa(_sdata));
4323+ map.virtual = (unsigned long)_sdata;
4324+ map.length = end - __pa(_sdata);
4325+ }
4326+#endif
4327+
4328+ map.type = MT_MEMORY_RW;
4329 create_mapping(&map);
4330 }
4331 }
4332diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4333index 6d98c13..3cfb174 100644
4334--- a/arch/arm/mm/proc-v7-2level.S
4335+++ b/arch/arm/mm/proc-v7-2level.S
4336@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4337 tst r1, #L_PTE_XN
4338 orrne r3, r3, #PTE_EXT_XN
4339
4340+ tst r1, #L_PTE_PXN
4341+ orrne r3, r3, #PTE_EXT_PXN
4342+
4343 tst r1, #L_PTE_YOUNG
4344 tstne r1, #L_PTE_VALID
4345 #ifndef CONFIG_CPU_USE_DOMAINS
4346diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4347index a5bc92d..0bb4730 100644
4348--- a/arch/arm/plat-omap/sram.c
4349+++ b/arch/arm/plat-omap/sram.c
4350@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4351 * Looks like we need to preserve some bootloader code at the
4352 * beginning of SRAM for jumping to flash for reboot to work...
4353 */
4354+ pax_open_kernel();
4355 memset_io(omap_sram_base + omap_sram_skip, 0,
4356 omap_sram_size - omap_sram_skip);
4357+ pax_close_kernel();
4358 }
4359diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4360index f5144cd..71f6d1f 100644
4361--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4362+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4363@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4364 int (*started)(unsigned ch);
4365 int (*flush)(unsigned ch);
4366 int (*stop)(unsigned ch);
4367-};
4368+} __no_const;
4369
4370 extern void *samsung_dmadev_get_ops(void);
4371 extern void *s3c_dma_get_ops(void);
4372diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4373index 0c3ba9f..95722b3 100644
4374--- a/arch/arm64/kernel/debug-monitors.c
4375+++ b/arch/arm64/kernel/debug-monitors.c
4376@@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4377 return NOTIFY_OK;
4378 }
4379
4380-static struct notifier_block __cpuinitdata os_lock_nb = {
4381+static struct notifier_block os_lock_nb = {
4382 .notifier_call = os_lock_notify,
4383 };
4384
4385diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4386index 5ab825c..96aaec8 100644
4387--- a/arch/arm64/kernel/hw_breakpoint.c
4388+++ b/arch/arm64/kernel/hw_breakpoint.c
4389@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4390 return NOTIFY_OK;
4391 }
4392
4393-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4394+static struct notifier_block hw_breakpoint_reset_nb = {
4395 .notifier_call = hw_breakpoint_reset_notify,
4396 };
4397
4398diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4399index c3a58a1..78fbf54 100644
4400--- a/arch/avr32/include/asm/cache.h
4401+++ b/arch/avr32/include/asm/cache.h
4402@@ -1,8 +1,10 @@
4403 #ifndef __ASM_AVR32_CACHE_H
4404 #define __ASM_AVR32_CACHE_H
4405
4406+#include <linux/const.h>
4407+
4408 #define L1_CACHE_SHIFT 5
4409-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4410+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4411
4412 /*
4413 * Memory returned by kmalloc() may be used for DMA, so we must make
4414diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4415index e2c3287..6c4f98c 100644
4416--- a/arch/avr32/include/asm/elf.h
4417+++ b/arch/avr32/include/asm/elf.h
4418@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4419 the loader. We need to make sure that it is out of the way of the program
4420 that it will "exec", and that there is sufficient room for the brk. */
4421
4422-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4423+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4424
4425+#ifdef CONFIG_PAX_ASLR
4426+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4427+
4428+#define PAX_DELTA_MMAP_LEN 15
4429+#define PAX_DELTA_STACK_LEN 15
4430+#endif
4431
4432 /* This yields a mask that user programs can use to figure out what
4433 instruction set this CPU supports. This could be done in user space,
4434diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4435index 479330b..53717a8 100644
4436--- a/arch/avr32/include/asm/kmap_types.h
4437+++ b/arch/avr32/include/asm/kmap_types.h
4438@@ -2,9 +2,9 @@
4439 #define __ASM_AVR32_KMAP_TYPES_H
4440
4441 #ifdef CONFIG_DEBUG_HIGHMEM
4442-# define KM_TYPE_NR 29
4443+# define KM_TYPE_NR 30
4444 #else
4445-# define KM_TYPE_NR 14
4446+# define KM_TYPE_NR 15
4447 #endif
4448
4449 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4450diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4451index b2f2d2d..d1c85cb 100644
4452--- a/arch/avr32/mm/fault.c
4453+++ b/arch/avr32/mm/fault.c
4454@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4455
4456 int exception_trace = 1;
4457
4458+#ifdef CONFIG_PAX_PAGEEXEC
4459+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4460+{
4461+ unsigned long i;
4462+
4463+ printk(KERN_ERR "PAX: bytes at PC: ");
4464+ for (i = 0; i < 20; i++) {
4465+ unsigned char c;
4466+ if (get_user(c, (unsigned char *)pc+i))
4467+ printk(KERN_CONT "???????? ");
4468+ else
4469+ printk(KERN_CONT "%02x ", c);
4470+ }
4471+ printk("\n");
4472+}
4473+#endif
4474+
4475 /*
4476 * This routine handles page faults. It determines the address and the
4477 * problem, and then passes it off to one of the appropriate routines.
4478@@ -174,6 +191,16 @@ bad_area:
4479 up_read(&mm->mmap_sem);
4480
4481 if (user_mode(regs)) {
4482+
4483+#ifdef CONFIG_PAX_PAGEEXEC
4484+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4485+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4486+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4487+ do_group_exit(SIGKILL);
4488+ }
4489+ }
4490+#endif
4491+
4492 if (exception_trace && printk_ratelimit())
4493 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4494 "sp %08lx ecr %lu\n",
4495diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4496index 568885a..f8008df 100644
4497--- a/arch/blackfin/include/asm/cache.h
4498+++ b/arch/blackfin/include/asm/cache.h
4499@@ -7,6 +7,7 @@
4500 #ifndef __ARCH_BLACKFIN_CACHE_H
4501 #define __ARCH_BLACKFIN_CACHE_H
4502
4503+#include <linux/const.h>
4504 #include <linux/linkage.h> /* for asmlinkage */
4505
4506 /*
4507@@ -14,7 +15,7 @@
4508 * Blackfin loads 32 bytes for cache
4509 */
4510 #define L1_CACHE_SHIFT 5
4511-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4512+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4513 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4514
4515 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4516diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4517index aea2718..3639a60 100644
4518--- a/arch/cris/include/arch-v10/arch/cache.h
4519+++ b/arch/cris/include/arch-v10/arch/cache.h
4520@@ -1,8 +1,9 @@
4521 #ifndef _ASM_ARCH_CACHE_H
4522 #define _ASM_ARCH_CACHE_H
4523
4524+#include <linux/const.h>
4525 /* Etrax 100LX have 32-byte cache-lines. */
4526-#define L1_CACHE_BYTES 32
4527 #define L1_CACHE_SHIFT 5
4528+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4529
4530 #endif /* _ASM_ARCH_CACHE_H */
4531diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4532index 7caf25d..ee65ac5 100644
4533--- a/arch/cris/include/arch-v32/arch/cache.h
4534+++ b/arch/cris/include/arch-v32/arch/cache.h
4535@@ -1,11 +1,12 @@
4536 #ifndef _ASM_CRIS_ARCH_CACHE_H
4537 #define _ASM_CRIS_ARCH_CACHE_H
4538
4539+#include <linux/const.h>
4540 #include <arch/hwregs/dma.h>
4541
4542 /* A cache-line is 32 bytes. */
4543-#define L1_CACHE_BYTES 32
4544 #define L1_CACHE_SHIFT 5
4545+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4546
4547 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4548
4549diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4550index b86329d..6709906 100644
4551--- a/arch/frv/include/asm/atomic.h
4552+++ b/arch/frv/include/asm/atomic.h
4553@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4554 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4555 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4556
4557+#define atomic64_read_unchecked(v) atomic64_read(v)
4558+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4559+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4560+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4561+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4562+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4563+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4564+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4565+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4566+
4567 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4568 {
4569 int c, old;
4570diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4571index 2797163..c2a401d 100644
4572--- a/arch/frv/include/asm/cache.h
4573+++ b/arch/frv/include/asm/cache.h
4574@@ -12,10 +12,11 @@
4575 #ifndef __ASM_CACHE_H
4576 #define __ASM_CACHE_H
4577
4578+#include <linux/const.h>
4579
4580 /* bytes per L1 cache line */
4581 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4582-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4583+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4584
4585 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4586 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4587diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4588index 43901f2..0d8b865 100644
4589--- a/arch/frv/include/asm/kmap_types.h
4590+++ b/arch/frv/include/asm/kmap_types.h
4591@@ -2,6 +2,6 @@
4592 #ifndef _ASM_KMAP_TYPES_H
4593 #define _ASM_KMAP_TYPES_H
4594
4595-#define KM_TYPE_NR 17
4596+#define KM_TYPE_NR 18
4597
4598 #endif
4599diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4600index 385fd30..3aaf4fe 100644
4601--- a/arch/frv/mm/elf-fdpic.c
4602+++ b/arch/frv/mm/elf-fdpic.c
4603@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4604 {
4605 struct vm_area_struct *vma;
4606 unsigned long limit;
4607+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4608
4609 if (len > TASK_SIZE)
4610 return -ENOMEM;
4611@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4612 if (addr) {
4613 addr = PAGE_ALIGN(addr);
4614 vma = find_vma(current->mm, addr);
4615- if (TASK_SIZE - len >= addr &&
4616- (!vma || addr + len <= vma->vm_start))
4617+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4618 goto success;
4619 }
4620
4621@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4622 for (; vma; vma = vma->vm_next) {
4623 if (addr > limit)
4624 break;
4625- if (addr + len <= vma->vm_start)
4626+ if (check_heap_stack_gap(vma, addr, len, offset))
4627 goto success;
4628 addr = vma->vm_end;
4629 }
4630@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4631 for (; vma; vma = vma->vm_next) {
4632 if (addr > limit)
4633 break;
4634- if (addr + len <= vma->vm_start)
4635+ if (check_heap_stack_gap(vma, addr, len, offset))
4636 goto success;
4637 addr = vma->vm_end;
4638 }
4639diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4640index f4ca594..adc72fd6 100644
4641--- a/arch/hexagon/include/asm/cache.h
4642+++ b/arch/hexagon/include/asm/cache.h
4643@@ -21,9 +21,11 @@
4644 #ifndef __ASM_CACHE_H
4645 #define __ASM_CACHE_H
4646
4647+#include <linux/const.h>
4648+
4649 /* Bytes per L1 cache line */
4650-#define L1_CACHE_SHIFT (5)
4651-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4652+#define L1_CACHE_SHIFT 5
4653+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4654
4655 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4656 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4657diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4658index 6e6fe18..a6ae668 100644
4659--- a/arch/ia64/include/asm/atomic.h
4660+++ b/arch/ia64/include/asm/atomic.h
4661@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4662 #define atomic64_inc(v) atomic64_add(1, (v))
4663 #define atomic64_dec(v) atomic64_sub(1, (v))
4664
4665+#define atomic64_read_unchecked(v) atomic64_read(v)
4666+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4667+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4668+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4669+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4670+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4671+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4672+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4673+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4674+
4675 /* Atomic operations are already serializing */
4676 #define smp_mb__before_atomic_dec() barrier()
4677 #define smp_mb__after_atomic_dec() barrier()
4678diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4679index 988254a..e1ee885 100644
4680--- a/arch/ia64/include/asm/cache.h
4681+++ b/arch/ia64/include/asm/cache.h
4682@@ -1,6 +1,7 @@
4683 #ifndef _ASM_IA64_CACHE_H
4684 #define _ASM_IA64_CACHE_H
4685
4686+#include <linux/const.h>
4687
4688 /*
4689 * Copyright (C) 1998-2000 Hewlett-Packard Co
4690@@ -9,7 +10,7 @@
4691
4692 /* Bytes per L1 (data) cache line. */
4693 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4694-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4695+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4696
4697 #ifdef CONFIG_SMP
4698 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4699diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4700index b5298eb..67c6e62 100644
4701--- a/arch/ia64/include/asm/elf.h
4702+++ b/arch/ia64/include/asm/elf.h
4703@@ -42,6 +42,13 @@
4704 */
4705 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4706
4707+#ifdef CONFIG_PAX_ASLR
4708+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4709+
4710+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4711+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4712+#endif
4713+
4714 #define PT_IA_64_UNWIND 0x70000001
4715
4716 /* IA-64 relocations: */
4717diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4718index 96a8d92..617a1cf 100644
4719--- a/arch/ia64/include/asm/pgalloc.h
4720+++ b/arch/ia64/include/asm/pgalloc.h
4721@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4722 pgd_val(*pgd_entry) = __pa(pud);
4723 }
4724
4725+static inline void
4726+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4727+{
4728+ pgd_populate(mm, pgd_entry, pud);
4729+}
4730+
4731 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4732 {
4733 return quicklist_alloc(0, GFP_KERNEL, NULL);
4734@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4735 pud_val(*pud_entry) = __pa(pmd);
4736 }
4737
4738+static inline void
4739+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4740+{
4741+ pud_populate(mm, pud_entry, pmd);
4742+}
4743+
4744 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4745 {
4746 return quicklist_alloc(0, GFP_KERNEL, NULL);
4747diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4748index 815810c..d60bd4c 100644
4749--- a/arch/ia64/include/asm/pgtable.h
4750+++ b/arch/ia64/include/asm/pgtable.h
4751@@ -12,7 +12,7 @@
4752 * David Mosberger-Tang <davidm@hpl.hp.com>
4753 */
4754
4755-
4756+#include <linux/const.h>
4757 #include <asm/mman.h>
4758 #include <asm/page.h>
4759 #include <asm/processor.h>
4760@@ -142,6 +142,17 @@
4761 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4762 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4763 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4764+
4765+#ifdef CONFIG_PAX_PAGEEXEC
4766+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4767+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4768+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4769+#else
4770+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4771+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4772+# define PAGE_COPY_NOEXEC PAGE_COPY
4773+#endif
4774+
4775 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4776 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4777 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4778diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4779index 54ff557..70c88b7 100644
4780--- a/arch/ia64/include/asm/spinlock.h
4781+++ b/arch/ia64/include/asm/spinlock.h
4782@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4783 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4784
4785 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4786- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4787+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4788 }
4789
4790 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4791diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4792index 449c8c0..50cdf87 100644
4793--- a/arch/ia64/include/asm/uaccess.h
4794+++ b/arch/ia64/include/asm/uaccess.h
4795@@ -42,6 +42,8 @@
4796 #include <asm/pgtable.h>
4797 #include <asm/io.h>
4798
4799+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4800+
4801 /*
4802 * For historical reasons, the following macros are grossly misnamed:
4803 */
4804@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4805 static inline unsigned long
4806 __copy_to_user (void __user *to, const void *from, unsigned long count)
4807 {
4808+ if (count > INT_MAX)
4809+ return count;
4810+
4811+ if (!__builtin_constant_p(count))
4812+ check_object_size(from, count, true);
4813+
4814 return __copy_user(to, (__force void __user *) from, count);
4815 }
4816
4817 static inline unsigned long
4818 __copy_from_user (void *to, const void __user *from, unsigned long count)
4819 {
4820+ if (count > INT_MAX)
4821+ return count;
4822+
4823+ if (!__builtin_constant_p(count))
4824+ check_object_size(to, count, false);
4825+
4826 return __copy_user((__force void __user *) to, from, count);
4827 }
4828
4829@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4830 ({ \
4831 void __user *__cu_to = (to); \
4832 const void *__cu_from = (from); \
4833- long __cu_len = (n); \
4834+ unsigned long __cu_len = (n); \
4835 \
4836- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4837+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4838+ if (!__builtin_constant_p(n)) \
4839+ check_object_size(__cu_from, __cu_len, true); \
4840 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4841+ } \
4842 __cu_len; \
4843 })
4844
4845@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4846 ({ \
4847 void *__cu_to = (to); \
4848 const void __user *__cu_from = (from); \
4849- long __cu_len = (n); \
4850+ unsigned long __cu_len = (n); \
4851 \
4852 __chk_user_ptr(__cu_from); \
4853- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4854+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4855+ if (!__builtin_constant_p(n)) \
4856+ check_object_size(__cu_to, __cu_len, false); \
4857 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4858+ } \
4859 __cu_len; \
4860 })
4861
4862diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4863index 2d67317..07d8bfa 100644
4864--- a/arch/ia64/kernel/err_inject.c
4865+++ b/arch/ia64/kernel/err_inject.c
4866@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4867 return NOTIFY_OK;
4868 }
4869
4870-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4871+static struct notifier_block err_inject_cpu_notifier =
4872 {
4873 .notifier_call = err_inject_cpu_callback,
4874 };
4875diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4876index 65bf9cd..794f06b 100644
4877--- a/arch/ia64/kernel/mca.c
4878+++ b/arch/ia64/kernel/mca.c
4879@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4880 return NOTIFY_OK;
4881 }
4882
4883-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4884+static struct notifier_block mca_cpu_notifier = {
4885 .notifier_call = mca_cpu_callback
4886 };
4887
4888diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4889index 24603be..948052d 100644
4890--- a/arch/ia64/kernel/module.c
4891+++ b/arch/ia64/kernel/module.c
4892@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4893 void
4894 module_free (struct module *mod, void *module_region)
4895 {
4896- if (mod && mod->arch.init_unw_table &&
4897- module_region == mod->module_init) {
4898+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4899 unw_remove_unwind_table(mod->arch.init_unw_table);
4900 mod->arch.init_unw_table = NULL;
4901 }
4902@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4903 }
4904
4905 static inline int
4906+in_init_rx (const struct module *mod, uint64_t addr)
4907+{
4908+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4909+}
4910+
4911+static inline int
4912+in_init_rw (const struct module *mod, uint64_t addr)
4913+{
4914+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4915+}
4916+
4917+static inline int
4918 in_init (const struct module *mod, uint64_t addr)
4919 {
4920- return addr - (uint64_t) mod->module_init < mod->init_size;
4921+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4922+}
4923+
4924+static inline int
4925+in_core_rx (const struct module *mod, uint64_t addr)
4926+{
4927+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4928+}
4929+
4930+static inline int
4931+in_core_rw (const struct module *mod, uint64_t addr)
4932+{
4933+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4934 }
4935
4936 static inline int
4937 in_core (const struct module *mod, uint64_t addr)
4938 {
4939- return addr - (uint64_t) mod->module_core < mod->core_size;
4940+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4941 }
4942
4943 static inline int
4944@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4945 break;
4946
4947 case RV_BDREL:
4948- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4949+ if (in_init_rx(mod, val))
4950+ val -= (uint64_t) mod->module_init_rx;
4951+ else if (in_init_rw(mod, val))
4952+ val -= (uint64_t) mod->module_init_rw;
4953+ else if (in_core_rx(mod, val))
4954+ val -= (uint64_t) mod->module_core_rx;
4955+ else if (in_core_rw(mod, val))
4956+ val -= (uint64_t) mod->module_core_rw;
4957 break;
4958
4959 case RV_LTV:
4960@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4961 * addresses have been selected...
4962 */
4963 uint64_t gp;
4964- if (mod->core_size > MAX_LTOFF)
4965+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4966 /*
4967 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4968 * at the end of the module.
4969 */
4970- gp = mod->core_size - MAX_LTOFF / 2;
4971+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4972 else
4973- gp = mod->core_size / 2;
4974- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4975+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4976+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4977 mod->arch.gp = gp;
4978 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4979 }
4980diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4981index 77597e5..6f28f3f 100644
4982--- a/arch/ia64/kernel/palinfo.c
4983+++ b/arch/ia64/kernel/palinfo.c
4984@@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4985 return NOTIFY_OK;
4986 }
4987
4988-static struct notifier_block __refdata palinfo_cpu_notifier =
4989+static struct notifier_block palinfo_cpu_notifier =
4990 {
4991 .notifier_call = palinfo_cpu_callback,
4992 .priority = 0,
4993diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4994index 79802e5..1a89ec5 100644
4995--- a/arch/ia64/kernel/salinfo.c
4996+++ b/arch/ia64/kernel/salinfo.c
4997@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4998 return NOTIFY_OK;
4999 }
5000
5001-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
5002+static struct notifier_block salinfo_cpu_notifier =
5003 {
5004 .notifier_call = salinfo_cpu_callback,
5005 .priority = 0,
5006diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5007index d9439ef..d0cac6b 100644
5008--- a/arch/ia64/kernel/sys_ia64.c
5009+++ b/arch/ia64/kernel/sys_ia64.c
5010@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5011 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
5012 struct mm_struct *mm = current->mm;
5013 struct vm_area_struct *vma;
5014+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5015
5016 if (len > RGN_MAP_LIMIT)
5017 return -ENOMEM;
5018@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5019 if (REGION_NUMBER(addr) == RGN_HPAGE)
5020 addr = 0;
5021 #endif
5022+
5023+#ifdef CONFIG_PAX_RANDMMAP
5024+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5025+ addr = mm->free_area_cache;
5026+ else
5027+#endif
5028+
5029 if (!addr)
5030 addr = mm->free_area_cache;
5031
5032@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5033 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
5034 /* At this point: (!vma || addr < vma->vm_end). */
5035 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
5036- if (start_addr != TASK_UNMAPPED_BASE) {
5037+ if (start_addr != mm->mmap_base) {
5038 /* Start a new search --- just in case we missed some holes. */
5039- addr = TASK_UNMAPPED_BASE;
5040+ addr = mm->mmap_base;
5041 goto full_search;
5042 }
5043 return -ENOMEM;
5044 }
5045- if (!vma || addr + len <= vma->vm_start) {
5046+ if (check_heap_stack_gap(vma, addr, len, offset)) {
5047 /* Remember the address where we stopped this search: */
5048 mm->free_area_cache = addr + len;
5049 return addr;
5050diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5051index dc00b2c..cce53c2 100644
5052--- a/arch/ia64/kernel/topology.c
5053+++ b/arch/ia64/kernel/topology.c
5054@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5055 return NOTIFY_OK;
5056 }
5057
5058-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5059+static struct notifier_block cache_cpu_notifier =
5060 {
5061 .notifier_call = cache_cpu_callback
5062 };
5063diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5064index 0ccb28f..8992469 100644
5065--- a/arch/ia64/kernel/vmlinux.lds.S
5066+++ b/arch/ia64/kernel/vmlinux.lds.S
5067@@ -198,7 +198,7 @@ SECTIONS {
5068 /* Per-cpu data: */
5069 . = ALIGN(PERCPU_PAGE_SIZE);
5070 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5071- __phys_per_cpu_start = __per_cpu_load;
5072+ __phys_per_cpu_start = per_cpu_load;
5073 /*
5074 * ensure percpu data fits
5075 * into percpu page size
5076diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5077index 6cf0341..d352594 100644
5078--- a/arch/ia64/mm/fault.c
5079+++ b/arch/ia64/mm/fault.c
5080@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5081 return pte_present(pte);
5082 }
5083
5084+#ifdef CONFIG_PAX_PAGEEXEC
5085+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5086+{
5087+ unsigned long i;
5088+
5089+ printk(KERN_ERR "PAX: bytes at PC: ");
5090+ for (i = 0; i < 8; i++) {
5091+ unsigned int c;
5092+ if (get_user(c, (unsigned int *)pc+i))
5093+ printk(KERN_CONT "???????? ");
5094+ else
5095+ printk(KERN_CONT "%08x ", c);
5096+ }
5097+ printk("\n");
5098+}
5099+#endif
5100+
5101 # define VM_READ_BIT 0
5102 # define VM_WRITE_BIT 1
5103 # define VM_EXEC_BIT 2
5104@@ -149,8 +166,21 @@ retry:
5105 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5106 goto bad_area;
5107
5108- if ((vma->vm_flags & mask) != mask)
5109+ if ((vma->vm_flags & mask) != mask) {
5110+
5111+#ifdef CONFIG_PAX_PAGEEXEC
5112+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5113+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5114+ goto bad_area;
5115+
5116+ up_read(&mm->mmap_sem);
5117+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5118+ do_group_exit(SIGKILL);
5119+ }
5120+#endif
5121+
5122 goto bad_area;
5123+ }
5124
5125 /*
5126 * If for any reason at all we couldn't handle the fault, make
5127diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5128index 5ca674b..127c3cb 100644
5129--- a/arch/ia64/mm/hugetlbpage.c
5130+++ b/arch/ia64/mm/hugetlbpage.c
5131@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5132 unsigned long pgoff, unsigned long flags)
5133 {
5134 struct vm_area_struct *vmm;
5135+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5136
5137 if (len > RGN_MAP_LIMIT)
5138 return -ENOMEM;
5139@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5140 /* At this point: (!vmm || addr < vmm->vm_end). */
5141 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
5142 return -ENOMEM;
5143- if (!vmm || (addr + len) <= vmm->vm_start)
5144+ if (check_heap_stack_gap(vmm, addr, len, offset))
5145 return addr;
5146 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
5147 }
5148diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5149index b755ea9..b9a969e 100644
5150--- a/arch/ia64/mm/init.c
5151+++ b/arch/ia64/mm/init.c
5152@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5153 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5154 vma->vm_end = vma->vm_start + PAGE_SIZE;
5155 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5156+
5157+#ifdef CONFIG_PAX_PAGEEXEC
5158+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5159+ vma->vm_flags &= ~VM_EXEC;
5160+
5161+#ifdef CONFIG_PAX_MPROTECT
5162+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5163+ vma->vm_flags &= ~VM_MAYEXEC;
5164+#endif
5165+
5166+ }
5167+#endif
5168+
5169 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5170 down_write(&current->mm->mmap_sem);
5171 if (insert_vm_struct(current->mm, vma)) {
5172diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5173index 40b3ee9..8c2c112 100644
5174--- a/arch/m32r/include/asm/cache.h
5175+++ b/arch/m32r/include/asm/cache.h
5176@@ -1,8 +1,10 @@
5177 #ifndef _ASM_M32R_CACHE_H
5178 #define _ASM_M32R_CACHE_H
5179
5180+#include <linux/const.h>
5181+
5182 /* L1 cache line size */
5183 #define L1_CACHE_SHIFT 4
5184-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5185+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5186
5187 #endif /* _ASM_M32R_CACHE_H */
5188diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5189index 82abd15..d95ae5d 100644
5190--- a/arch/m32r/lib/usercopy.c
5191+++ b/arch/m32r/lib/usercopy.c
5192@@ -14,6 +14,9 @@
5193 unsigned long
5194 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5195 {
5196+ if ((long)n < 0)
5197+ return n;
5198+
5199 prefetch(from);
5200 if (access_ok(VERIFY_WRITE, to, n))
5201 __copy_user(to,from,n);
5202@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5203 unsigned long
5204 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5205 {
5206+ if ((long)n < 0)
5207+ return n;
5208+
5209 prefetchw(to);
5210 if (access_ok(VERIFY_READ, from, n))
5211 __copy_user_zeroing(to,from,n);
5212diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5213index 0395c51..5f26031 100644
5214--- a/arch/m68k/include/asm/cache.h
5215+++ b/arch/m68k/include/asm/cache.h
5216@@ -4,9 +4,11 @@
5217 #ifndef __ARCH_M68K_CACHE_H
5218 #define __ARCH_M68K_CACHE_H
5219
5220+#include <linux/const.h>
5221+
5222 /* bytes per L1 cache line */
5223 #define L1_CACHE_SHIFT 4
5224-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5225+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5226
5227 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5228
5229diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5230index 4efe96a..60e8699 100644
5231--- a/arch/microblaze/include/asm/cache.h
5232+++ b/arch/microblaze/include/asm/cache.h
5233@@ -13,11 +13,12 @@
5234 #ifndef _ASM_MICROBLAZE_CACHE_H
5235 #define _ASM_MICROBLAZE_CACHE_H
5236
5237+#include <linux/const.h>
5238 #include <asm/registers.h>
5239
5240 #define L1_CACHE_SHIFT 5
5241 /* word-granular cache in microblaze */
5242-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5243+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5244
5245 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5246
5247diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5248index 01cc6ba..bcb7a5d 100644
5249--- a/arch/mips/include/asm/atomic.h
5250+++ b/arch/mips/include/asm/atomic.h
5251@@ -21,6 +21,10 @@
5252 #include <asm/cmpxchg.h>
5253 #include <asm/war.h>
5254
5255+#ifdef CONFIG_GENERIC_ATOMIC64
5256+#include <asm-generic/atomic64.h>
5257+#endif
5258+
5259 #define ATOMIC_INIT(i) { (i) }
5260
5261 /*
5262@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5263 */
5264 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5265
5266+#define atomic64_read_unchecked(v) atomic64_read(v)
5267+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5268+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5269+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5270+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5271+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5272+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5273+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5274+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5275+
5276 #endif /* CONFIG_64BIT */
5277
5278 /*
5279diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5280index b4db69f..8f3b093 100644
5281--- a/arch/mips/include/asm/cache.h
5282+++ b/arch/mips/include/asm/cache.h
5283@@ -9,10 +9,11 @@
5284 #ifndef _ASM_CACHE_H
5285 #define _ASM_CACHE_H
5286
5287+#include <linux/const.h>
5288 #include <kmalloc.h>
5289
5290 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5291-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5292+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5293
5294 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5295 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5296diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5297index 455c0ac..ad65fbe 100644
5298--- a/arch/mips/include/asm/elf.h
5299+++ b/arch/mips/include/asm/elf.h
5300@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5301 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5302 #endif
5303
5304+#ifdef CONFIG_PAX_ASLR
5305+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5306+
5307+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5308+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5309+#endif
5310+
5311 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5312 struct linux_binprm;
5313 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5314 int uses_interp);
5315
5316-struct mm_struct;
5317-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5318-#define arch_randomize_brk arch_randomize_brk
5319-
5320 #endif /* _ASM_ELF_H */
5321diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5322index c1f6afa..38cc6e9 100644
5323--- a/arch/mips/include/asm/exec.h
5324+++ b/arch/mips/include/asm/exec.h
5325@@ -12,6 +12,6 @@
5326 #ifndef _ASM_EXEC_H
5327 #define _ASM_EXEC_H
5328
5329-extern unsigned long arch_align_stack(unsigned long sp);
5330+#define arch_align_stack(x) ((x) & ~0xfUL)
5331
5332 #endif /* _ASM_EXEC_H */
5333diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5334index dbaec94..6a14935 100644
5335--- a/arch/mips/include/asm/page.h
5336+++ b/arch/mips/include/asm/page.h
5337@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5338 #ifdef CONFIG_CPU_MIPS32
5339 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5340 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5341- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5342+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5343 #else
5344 typedef struct { unsigned long long pte; } pte_t;
5345 #define pte_val(x) ((x).pte)
5346diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5347index 881d18b..cea38bc 100644
5348--- a/arch/mips/include/asm/pgalloc.h
5349+++ b/arch/mips/include/asm/pgalloc.h
5350@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5351 {
5352 set_pud(pud, __pud((unsigned long)pmd));
5353 }
5354+
5355+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5356+{
5357+ pud_populate(mm, pud, pmd);
5358+}
5359 #endif
5360
5361 /*
5362diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5363index b2050b9..d71bb1b 100644
5364--- a/arch/mips/include/asm/thread_info.h
5365+++ b/arch/mips/include/asm/thread_info.h
5366@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5367 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5368 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5369 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5370+/* li takes a 32bit immediate */
5371+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5372 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5373
5374 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5375@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5376 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5377 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5378 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5379+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5380+
5381+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5382
5383 /* work to do in syscall_trace_leave() */
5384-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5385+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5386
5387 /* work to do on interrupt/exception return */
5388 #define _TIF_WORK_MASK \
5389 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5390 /* work to do on any return to u-space */
5391-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5392+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5393
5394 #endif /* __KERNEL__ */
5395
5396diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5397index 9fdd8bc..4bd7f1a 100644
5398--- a/arch/mips/kernel/binfmt_elfn32.c
5399+++ b/arch/mips/kernel/binfmt_elfn32.c
5400@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5401 #undef ELF_ET_DYN_BASE
5402 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5403
5404+#ifdef CONFIG_PAX_ASLR
5405+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5406+
5407+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5408+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5409+#endif
5410+
5411 #include <asm/processor.h>
5412 #include <linux/module.h>
5413 #include <linux/elfcore.h>
5414diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5415index ff44823..97f8906 100644
5416--- a/arch/mips/kernel/binfmt_elfo32.c
5417+++ b/arch/mips/kernel/binfmt_elfo32.c
5418@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5419 #undef ELF_ET_DYN_BASE
5420 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5421
5422+#ifdef CONFIG_PAX_ASLR
5423+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5424+
5425+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5426+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5427+#endif
5428+
5429 #include <asm/processor.h>
5430
5431 /*
5432diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5433index a11c6f9..be5e164 100644
5434--- a/arch/mips/kernel/process.c
5435+++ b/arch/mips/kernel/process.c
5436@@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5437 out:
5438 return pc;
5439 }
5440-
5441-/*
5442- * Don't forget that the stack pointer must be aligned on a 8 bytes
5443- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5444- */
5445-unsigned long arch_align_stack(unsigned long sp)
5446-{
5447- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5448- sp -= get_random_int() & ~PAGE_MASK;
5449-
5450- return sp & ALMASK;
5451-}
5452diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5453index 4812c6d..2069554 100644
5454--- a/arch/mips/kernel/ptrace.c
5455+++ b/arch/mips/kernel/ptrace.c
5456@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5457 return arch;
5458 }
5459
5460+#ifdef CONFIG_GRKERNSEC_SETXID
5461+extern void gr_delayed_cred_worker(void);
5462+#endif
5463+
5464 /*
5465 * Notification of system call entry/exit
5466 * - triggered by current->work.syscall_trace
5467@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5468 /* do the secure computing check first */
5469 secure_computing_strict(regs->regs[2]);
5470
5471+#ifdef CONFIG_GRKERNSEC_SETXID
5472+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5473+ gr_delayed_cred_worker();
5474+#endif
5475+
5476 if (!(current->ptrace & PT_PTRACED))
5477 goto out;
5478
5479diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5480index d20a4bc..7096ae5 100644
5481--- a/arch/mips/kernel/scall32-o32.S
5482+++ b/arch/mips/kernel/scall32-o32.S
5483@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5484
5485 stack_done:
5486 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5487- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5488+ li t1, _TIF_SYSCALL_WORK
5489 and t0, t1
5490 bnez t0, syscall_trace_entry # -> yes
5491
5492diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5493index b64f642..0fe6eab 100644
5494--- a/arch/mips/kernel/scall64-64.S
5495+++ b/arch/mips/kernel/scall64-64.S
5496@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5497
5498 sd a3, PT_R26(sp) # save a3 for syscall restarting
5499
5500- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5501+ li t1, _TIF_SYSCALL_WORK
5502 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5503 and t0, t1, t0
5504 bnez t0, syscall_trace_entry
5505diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5506index c29ac19..c592d05 100644
5507--- a/arch/mips/kernel/scall64-n32.S
5508+++ b/arch/mips/kernel/scall64-n32.S
5509@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5510
5511 sd a3, PT_R26(sp) # save a3 for syscall restarting
5512
5513- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5514+ li t1, _TIF_SYSCALL_WORK
5515 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5516 and t0, t1, t0
5517 bnez t0, n32_syscall_trace_entry
5518diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5519index cf3e75e..72e93fe 100644
5520--- a/arch/mips/kernel/scall64-o32.S
5521+++ b/arch/mips/kernel/scall64-o32.S
5522@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5523 PTR 4b, bad_stack
5524 .previous
5525
5526- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5527+ li t1, _TIF_SYSCALL_WORK
5528 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5529 and t0, t1, t0
5530 bnez t0, trace_a_syscall
5531diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5532index ddcec1e..c7f983e 100644
5533--- a/arch/mips/mm/fault.c
5534+++ b/arch/mips/mm/fault.c
5535@@ -27,6 +27,23 @@
5536 #include <asm/highmem.h> /* For VMALLOC_END */
5537 #include <linux/kdebug.h>
5538
5539+#ifdef CONFIG_PAX_PAGEEXEC
5540+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5541+{
5542+ unsigned long i;
5543+
5544+ printk(KERN_ERR "PAX: bytes at PC: ");
5545+ for (i = 0; i < 5; i++) {
5546+ unsigned int c;
5547+ if (get_user(c, (unsigned int *)pc+i))
5548+ printk(KERN_CONT "???????? ");
5549+ else
5550+ printk(KERN_CONT "%08x ", c);
5551+ }
5552+ printk("\n");
5553+}
5554+#endif
5555+
5556 /*
5557 * This routine handles page faults. It determines the address,
5558 * and the problem, and then passes it off to one of the appropriate
5559diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5560index 7e5fe27..479a219 100644
5561--- a/arch/mips/mm/mmap.c
5562+++ b/arch/mips/mm/mmap.c
5563@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5564 struct vm_area_struct *vma;
5565 unsigned long addr = addr0;
5566 int do_color_align;
5567+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5568 struct vm_unmapped_area_info info;
5569
5570 if (unlikely(len > TASK_SIZE))
5571@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5572 do_color_align = 1;
5573
5574 /* requesting a specific address */
5575+
5576+#ifdef CONFIG_PAX_RANDMMAP
5577+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5578+#endif
5579+
5580 if (addr) {
5581 if (do_color_align)
5582 addr = COLOUR_ALIGN(addr, pgoff);
5583@@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5584 addr = PAGE_ALIGN(addr);
5585
5586 vma = find_vma(mm, addr);
5587- if (TASK_SIZE - len >= addr &&
5588- (!vma || addr + len <= vma->vm_start))
5589+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5590 return addr;
5591 }
5592
5593@@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5594 {
5595 unsigned long random_factor = 0UL;
5596
5597+#ifdef CONFIG_PAX_RANDMMAP
5598+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5599+#endif
5600+
5601 if (current->flags & PF_RANDOMIZE) {
5602 random_factor = get_random_int();
5603 random_factor = random_factor << PAGE_SHIFT;
5604@@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5605
5606 if (mmap_is_legacy()) {
5607 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5608+
5609+#ifdef CONFIG_PAX_RANDMMAP
5610+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5611+ mm->mmap_base += mm->delta_mmap;
5612+#endif
5613+
5614 mm->get_unmapped_area = arch_get_unmapped_area;
5615 mm->unmap_area = arch_unmap_area;
5616 } else {
5617 mm->mmap_base = mmap_base(random_factor);
5618+
5619+#ifdef CONFIG_PAX_RANDMMAP
5620+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5621+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5622+#endif
5623+
5624 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5625 mm->unmap_area = arch_unmap_area_topdown;
5626 }
5627 }
5628
5629-static inline unsigned long brk_rnd(void)
5630-{
5631- unsigned long rnd = get_random_int();
5632-
5633- rnd = rnd << PAGE_SHIFT;
5634- /* 8MB for 32bit, 256MB for 64bit */
5635- if (TASK_IS_32BIT_ADDR)
5636- rnd = rnd & 0x7ffffful;
5637- else
5638- rnd = rnd & 0xffffffful;
5639-
5640- return rnd;
5641-}
5642-
5643-unsigned long arch_randomize_brk(struct mm_struct *mm)
5644-{
5645- unsigned long base = mm->brk;
5646- unsigned long ret;
5647-
5648- ret = PAGE_ALIGN(base + brk_rnd());
5649-
5650- if (ret < mm->brk)
5651- return mm->brk;
5652-
5653- return ret;
5654-}
5655-
5656 int __virt_addr_valid(const volatile void *kaddr)
5657 {
5658 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5659diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5660index 967d144..db12197 100644
5661--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5662+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5663@@ -11,12 +11,14 @@
5664 #ifndef _ASM_PROC_CACHE_H
5665 #define _ASM_PROC_CACHE_H
5666
5667+#include <linux/const.h>
5668+
5669 /* L1 cache */
5670
5671 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5672 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5673-#define L1_CACHE_BYTES 16 /* bytes per entry */
5674 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5675+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5676 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5677
5678 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5679diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5680index bcb5df2..84fabd2 100644
5681--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5682+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5683@@ -16,13 +16,15 @@
5684 #ifndef _ASM_PROC_CACHE_H
5685 #define _ASM_PROC_CACHE_H
5686
5687+#include <linux/const.h>
5688+
5689 /*
5690 * L1 cache
5691 */
5692 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5693 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5694-#define L1_CACHE_BYTES 32 /* bytes per entry */
5695 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5696+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5697 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5698
5699 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5700diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5701index 4ce7a01..449202a 100644
5702--- a/arch/openrisc/include/asm/cache.h
5703+++ b/arch/openrisc/include/asm/cache.h
5704@@ -19,11 +19,13 @@
5705 #ifndef __ASM_OPENRISC_CACHE_H
5706 #define __ASM_OPENRISC_CACHE_H
5707
5708+#include <linux/const.h>
5709+
5710 /* FIXME: How can we replace these with values from the CPU...
5711 * they shouldn't be hard-coded!
5712 */
5713
5714-#define L1_CACHE_BYTES 16
5715 #define L1_CACHE_SHIFT 4
5716+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5717
5718 #endif /* __ASM_OPENRISC_CACHE_H */
5719diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5720index af9cf30..2aae9b2 100644
5721--- a/arch/parisc/include/asm/atomic.h
5722+++ b/arch/parisc/include/asm/atomic.h
5723@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5724
5725 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5726
5727+#define atomic64_read_unchecked(v) atomic64_read(v)
5728+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5729+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5730+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5731+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5732+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5733+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5734+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5735+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5736+
5737 #endif /* !CONFIG_64BIT */
5738
5739
5740diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5741index 47f11c7..3420df2 100644
5742--- a/arch/parisc/include/asm/cache.h
5743+++ b/arch/parisc/include/asm/cache.h
5744@@ -5,6 +5,7 @@
5745 #ifndef __ARCH_PARISC_CACHE_H
5746 #define __ARCH_PARISC_CACHE_H
5747
5748+#include <linux/const.h>
5749
5750 /*
5751 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5752@@ -15,13 +16,13 @@
5753 * just ruin performance.
5754 */
5755 #ifdef CONFIG_PA20
5756-#define L1_CACHE_BYTES 64
5757 #define L1_CACHE_SHIFT 6
5758 #else
5759-#define L1_CACHE_BYTES 32
5760 #define L1_CACHE_SHIFT 5
5761 #endif
5762
5763+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5764+
5765 #ifndef __ASSEMBLY__
5766
5767 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5768diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5769index 19f6cb1..6c78cf2 100644
5770--- a/arch/parisc/include/asm/elf.h
5771+++ b/arch/parisc/include/asm/elf.h
5772@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5773
5774 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5775
5776+#ifdef CONFIG_PAX_ASLR
5777+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5778+
5779+#define PAX_DELTA_MMAP_LEN 16
5780+#define PAX_DELTA_STACK_LEN 16
5781+#endif
5782+
5783 /* This yields a mask that user programs can use to figure out what
5784 instruction set this CPU supports. This could be done in user space,
5785 but it's not easy, and we've already done it here. */
5786diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5787index fc987a1..6e068ef 100644
5788--- a/arch/parisc/include/asm/pgalloc.h
5789+++ b/arch/parisc/include/asm/pgalloc.h
5790@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5791 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5792 }
5793
5794+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5795+{
5796+ pgd_populate(mm, pgd, pmd);
5797+}
5798+
5799 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5800 {
5801 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5802@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5803 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5804 #define pmd_free(mm, x) do { } while (0)
5805 #define pgd_populate(mm, pmd, pte) BUG()
5806+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5807
5808 #endif
5809
5810diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5811index 7df49fa..38b62bf 100644
5812--- a/arch/parisc/include/asm/pgtable.h
5813+++ b/arch/parisc/include/asm/pgtable.h
5814@@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5815 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5816 #define PAGE_COPY PAGE_EXECREAD
5817 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5818+
5819+#ifdef CONFIG_PAX_PAGEEXEC
5820+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5821+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5822+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5823+#else
5824+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5825+# define PAGE_COPY_NOEXEC PAGE_COPY
5826+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5827+#endif
5828+
5829 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5830 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5831 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5832diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5833index 4ba2c93..f5e3974 100644
5834--- a/arch/parisc/include/asm/uaccess.h
5835+++ b/arch/parisc/include/asm/uaccess.h
5836@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5837 const void __user *from,
5838 unsigned long n)
5839 {
5840- int sz = __compiletime_object_size(to);
5841+ size_t sz = __compiletime_object_size(to);
5842 int ret = -EFAULT;
5843
5844- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5845+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5846 ret = __copy_from_user(to, from, n);
5847 else
5848 copy_from_user_overflow();
5849diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5850index 2a625fb..9908930 100644
5851--- a/arch/parisc/kernel/module.c
5852+++ b/arch/parisc/kernel/module.c
5853@@ -98,16 +98,38 @@
5854
5855 /* three functions to determine where in the module core
5856 * or init pieces the location is */
5857+static inline int in_init_rx(struct module *me, void *loc)
5858+{
5859+ return (loc >= me->module_init_rx &&
5860+ loc < (me->module_init_rx + me->init_size_rx));
5861+}
5862+
5863+static inline int in_init_rw(struct module *me, void *loc)
5864+{
5865+ return (loc >= me->module_init_rw &&
5866+ loc < (me->module_init_rw + me->init_size_rw));
5867+}
5868+
5869 static inline int in_init(struct module *me, void *loc)
5870 {
5871- return (loc >= me->module_init &&
5872- loc <= (me->module_init + me->init_size));
5873+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5874+}
5875+
5876+static inline int in_core_rx(struct module *me, void *loc)
5877+{
5878+ return (loc >= me->module_core_rx &&
5879+ loc < (me->module_core_rx + me->core_size_rx));
5880+}
5881+
5882+static inline int in_core_rw(struct module *me, void *loc)
5883+{
5884+ return (loc >= me->module_core_rw &&
5885+ loc < (me->module_core_rw + me->core_size_rw));
5886 }
5887
5888 static inline int in_core(struct module *me, void *loc)
5889 {
5890- return (loc >= me->module_core &&
5891- loc <= (me->module_core + me->core_size));
5892+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5893 }
5894
5895 static inline int in_local(struct module *me, void *loc)
5896@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5897 }
5898
5899 /* align things a bit */
5900- me->core_size = ALIGN(me->core_size, 16);
5901- me->arch.got_offset = me->core_size;
5902- me->core_size += gots * sizeof(struct got_entry);
5903+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5904+ me->arch.got_offset = me->core_size_rw;
5905+ me->core_size_rw += gots * sizeof(struct got_entry);
5906
5907- me->core_size = ALIGN(me->core_size, 16);
5908- me->arch.fdesc_offset = me->core_size;
5909- me->core_size += fdescs * sizeof(Elf_Fdesc);
5910+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5911+ me->arch.fdesc_offset = me->core_size_rw;
5912+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5913
5914 me->arch.got_max = gots;
5915 me->arch.fdesc_max = fdescs;
5916@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5917
5918 BUG_ON(value == 0);
5919
5920- got = me->module_core + me->arch.got_offset;
5921+ got = me->module_core_rw + me->arch.got_offset;
5922 for (i = 0; got[i].addr; i++)
5923 if (got[i].addr == value)
5924 goto out;
5925@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5926 #ifdef CONFIG_64BIT
5927 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5928 {
5929- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5930+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5931
5932 if (!value) {
5933 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5934@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5935
5936 /* Create new one */
5937 fdesc->addr = value;
5938- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5939+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5940 return (Elf_Addr)fdesc;
5941 }
5942 #endif /* CONFIG_64BIT */
5943@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5944
5945 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5946 end = table + sechdrs[me->arch.unwind_section].sh_size;
5947- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5948+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5949
5950 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5951 me->arch.unwind_section, table, end, gp);
5952diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5953index f76c108..92bad82 100644
5954--- a/arch/parisc/kernel/sys_parisc.c
5955+++ b/arch/parisc/kernel/sys_parisc.c
5956@@ -33,9 +33,11 @@
5957 #include <linux/utsname.h>
5958 #include <linux/personality.h>
5959
5960-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5961+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5962+ unsigned long flags)
5963 {
5964 struct vm_area_struct *vma;
5965+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5966
5967 addr = PAGE_ALIGN(addr);
5968
5969@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5970 /* At this point: (!vma || addr < vma->vm_end). */
5971 if (TASK_SIZE - len < addr)
5972 return -ENOMEM;
5973- if (!vma || addr + len <= vma->vm_start)
5974+ if (check_heap_stack_gap(vma, addr, len, offset))
5975 return addr;
5976 addr = vma->vm_end;
5977 }
5978@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5979 return offset & 0x3FF000;
5980 }
5981
5982-static unsigned long get_shared_area(struct address_space *mapping,
5983- unsigned long addr, unsigned long len, unsigned long pgoff)
5984+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5985+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5986 {
5987 struct vm_area_struct *vma;
5988 int offset = mapping ? get_offset(mapping) : 0;
5989+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5990
5991 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5992
5993@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5994 /* At this point: (!vma || addr < vma->vm_end). */
5995 if (TASK_SIZE - len < addr)
5996 return -ENOMEM;
5997- if (!vma || addr + len <= vma->vm_start)
5998+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
5999 return addr;
6000 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
6001 if (addr < vma->vm_end) /* handle wraparound */
6002@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6003 if (flags & MAP_FIXED)
6004 return addr;
6005 if (!addr)
6006- addr = TASK_UNMAPPED_BASE;
6007+ addr = current->mm->mmap_base;
6008
6009 if (filp) {
6010- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
6011+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
6012 } else if(flags & MAP_SHARED) {
6013- addr = get_shared_area(NULL, addr, len, pgoff);
6014+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6015 } else {
6016- addr = get_unshared_area(addr, len);
6017+ addr = get_unshared_area(filp, addr, len, flags);
6018 }
6019 return addr;
6020 }
6021diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6022index 45ba99f..8e22c33 100644
6023--- a/arch/parisc/kernel/traps.c
6024+++ b/arch/parisc/kernel/traps.c
6025@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6026
6027 down_read(&current->mm->mmap_sem);
6028 vma = find_vma(current->mm,regs->iaoq[0]);
6029- if (vma && (regs->iaoq[0] >= vma->vm_start)
6030- && (vma->vm_flags & VM_EXEC)) {
6031-
6032+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6033 fault_address = regs->iaoq[0];
6034 fault_space = regs->iasq[0];
6035
6036diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6037index 18162ce..94de376 100644
6038--- a/arch/parisc/mm/fault.c
6039+++ b/arch/parisc/mm/fault.c
6040@@ -15,6 +15,7 @@
6041 #include <linux/sched.h>
6042 #include <linux/interrupt.h>
6043 #include <linux/module.h>
6044+#include <linux/unistd.h>
6045
6046 #include <asm/uaccess.h>
6047 #include <asm/traps.h>
6048@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6049 static unsigned long
6050 parisc_acctyp(unsigned long code, unsigned int inst)
6051 {
6052- if (code == 6 || code == 16)
6053+ if (code == 6 || code == 7 || code == 16)
6054 return VM_EXEC;
6055
6056 switch (inst & 0xf0000000) {
6057@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6058 }
6059 #endif
6060
6061+#ifdef CONFIG_PAX_PAGEEXEC
6062+/*
6063+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6064+ *
6065+ * returns 1 when task should be killed
6066+ * 2 when rt_sigreturn trampoline was detected
6067+ * 3 when unpatched PLT trampoline was detected
6068+ */
6069+static int pax_handle_fetch_fault(struct pt_regs *regs)
6070+{
6071+
6072+#ifdef CONFIG_PAX_EMUPLT
6073+ int err;
6074+
6075+ do { /* PaX: unpatched PLT emulation */
6076+ unsigned int bl, depwi;
6077+
6078+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6079+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6080+
6081+ if (err)
6082+ break;
6083+
6084+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6085+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6086+
6087+ err = get_user(ldw, (unsigned int *)addr);
6088+ err |= get_user(bv, (unsigned int *)(addr+4));
6089+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6090+
6091+ if (err)
6092+ break;
6093+
6094+ if (ldw == 0x0E801096U &&
6095+ bv == 0xEAC0C000U &&
6096+ ldw2 == 0x0E881095U)
6097+ {
6098+ unsigned int resolver, map;
6099+
6100+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6101+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6102+ if (err)
6103+ break;
6104+
6105+ regs->gr[20] = instruction_pointer(regs)+8;
6106+ regs->gr[21] = map;
6107+ regs->gr[22] = resolver;
6108+ regs->iaoq[0] = resolver | 3UL;
6109+ regs->iaoq[1] = regs->iaoq[0] + 4;
6110+ return 3;
6111+ }
6112+ }
6113+ } while (0);
6114+#endif
6115+
6116+#ifdef CONFIG_PAX_EMUTRAMP
6117+
6118+#ifndef CONFIG_PAX_EMUSIGRT
6119+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6120+ return 1;
6121+#endif
6122+
6123+ do { /* PaX: rt_sigreturn emulation */
6124+ unsigned int ldi1, ldi2, bel, nop;
6125+
6126+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6127+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6128+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6129+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6130+
6131+ if (err)
6132+ break;
6133+
6134+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6135+ ldi2 == 0x3414015AU &&
6136+ bel == 0xE4008200U &&
6137+ nop == 0x08000240U)
6138+ {
6139+ regs->gr[25] = (ldi1 & 2) >> 1;
6140+ regs->gr[20] = __NR_rt_sigreturn;
6141+ regs->gr[31] = regs->iaoq[1] + 16;
6142+ regs->sr[0] = regs->iasq[1];
6143+ regs->iaoq[0] = 0x100UL;
6144+ regs->iaoq[1] = regs->iaoq[0] + 4;
6145+ regs->iasq[0] = regs->sr[2];
6146+ regs->iasq[1] = regs->sr[2];
6147+ return 2;
6148+ }
6149+ } while (0);
6150+#endif
6151+
6152+ return 1;
6153+}
6154+
6155+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6156+{
6157+ unsigned long i;
6158+
6159+ printk(KERN_ERR "PAX: bytes at PC: ");
6160+ for (i = 0; i < 5; i++) {
6161+ unsigned int c;
6162+ if (get_user(c, (unsigned int *)pc+i))
6163+ printk(KERN_CONT "???????? ");
6164+ else
6165+ printk(KERN_CONT "%08x ", c);
6166+ }
6167+ printk("\n");
6168+}
6169+#endif
6170+
6171 int fixup_exception(struct pt_regs *regs)
6172 {
6173 const struct exception_table_entry *fix;
6174@@ -192,8 +303,33 @@ good_area:
6175
6176 acc_type = parisc_acctyp(code,regs->iir);
6177
6178- if ((vma->vm_flags & acc_type) != acc_type)
6179+ if ((vma->vm_flags & acc_type) != acc_type) {
6180+
6181+#ifdef CONFIG_PAX_PAGEEXEC
6182+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6183+ (address & ~3UL) == instruction_pointer(regs))
6184+ {
6185+ up_read(&mm->mmap_sem);
6186+ switch (pax_handle_fetch_fault(regs)) {
6187+
6188+#ifdef CONFIG_PAX_EMUPLT
6189+ case 3:
6190+ return;
6191+#endif
6192+
6193+#ifdef CONFIG_PAX_EMUTRAMP
6194+ case 2:
6195+ return;
6196+#endif
6197+
6198+ }
6199+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6200+ do_group_exit(SIGKILL);
6201+ }
6202+#endif
6203+
6204 goto bad_area;
6205+ }
6206
6207 /*
6208 * If for any reason at all we couldn't handle the fault, make
6209diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6210index e3b1d41..8e81edf 100644
6211--- a/arch/powerpc/include/asm/atomic.h
6212+++ b/arch/powerpc/include/asm/atomic.h
6213@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6214 return t1;
6215 }
6216
6217+#define atomic64_read_unchecked(v) atomic64_read(v)
6218+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6219+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6220+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6221+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6222+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6223+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6224+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6225+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6226+
6227 #endif /* __powerpc64__ */
6228
6229 #endif /* __KERNEL__ */
6230diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6231index 9e495c9..b6878e5 100644
6232--- a/arch/powerpc/include/asm/cache.h
6233+++ b/arch/powerpc/include/asm/cache.h
6234@@ -3,6 +3,7 @@
6235
6236 #ifdef __KERNEL__
6237
6238+#include <linux/const.h>
6239
6240 /* bytes per L1 cache line */
6241 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6242@@ -22,7 +23,7 @@
6243 #define L1_CACHE_SHIFT 7
6244 #endif
6245
6246-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6247+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6248
6249 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6250
6251diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6252index 6abf0a1..459d0f1 100644
6253--- a/arch/powerpc/include/asm/elf.h
6254+++ b/arch/powerpc/include/asm/elf.h
6255@@ -28,8 +28,19 @@
6256 the loader. We need to make sure that it is out of the way of the program
6257 that it will "exec", and that there is sufficient room for the brk. */
6258
6259-extern unsigned long randomize_et_dyn(unsigned long base);
6260-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6261+#define ELF_ET_DYN_BASE (0x20000000)
6262+
6263+#ifdef CONFIG_PAX_ASLR
6264+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6265+
6266+#ifdef __powerpc64__
6267+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6268+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6269+#else
6270+#define PAX_DELTA_MMAP_LEN 15
6271+#define PAX_DELTA_STACK_LEN 15
6272+#endif
6273+#endif
6274
6275 /*
6276 * Our registers are always unsigned longs, whether we're a 32 bit
6277@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6278 (0x7ff >> (PAGE_SHIFT - 12)) : \
6279 (0x3ffff >> (PAGE_SHIFT - 12)))
6280
6281-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6282-#define arch_randomize_brk arch_randomize_brk
6283-
6284-
6285 #ifdef CONFIG_SPU_BASE
6286 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6287 #define NT_SPU 1
6288diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6289index 8196e9c..d83a9f3 100644
6290--- a/arch/powerpc/include/asm/exec.h
6291+++ b/arch/powerpc/include/asm/exec.h
6292@@ -4,6 +4,6 @@
6293 #ifndef _ASM_POWERPC_EXEC_H
6294 #define _ASM_POWERPC_EXEC_H
6295
6296-extern unsigned long arch_align_stack(unsigned long sp);
6297+#define arch_align_stack(x) ((x) & ~0xfUL)
6298
6299 #endif /* _ASM_POWERPC_EXEC_H */
6300diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6301index 5acabbd..7ea14fa 100644
6302--- a/arch/powerpc/include/asm/kmap_types.h
6303+++ b/arch/powerpc/include/asm/kmap_types.h
6304@@ -10,7 +10,7 @@
6305 * 2 of the License, or (at your option) any later version.
6306 */
6307
6308-#define KM_TYPE_NR 16
6309+#define KM_TYPE_NR 17
6310
6311 #endif /* __KERNEL__ */
6312 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6313diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6314index 8565c25..2865190 100644
6315--- a/arch/powerpc/include/asm/mman.h
6316+++ b/arch/powerpc/include/asm/mman.h
6317@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6318 }
6319 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6320
6321-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6322+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6323 {
6324 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6325 }
6326diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6327index f072e97..b436dee 100644
6328--- a/arch/powerpc/include/asm/page.h
6329+++ b/arch/powerpc/include/asm/page.h
6330@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6331 * and needs to be executable. This means the whole heap ends
6332 * up being executable.
6333 */
6334-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6335- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6336+#define VM_DATA_DEFAULT_FLAGS32 \
6337+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6338+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6339
6340 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6341 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6342@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6343 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6344 #endif
6345
6346+#define ktla_ktva(addr) (addr)
6347+#define ktva_ktla(addr) (addr)
6348+
6349 /*
6350 * Use the top bit of the higher-level page table entries to indicate whether
6351 * the entries we point to contain hugepages. This works because we know that
6352diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6353index cd915d6..c10cee8 100644
6354--- a/arch/powerpc/include/asm/page_64.h
6355+++ b/arch/powerpc/include/asm/page_64.h
6356@@ -154,15 +154,18 @@ do { \
6357 * stack by default, so in the absence of a PT_GNU_STACK program header
6358 * we turn execute permission off.
6359 */
6360-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6361- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6362+#define VM_STACK_DEFAULT_FLAGS32 \
6363+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6364+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6365
6366 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6367 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6368
6369+#ifndef CONFIG_PAX_PAGEEXEC
6370 #define VM_STACK_DEFAULT_FLAGS \
6371 (is_32bit_task() ? \
6372 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6373+#endif
6374
6375 #include <asm-generic/getorder.h>
6376
6377diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6378index 292725c..f87ae14 100644
6379--- a/arch/powerpc/include/asm/pgalloc-64.h
6380+++ b/arch/powerpc/include/asm/pgalloc-64.h
6381@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6382 #ifndef CONFIG_PPC_64K_PAGES
6383
6384 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6385+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6386
6387 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6388 {
6389@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6390 pud_set(pud, (unsigned long)pmd);
6391 }
6392
6393+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6394+{
6395+ pud_populate(mm, pud, pmd);
6396+}
6397+
6398 #define pmd_populate(mm, pmd, pte_page) \
6399 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6400 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6401@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6402 #else /* CONFIG_PPC_64K_PAGES */
6403
6404 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6405+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6406
6407 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6408 pte_t *pte)
6409diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6410index a9cbd3b..3b67efa 100644
6411--- a/arch/powerpc/include/asm/pgtable.h
6412+++ b/arch/powerpc/include/asm/pgtable.h
6413@@ -2,6 +2,7 @@
6414 #define _ASM_POWERPC_PGTABLE_H
6415 #ifdef __KERNEL__
6416
6417+#include <linux/const.h>
6418 #ifndef __ASSEMBLY__
6419 #include <asm/processor.h> /* For TASK_SIZE */
6420 #include <asm/mmu.h>
6421diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6422index 4aad413..85d86bf 100644
6423--- a/arch/powerpc/include/asm/pte-hash32.h
6424+++ b/arch/powerpc/include/asm/pte-hash32.h
6425@@ -21,6 +21,7 @@
6426 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6427 #define _PAGE_USER 0x004 /* usermode access allowed */
6428 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6429+#define _PAGE_EXEC _PAGE_GUARDED
6430 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6431 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6432 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6433diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6434index 3d5c9dc..62f8414 100644
6435--- a/arch/powerpc/include/asm/reg.h
6436+++ b/arch/powerpc/include/asm/reg.h
6437@@ -215,6 +215,7 @@
6438 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6439 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6440 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6441+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6442 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6443 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6444 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6445diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6446index 406b7b9..af63426 100644
6447--- a/arch/powerpc/include/asm/thread_info.h
6448+++ b/arch/powerpc/include/asm/thread_info.h
6449@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6450 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6451 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6452 #define TIF_SINGLESTEP 8 /* singlestepping active */
6453-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6454 #define TIF_SECCOMP 10 /* secure computing */
6455 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6456 #define TIF_NOERROR 12 /* Force successful syscall return */
6457@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6458 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6459 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6460 for stack store? */
6461+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6462+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6463+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6464
6465 /* as above, but as bit values */
6466 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6467@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6468 #define _TIF_UPROBE (1<<TIF_UPROBE)
6469 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6470 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6471+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6472 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6473- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6474+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6475+ _TIF_GRSEC_SETXID)
6476
6477 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6478 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6479diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6480index 4db4959..335e00c 100644
6481--- a/arch/powerpc/include/asm/uaccess.h
6482+++ b/arch/powerpc/include/asm/uaccess.h
6483@@ -13,6 +13,8 @@
6484 #define VERIFY_READ 0
6485 #define VERIFY_WRITE 1
6486
6487+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6488+
6489 /*
6490 * The fs value determines whether argument validity checking should be
6491 * performed or not. If get_fs() == USER_DS, checking is performed, with
6492@@ -318,52 +320,6 @@ do { \
6493 extern unsigned long __copy_tofrom_user(void __user *to,
6494 const void __user *from, unsigned long size);
6495
6496-#ifndef __powerpc64__
6497-
6498-static inline unsigned long copy_from_user(void *to,
6499- const void __user *from, unsigned long n)
6500-{
6501- unsigned long over;
6502-
6503- if (access_ok(VERIFY_READ, from, n))
6504- return __copy_tofrom_user((__force void __user *)to, from, n);
6505- if ((unsigned long)from < TASK_SIZE) {
6506- over = (unsigned long)from + n - TASK_SIZE;
6507- return __copy_tofrom_user((__force void __user *)to, from,
6508- n - over) + over;
6509- }
6510- return n;
6511-}
6512-
6513-static inline unsigned long copy_to_user(void __user *to,
6514- const void *from, unsigned long n)
6515-{
6516- unsigned long over;
6517-
6518- if (access_ok(VERIFY_WRITE, to, n))
6519- return __copy_tofrom_user(to, (__force void __user *)from, n);
6520- if ((unsigned long)to < TASK_SIZE) {
6521- over = (unsigned long)to + n - TASK_SIZE;
6522- return __copy_tofrom_user(to, (__force void __user *)from,
6523- n - over) + over;
6524- }
6525- return n;
6526-}
6527-
6528-#else /* __powerpc64__ */
6529-
6530-#define __copy_in_user(to, from, size) \
6531- __copy_tofrom_user((to), (from), (size))
6532-
6533-extern unsigned long copy_from_user(void *to, const void __user *from,
6534- unsigned long n);
6535-extern unsigned long copy_to_user(void __user *to, const void *from,
6536- unsigned long n);
6537-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6538- unsigned long n);
6539-
6540-#endif /* __powerpc64__ */
6541-
6542 static inline unsigned long __copy_from_user_inatomic(void *to,
6543 const void __user *from, unsigned long n)
6544 {
6545@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6546 if (ret == 0)
6547 return 0;
6548 }
6549+
6550+ if (!__builtin_constant_p(n))
6551+ check_object_size(to, n, false);
6552+
6553 return __copy_tofrom_user((__force void __user *)to, from, n);
6554 }
6555
6556@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6557 if (ret == 0)
6558 return 0;
6559 }
6560+
6561+ if (!__builtin_constant_p(n))
6562+ check_object_size(from, n, true);
6563+
6564 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6565 }
6566
6567@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6568 return __copy_to_user_inatomic(to, from, size);
6569 }
6570
6571+#ifndef __powerpc64__
6572+
6573+static inline unsigned long __must_check copy_from_user(void *to,
6574+ const void __user *from, unsigned long n)
6575+{
6576+ unsigned long over;
6577+
6578+ if ((long)n < 0)
6579+ return n;
6580+
6581+ if (access_ok(VERIFY_READ, from, n)) {
6582+ if (!__builtin_constant_p(n))
6583+ check_object_size(to, n, false);
6584+ return __copy_tofrom_user((__force void __user *)to, from, n);
6585+ }
6586+ if ((unsigned long)from < TASK_SIZE) {
6587+ over = (unsigned long)from + n - TASK_SIZE;
6588+ if (!__builtin_constant_p(n - over))
6589+ check_object_size(to, n - over, false);
6590+ return __copy_tofrom_user((__force void __user *)to, from,
6591+ n - over) + over;
6592+ }
6593+ return n;
6594+}
6595+
6596+static inline unsigned long __must_check copy_to_user(void __user *to,
6597+ const void *from, unsigned long n)
6598+{
6599+ unsigned long over;
6600+
6601+ if ((long)n < 0)
6602+ return n;
6603+
6604+ if (access_ok(VERIFY_WRITE, to, n)) {
6605+ if (!__builtin_constant_p(n))
6606+ check_object_size(from, n, true);
6607+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6608+ }
6609+ if ((unsigned long)to < TASK_SIZE) {
6610+ over = (unsigned long)to + n - TASK_SIZE;
6611+ if (!__builtin_constant_p(n))
6612+ check_object_size(from, n - over, true);
6613+ return __copy_tofrom_user(to, (__force void __user *)from,
6614+ n - over) + over;
6615+ }
6616+ return n;
6617+}
6618+
6619+#else /* __powerpc64__ */
6620+
6621+#define __copy_in_user(to, from, size) \
6622+ __copy_tofrom_user((to), (from), (size))
6623+
6624+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6625+{
6626+ if ((long)n < 0 || n > INT_MAX)
6627+ return n;
6628+
6629+ if (!__builtin_constant_p(n))
6630+ check_object_size(to, n, false);
6631+
6632+ if (likely(access_ok(VERIFY_READ, from, n)))
6633+ n = __copy_from_user(to, from, n);
6634+ else
6635+ memset(to, 0, n);
6636+ return n;
6637+}
6638+
6639+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6640+{
6641+ if ((long)n < 0 || n > INT_MAX)
6642+ return n;
6643+
6644+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6645+ if (!__builtin_constant_p(n))
6646+ check_object_size(from, n, true);
6647+ n = __copy_to_user(to, from, n);
6648+ }
6649+ return n;
6650+}
6651+
6652+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6653+ unsigned long n);
6654+
6655+#endif /* __powerpc64__ */
6656+
6657 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6658
6659 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6660diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6661index 4684e33..acc4d19e 100644
6662--- a/arch/powerpc/kernel/exceptions-64e.S
6663+++ b/arch/powerpc/kernel/exceptions-64e.S
6664@@ -715,6 +715,7 @@ storage_fault_common:
6665 std r14,_DAR(r1)
6666 std r15,_DSISR(r1)
6667 addi r3,r1,STACK_FRAME_OVERHEAD
6668+ bl .save_nvgprs
6669 mr r4,r14
6670 mr r5,r15
6671 ld r14,PACA_EXGEN+EX_R14(r13)
6672@@ -723,8 +724,7 @@ storage_fault_common:
6673 cmpdi r3,0
6674 bne- 1f
6675 b .ret_from_except_lite
6676-1: bl .save_nvgprs
6677- mr r5,r3
6678+1: mr r5,r3
6679 addi r3,r1,STACK_FRAME_OVERHEAD
6680 ld r4,_DAR(r1)
6681 bl .bad_page_fault
6682diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6683index 4665e82..080ea99 100644
6684--- a/arch/powerpc/kernel/exceptions-64s.S
6685+++ b/arch/powerpc/kernel/exceptions-64s.S
6686@@ -1206,10 +1206,10 @@ handle_page_fault:
6687 11: ld r4,_DAR(r1)
6688 ld r5,_DSISR(r1)
6689 addi r3,r1,STACK_FRAME_OVERHEAD
6690+ bl .save_nvgprs
6691 bl .do_page_fault
6692 cmpdi r3,0
6693 beq+ 12f
6694- bl .save_nvgprs
6695 mr r5,r3
6696 addi r3,r1,STACK_FRAME_OVERHEAD
6697 lwz r4,_DAR(r1)
6698diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6699index 2e3200c..72095ce 100644
6700--- a/arch/powerpc/kernel/module_32.c
6701+++ b/arch/powerpc/kernel/module_32.c
6702@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6703 me->arch.core_plt_section = i;
6704 }
6705 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6706- printk("Module doesn't contain .plt or .init.plt sections.\n");
6707+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6708 return -ENOEXEC;
6709 }
6710
6711@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6712
6713 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6714 /* Init, or core PLT? */
6715- if (location >= mod->module_core
6716- && location < mod->module_core + mod->core_size)
6717+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6718+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6719 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6720- else
6721+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6722+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6723 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6724+ else {
6725+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6726+ return ~0UL;
6727+ }
6728
6729 /* Find this entry, or if that fails, the next avail. entry */
6730 while (entry->jump[0]) {
6731diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6732index 8143067..21ae55b 100644
6733--- a/arch/powerpc/kernel/process.c
6734+++ b/arch/powerpc/kernel/process.c
6735@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6736 * Lookup NIP late so we have the best change of getting the
6737 * above info out without failing
6738 */
6739- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6740- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6741+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6742+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6743 #endif
6744 show_stack(current, (unsigned long *) regs->gpr[1]);
6745 if (!user_mode(regs))
6746@@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6747 newsp = stack[0];
6748 ip = stack[STACK_FRAME_LR_SAVE];
6749 if (!firstframe || ip != lr) {
6750- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6751+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6752 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6753 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6754- printk(" (%pS)",
6755+ printk(" (%pA)",
6756 (void *)current->ret_stack[curr_frame].ret);
6757 curr_frame--;
6758 }
6759@@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6760 struct pt_regs *regs = (struct pt_regs *)
6761 (sp + STACK_FRAME_OVERHEAD);
6762 lr = regs->link;
6763- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6764+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6765 regs->trap, (void *)regs->nip, (void *)lr);
6766 firstframe = 1;
6767 }
6768@@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6769 mtspr(SPRN_CTRLT, ctrl);
6770 }
6771 #endif /* CONFIG_PPC64 */
6772-
6773-unsigned long arch_align_stack(unsigned long sp)
6774-{
6775- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6776- sp -= get_random_int() & ~PAGE_MASK;
6777- return sp & ~0xf;
6778-}
6779-
6780-static inline unsigned long brk_rnd(void)
6781-{
6782- unsigned long rnd = 0;
6783-
6784- /* 8MB for 32bit, 1GB for 64bit */
6785- if (is_32bit_task())
6786- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6787- else
6788- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6789-
6790- return rnd << PAGE_SHIFT;
6791-}
6792-
6793-unsigned long arch_randomize_brk(struct mm_struct *mm)
6794-{
6795- unsigned long base = mm->brk;
6796- unsigned long ret;
6797-
6798-#ifdef CONFIG_PPC_STD_MMU_64
6799- /*
6800- * If we are using 1TB segments and we are allowed to randomise
6801- * the heap, we can put it above 1TB so it is backed by a 1TB
6802- * segment. Otherwise the heap will be in the bottom 1TB
6803- * which always uses 256MB segments and this may result in a
6804- * performance penalty.
6805- */
6806- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6807- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6808-#endif
6809-
6810- ret = PAGE_ALIGN(base + brk_rnd());
6811-
6812- if (ret < mm->brk)
6813- return mm->brk;
6814-
6815- return ret;
6816-}
6817-
6818-unsigned long randomize_et_dyn(unsigned long base)
6819-{
6820- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6821-
6822- if (ret < base)
6823- return base;
6824-
6825- return ret;
6826-}
6827diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6828index c497000..8fde506 100644
6829--- a/arch/powerpc/kernel/ptrace.c
6830+++ b/arch/powerpc/kernel/ptrace.c
6831@@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6832 return ret;
6833 }
6834
6835+#ifdef CONFIG_GRKERNSEC_SETXID
6836+extern void gr_delayed_cred_worker(void);
6837+#endif
6838+
6839 /*
6840 * We must return the syscall number to actually look up in the table.
6841 * This can be -1L to skip running any syscall at all.
6842@@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6843
6844 secure_computing_strict(regs->gpr[0]);
6845
6846+#ifdef CONFIG_GRKERNSEC_SETXID
6847+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6848+ gr_delayed_cred_worker();
6849+#endif
6850+
6851 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6852 tracehook_report_syscall_entry(regs))
6853 /*
6854@@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6855 {
6856 int step;
6857
6858+#ifdef CONFIG_GRKERNSEC_SETXID
6859+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6860+ gr_delayed_cred_worker();
6861+#endif
6862+
6863 audit_syscall_exit(regs);
6864
6865 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6866diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6867index 804e323..79181c1 100644
6868--- a/arch/powerpc/kernel/signal_32.c
6869+++ b/arch/powerpc/kernel/signal_32.c
6870@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6871 /* Save user registers on the stack */
6872 frame = &rt_sf->uc.uc_mcontext;
6873 addr = frame;
6874- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6875+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6876 if (save_user_regs(regs, frame, 0, 1))
6877 goto badframe;
6878 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6879diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6880index 1ca045d..139c3f7 100644
6881--- a/arch/powerpc/kernel/signal_64.c
6882+++ b/arch/powerpc/kernel/signal_64.c
6883@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6884 current->thread.fpscr.val = 0;
6885
6886 /* Set up to return from userspace. */
6887- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6888+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6889 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6890 } else {
6891 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6892diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6893index 3ce1f86..c30e629 100644
6894--- a/arch/powerpc/kernel/sysfs.c
6895+++ b/arch/powerpc/kernel/sysfs.c
6896@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6897 return NOTIFY_OK;
6898 }
6899
6900-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6901+static struct notifier_block sysfs_cpu_nb = {
6902 .notifier_call = sysfs_cpu_notify,
6903 };
6904
6905diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6906index 3251840..3f7c77a 100644
6907--- a/arch/powerpc/kernel/traps.c
6908+++ b/arch/powerpc/kernel/traps.c
6909@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6910 return flags;
6911 }
6912
6913+extern void gr_handle_kernel_exploit(void);
6914+
6915 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6916 int signr)
6917 {
6918@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6919 panic("Fatal exception in interrupt");
6920 if (panic_on_oops)
6921 panic("Fatal exception");
6922+
6923+ gr_handle_kernel_exploit();
6924+
6925 do_exit(signr);
6926 }
6927
6928diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6929index 1b2076f..835e4be 100644
6930--- a/arch/powerpc/kernel/vdso.c
6931+++ b/arch/powerpc/kernel/vdso.c
6932@@ -34,6 +34,7 @@
6933 #include <asm/firmware.h>
6934 #include <asm/vdso.h>
6935 #include <asm/vdso_datapage.h>
6936+#include <asm/mman.h>
6937
6938 #include "setup.h"
6939
6940@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6941 vdso_base = VDSO32_MBASE;
6942 #endif
6943
6944- current->mm->context.vdso_base = 0;
6945+ current->mm->context.vdso_base = ~0UL;
6946
6947 /* vDSO has a problem and was disabled, just don't "enable" it for the
6948 * process
6949@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6950 vdso_base = get_unmapped_area(NULL, vdso_base,
6951 (vdso_pages << PAGE_SHIFT) +
6952 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6953- 0, 0);
6954+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6955 if (IS_ERR_VALUE(vdso_base)) {
6956 rc = vdso_base;
6957 goto fail_mmapsem;
6958diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6959index 5eea6f3..5d10396 100644
6960--- a/arch/powerpc/lib/usercopy_64.c
6961+++ b/arch/powerpc/lib/usercopy_64.c
6962@@ -9,22 +9,6 @@
6963 #include <linux/module.h>
6964 #include <asm/uaccess.h>
6965
6966-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6967-{
6968- if (likely(access_ok(VERIFY_READ, from, n)))
6969- n = __copy_from_user(to, from, n);
6970- else
6971- memset(to, 0, n);
6972- return n;
6973-}
6974-
6975-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6976-{
6977- if (likely(access_ok(VERIFY_WRITE, to, n)))
6978- n = __copy_to_user(to, from, n);
6979- return n;
6980-}
6981-
6982 unsigned long copy_in_user(void __user *to, const void __user *from,
6983 unsigned long n)
6984 {
6985@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6986 return n;
6987 }
6988
6989-EXPORT_SYMBOL(copy_from_user);
6990-EXPORT_SYMBOL(copy_to_user);
6991 EXPORT_SYMBOL(copy_in_user);
6992
6993diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6994index 3a8489a..6a63b3b 100644
6995--- a/arch/powerpc/mm/fault.c
6996+++ b/arch/powerpc/mm/fault.c
6997@@ -32,6 +32,10 @@
6998 #include <linux/perf_event.h>
6999 #include <linux/magic.h>
7000 #include <linux/ratelimit.h>
7001+#include <linux/slab.h>
7002+#include <linux/pagemap.h>
7003+#include <linux/compiler.h>
7004+#include <linux/unistd.h>
7005
7006 #include <asm/firmware.h>
7007 #include <asm/page.h>
7008@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
7009 }
7010 #endif
7011
7012+#ifdef CONFIG_PAX_PAGEEXEC
7013+/*
7014+ * PaX: decide what to do with offenders (regs->nip = fault address)
7015+ *
7016+ * returns 1 when task should be killed
7017+ */
7018+static int pax_handle_fetch_fault(struct pt_regs *regs)
7019+{
7020+ return 1;
7021+}
7022+
7023+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7024+{
7025+ unsigned long i;
7026+
7027+ printk(KERN_ERR "PAX: bytes at PC: ");
7028+ for (i = 0; i < 5; i++) {
7029+ unsigned int c;
7030+ if (get_user(c, (unsigned int __user *)pc+i))
7031+ printk(KERN_CONT "???????? ");
7032+ else
7033+ printk(KERN_CONT "%08x ", c);
7034+ }
7035+ printk("\n");
7036+}
7037+#endif
7038+
7039 /*
7040 * Check whether the instruction at regs->nip is a store using
7041 * an update addressing form which will update r1.
7042@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7043 * indicate errors in DSISR but can validly be set in SRR1.
7044 */
7045 if (trap == 0x400)
7046- error_code &= 0x48200000;
7047+ error_code &= 0x58200000;
7048 else
7049 is_write = error_code & DSISR_ISSTORE;
7050 #else
7051@@ -364,7 +395,7 @@ good_area:
7052 * "undefined". Of those that can be set, this is the only
7053 * one which seems bad.
7054 */
7055- if (error_code & 0x10000000)
7056+ if (error_code & DSISR_GUARDED)
7057 /* Guarded storage error. */
7058 goto bad_area;
7059 #endif /* CONFIG_8xx */
7060@@ -379,7 +410,7 @@ good_area:
7061 * processors use the same I/D cache coherency mechanism
7062 * as embedded.
7063 */
7064- if (error_code & DSISR_PROTFAULT)
7065+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7066 goto bad_area;
7067 #endif /* CONFIG_PPC_STD_MMU */
7068
7069@@ -462,6 +493,23 @@ bad_area:
7070 bad_area_nosemaphore:
7071 /* User mode accesses cause a SIGSEGV */
7072 if (user_mode(regs)) {
7073+
7074+#ifdef CONFIG_PAX_PAGEEXEC
7075+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7076+#ifdef CONFIG_PPC_STD_MMU
7077+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7078+#else
7079+ if (is_exec && regs->nip == address) {
7080+#endif
7081+ switch (pax_handle_fetch_fault(regs)) {
7082+ }
7083+
7084+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7085+ do_group_exit(SIGKILL);
7086+ }
7087+ }
7088+#endif
7089+
7090 _exception(SIGSEGV, regs, code, address);
7091 return 0;
7092 }
7093diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7094index 67a42ed..cd463e0 100644
7095--- a/arch/powerpc/mm/mmap_64.c
7096+++ b/arch/powerpc/mm/mmap_64.c
7097@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7098 {
7099 unsigned long rnd = 0;
7100
7101+#ifdef CONFIG_PAX_RANDMMAP
7102+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7103+#endif
7104+
7105 if (current->flags & PF_RANDOMIZE) {
7106 /* 8MB for 32bit, 1GB for 64bit */
7107 if (is_32bit_task())
7108@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7109 */
7110 if (mmap_is_legacy()) {
7111 mm->mmap_base = TASK_UNMAPPED_BASE;
7112+
7113+#ifdef CONFIG_PAX_RANDMMAP
7114+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7115+ mm->mmap_base += mm->delta_mmap;
7116+#endif
7117+
7118 mm->get_unmapped_area = arch_get_unmapped_area;
7119 mm->unmap_area = arch_unmap_area;
7120 } else {
7121 mm->mmap_base = mmap_base();
7122+
7123+#ifdef CONFIG_PAX_RANDMMAP
7124+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7125+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7126+#endif
7127+
7128 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7129 mm->unmap_area = arch_unmap_area_topdown;
7130 }
7131diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7132index e779642..e5bb889 100644
7133--- a/arch/powerpc/mm/mmu_context_nohash.c
7134+++ b/arch/powerpc/mm/mmu_context_nohash.c
7135@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7136 return NOTIFY_OK;
7137 }
7138
7139-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7140+static struct notifier_block mmu_context_cpu_nb = {
7141 .notifier_call = mmu_context_cpu_notify,
7142 };
7143
7144diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7145index bba87ca..c346a33 100644
7146--- a/arch/powerpc/mm/numa.c
7147+++ b/arch/powerpc/mm/numa.c
7148@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7149 return ret;
7150 }
7151
7152-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7153+static struct notifier_block ppc64_numa_nb = {
7154 .notifier_call = cpu_numa_callback,
7155 .priority = 1 /* Must run before sched domains notifier. */
7156 };
7157diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7158index cf9dada..241529f 100644
7159--- a/arch/powerpc/mm/slice.c
7160+++ b/arch/powerpc/mm/slice.c
7161@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7162 if ((mm->task_size - len) < addr)
7163 return 0;
7164 vma = find_vma(mm, addr);
7165- return (!vma || (addr + len) <= vma->vm_start);
7166+ return check_heap_stack_gap(vma, addr, len, 0);
7167 }
7168
7169 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7170@@ -272,7 +272,7 @@ full_search:
7171 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
7172 continue;
7173 }
7174- if (!vma || addr + len <= vma->vm_start) {
7175+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7176 /*
7177 * Remember the place where we stopped the search:
7178 */
7179@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7180 }
7181 }
7182
7183- addr = mm->mmap_base;
7184- while (addr > len) {
7185+ if (mm->mmap_base < len)
7186+ addr = -ENOMEM;
7187+ else
7188+ addr = mm->mmap_base - len;
7189+
7190+ while (!IS_ERR_VALUE(addr)) {
7191 /* Go down by chunk size */
7192- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
7193+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
7194
7195 /* Check for hit with different page size */
7196 mask = slice_range_to_mask(addr, len);
7197@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7198 * return with success:
7199 */
7200 vma = find_vma(mm, addr);
7201- if (!vma || (addr + len) <= vma->vm_start) {
7202+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7203 /* remember the address as a hint for next time */
7204 if (use_cache)
7205 mm->free_area_cache = addr;
7206@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7207 mm->cached_hole_size = vma->vm_start - addr;
7208
7209 /* try just below the current vma->vm_start */
7210- addr = vma->vm_start;
7211+ addr = skip_heap_stack_gap(vma, len, 0);
7212 }
7213
7214 /*
7215@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7216 if (fixed && addr > (mm->task_size - len))
7217 return -EINVAL;
7218
7219+#ifdef CONFIG_PAX_RANDMMAP
7220+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7221+ addr = 0;
7222+#endif
7223+
7224 /* If hint, make sure it matches our alignment restrictions */
7225 if (!fixed && addr) {
7226 addr = _ALIGN_UP(addr, 1ul << pshift);
7227diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7228index bdb738a..49c9f95 100644
7229--- a/arch/powerpc/platforms/powermac/smp.c
7230+++ b/arch/powerpc/platforms/powermac/smp.c
7231@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7232 return NOTIFY_OK;
7233 }
7234
7235-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7236+static struct notifier_block smp_core99_cpu_nb = {
7237 .notifier_call = smp_core99_cpu_notify,
7238 };
7239 #endif /* CONFIG_HOTPLUG_CPU */
7240diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7241index c797832..ce575c8 100644
7242--- a/arch/s390/include/asm/atomic.h
7243+++ b/arch/s390/include/asm/atomic.h
7244@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7245 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7246 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7247
7248+#define atomic64_read_unchecked(v) atomic64_read(v)
7249+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7250+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7251+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7252+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7253+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7254+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7255+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7256+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7257+
7258 #define smp_mb__before_atomic_dec() smp_mb()
7259 #define smp_mb__after_atomic_dec() smp_mb()
7260 #define smp_mb__before_atomic_inc() smp_mb()
7261diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7262index 4d7ccac..d03d0ad 100644
7263--- a/arch/s390/include/asm/cache.h
7264+++ b/arch/s390/include/asm/cache.h
7265@@ -9,8 +9,10 @@
7266 #ifndef __ARCH_S390_CACHE_H
7267 #define __ARCH_S390_CACHE_H
7268
7269-#define L1_CACHE_BYTES 256
7270+#include <linux/const.h>
7271+
7272 #define L1_CACHE_SHIFT 8
7273+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7274 #define NET_SKB_PAD 32
7275
7276 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7277diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7278index 178ff96..8c93bd1 100644
7279--- a/arch/s390/include/asm/elf.h
7280+++ b/arch/s390/include/asm/elf.h
7281@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7282 the loader. We need to make sure that it is out of the way of the program
7283 that it will "exec", and that there is sufficient room for the brk. */
7284
7285-extern unsigned long randomize_et_dyn(unsigned long base);
7286-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7287+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7288+
7289+#ifdef CONFIG_PAX_ASLR
7290+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7291+
7292+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7293+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7294+#endif
7295
7296 /* This yields a mask that user programs can use to figure out what
7297 instruction set this CPU supports. */
7298@@ -210,9 +216,6 @@ struct linux_binprm;
7299 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7300 int arch_setup_additional_pages(struct linux_binprm *, int);
7301
7302-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7303-#define arch_randomize_brk arch_randomize_brk
7304-
7305 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7306
7307 #endif
7308diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7309index c4a93d6..4d2a9b4 100644
7310--- a/arch/s390/include/asm/exec.h
7311+++ b/arch/s390/include/asm/exec.h
7312@@ -7,6 +7,6 @@
7313 #ifndef __ASM_EXEC_H
7314 #define __ASM_EXEC_H
7315
7316-extern unsigned long arch_align_stack(unsigned long sp);
7317+#define arch_align_stack(x) ((x) & ~0xfUL)
7318
7319 #endif /* __ASM_EXEC_H */
7320diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7321index 34268df..ea97318 100644
7322--- a/arch/s390/include/asm/uaccess.h
7323+++ b/arch/s390/include/asm/uaccess.h
7324@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7325 copy_to_user(void __user *to, const void *from, unsigned long n)
7326 {
7327 might_fault();
7328+
7329+ if ((long)n < 0)
7330+ return n;
7331+
7332 if (access_ok(VERIFY_WRITE, to, n))
7333 n = __copy_to_user(to, from, n);
7334 return n;
7335@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7336 static inline unsigned long __must_check
7337 __copy_from_user(void *to, const void __user *from, unsigned long n)
7338 {
7339+ if ((long)n < 0)
7340+ return n;
7341+
7342 if (__builtin_constant_p(n) && (n <= 256))
7343 return uaccess.copy_from_user_small(n, from, to);
7344 else
7345@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7346 static inline unsigned long __must_check
7347 copy_from_user(void *to, const void __user *from, unsigned long n)
7348 {
7349- unsigned int sz = __compiletime_object_size(to);
7350+ size_t sz = __compiletime_object_size(to);
7351
7352 might_fault();
7353- if (unlikely(sz != -1 && sz < n)) {
7354+
7355+ if ((long)n < 0)
7356+ return n;
7357+
7358+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7359 copy_from_user_overflow();
7360 return n;
7361 }
7362diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7363index 4610dea..cf0af21 100644
7364--- a/arch/s390/kernel/module.c
7365+++ b/arch/s390/kernel/module.c
7366@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7367
7368 /* Increase core size by size of got & plt and set start
7369 offsets for got and plt. */
7370- me->core_size = ALIGN(me->core_size, 4);
7371- me->arch.got_offset = me->core_size;
7372- me->core_size += me->arch.got_size;
7373- me->arch.plt_offset = me->core_size;
7374- me->core_size += me->arch.plt_size;
7375+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7376+ me->arch.got_offset = me->core_size_rw;
7377+ me->core_size_rw += me->arch.got_size;
7378+ me->arch.plt_offset = me->core_size_rx;
7379+ me->core_size_rx += me->arch.plt_size;
7380 return 0;
7381 }
7382
7383@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7384 if (info->got_initialized == 0) {
7385 Elf_Addr *gotent;
7386
7387- gotent = me->module_core + me->arch.got_offset +
7388+ gotent = me->module_core_rw + me->arch.got_offset +
7389 info->got_offset;
7390 *gotent = val;
7391 info->got_initialized = 1;
7392@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7393 else if (r_type == R_390_GOTENT ||
7394 r_type == R_390_GOTPLTENT)
7395 *(unsigned int *) loc =
7396- (val + (Elf_Addr) me->module_core - loc) >> 1;
7397+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7398 else if (r_type == R_390_GOT64 ||
7399 r_type == R_390_GOTPLT64)
7400 *(unsigned long *) loc = val;
7401@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7402 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7403 if (info->plt_initialized == 0) {
7404 unsigned int *ip;
7405- ip = me->module_core + me->arch.plt_offset +
7406+ ip = me->module_core_rx + me->arch.plt_offset +
7407 info->plt_offset;
7408 #ifndef CONFIG_64BIT
7409 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7410@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7411 val - loc + 0xffffUL < 0x1ffffeUL) ||
7412 (r_type == R_390_PLT32DBL &&
7413 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7414- val = (Elf_Addr) me->module_core +
7415+ val = (Elf_Addr) me->module_core_rx +
7416 me->arch.plt_offset +
7417 info->plt_offset;
7418 val += rela->r_addend - loc;
7419@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7420 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7421 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7422 val = val + rela->r_addend -
7423- ((Elf_Addr) me->module_core + me->arch.got_offset);
7424+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7425 if (r_type == R_390_GOTOFF16)
7426 *(unsigned short *) loc = val;
7427 else if (r_type == R_390_GOTOFF32)
7428@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7429 break;
7430 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7431 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7432- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7433+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7434 rela->r_addend - loc;
7435 if (r_type == R_390_GOTPC)
7436 *(unsigned int *) loc = val;
7437diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7438index 536d645..4a5bd9e 100644
7439--- a/arch/s390/kernel/process.c
7440+++ b/arch/s390/kernel/process.c
7441@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7442 }
7443 return 0;
7444 }
7445-
7446-unsigned long arch_align_stack(unsigned long sp)
7447-{
7448- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7449- sp -= get_random_int() & ~PAGE_MASK;
7450- return sp & ~0xf;
7451-}
7452-
7453-static inline unsigned long brk_rnd(void)
7454-{
7455- /* 8MB for 32bit, 1GB for 64bit */
7456- if (is_32bit_task())
7457- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7458- else
7459- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7460-}
7461-
7462-unsigned long arch_randomize_brk(struct mm_struct *mm)
7463-{
7464- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7465-
7466- if (ret < mm->brk)
7467- return mm->brk;
7468- return ret;
7469-}
7470-
7471-unsigned long randomize_et_dyn(unsigned long base)
7472-{
7473- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7474-
7475- if (!(current->flags & PF_RANDOMIZE))
7476- return base;
7477- if (ret < base)
7478- return base;
7479- return ret;
7480-}
7481diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7482index c59a5ef..3fae59c 100644
7483--- a/arch/s390/mm/mmap.c
7484+++ b/arch/s390/mm/mmap.c
7485@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7486 */
7487 if (mmap_is_legacy()) {
7488 mm->mmap_base = TASK_UNMAPPED_BASE;
7489+
7490+#ifdef CONFIG_PAX_RANDMMAP
7491+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7492+ mm->mmap_base += mm->delta_mmap;
7493+#endif
7494+
7495 mm->get_unmapped_area = arch_get_unmapped_area;
7496 mm->unmap_area = arch_unmap_area;
7497 } else {
7498 mm->mmap_base = mmap_base();
7499+
7500+#ifdef CONFIG_PAX_RANDMMAP
7501+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7502+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7503+#endif
7504+
7505 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7506 mm->unmap_area = arch_unmap_area_topdown;
7507 }
7508@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7509 */
7510 if (mmap_is_legacy()) {
7511 mm->mmap_base = TASK_UNMAPPED_BASE;
7512+
7513+#ifdef CONFIG_PAX_RANDMMAP
7514+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7515+ mm->mmap_base += mm->delta_mmap;
7516+#endif
7517+
7518 mm->get_unmapped_area = s390_get_unmapped_area;
7519 mm->unmap_area = arch_unmap_area;
7520 } else {
7521 mm->mmap_base = mmap_base();
7522+
7523+#ifdef CONFIG_PAX_RANDMMAP
7524+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7525+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7526+#endif
7527+
7528 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7529 mm->unmap_area = arch_unmap_area_topdown;
7530 }
7531diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7532index ae3d59f..f65f075 100644
7533--- a/arch/score/include/asm/cache.h
7534+++ b/arch/score/include/asm/cache.h
7535@@ -1,7 +1,9 @@
7536 #ifndef _ASM_SCORE_CACHE_H
7537 #define _ASM_SCORE_CACHE_H
7538
7539+#include <linux/const.h>
7540+
7541 #define L1_CACHE_SHIFT 4
7542-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7543+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7544
7545 #endif /* _ASM_SCORE_CACHE_H */
7546diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7547index f9f3cd5..58ff438 100644
7548--- a/arch/score/include/asm/exec.h
7549+++ b/arch/score/include/asm/exec.h
7550@@ -1,6 +1,6 @@
7551 #ifndef _ASM_SCORE_EXEC_H
7552 #define _ASM_SCORE_EXEC_H
7553
7554-extern unsigned long arch_align_stack(unsigned long sp);
7555+#define arch_align_stack(x) (x)
7556
7557 #endif /* _ASM_SCORE_EXEC_H */
7558diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7559index 7956846..5f37677 100644
7560--- a/arch/score/kernel/process.c
7561+++ b/arch/score/kernel/process.c
7562@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7563
7564 return task_pt_regs(task)->cp0_epc;
7565 }
7566-
7567-unsigned long arch_align_stack(unsigned long sp)
7568-{
7569- return sp;
7570-}
7571diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7572index ef9e555..331bd29 100644
7573--- a/arch/sh/include/asm/cache.h
7574+++ b/arch/sh/include/asm/cache.h
7575@@ -9,10 +9,11 @@
7576 #define __ASM_SH_CACHE_H
7577 #ifdef __KERNEL__
7578
7579+#include <linux/const.h>
7580 #include <linux/init.h>
7581 #include <cpu/cache.h>
7582
7583-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7584+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7585
7586 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7587
7588diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7589index 03f2b55..b027032 100644
7590--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7591+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7592@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7593 return NOTIFY_OK;
7594 }
7595
7596-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7597+static struct notifier_block shx3_cpu_notifier = {
7598 .notifier_call = shx3_cpu_callback,
7599 };
7600
7601diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7602index 6777177..cb5e44f 100644
7603--- a/arch/sh/mm/mmap.c
7604+++ b/arch/sh/mm/mmap.c
7605@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7606 struct mm_struct *mm = current->mm;
7607 struct vm_area_struct *vma;
7608 int do_colour_align;
7609+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7610 struct vm_unmapped_area_info info;
7611
7612 if (flags & MAP_FIXED) {
7613@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7614 if (filp || (flags & MAP_SHARED))
7615 do_colour_align = 1;
7616
7617+#ifdef CONFIG_PAX_RANDMMAP
7618+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7619+#endif
7620+
7621 if (addr) {
7622 if (do_colour_align)
7623 addr = COLOUR_ALIGN(addr, pgoff);
7624@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7625 addr = PAGE_ALIGN(addr);
7626
7627 vma = find_vma(mm, addr);
7628- if (TASK_SIZE - len >= addr &&
7629- (!vma || addr + len <= vma->vm_start))
7630+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7631 return addr;
7632 }
7633
7634 info.flags = 0;
7635 info.length = len;
7636- info.low_limit = TASK_UNMAPPED_BASE;
7637+ info.low_limit = mm->mmap_base;
7638 info.high_limit = TASK_SIZE;
7639 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7640 info.align_offset = pgoff << PAGE_SHIFT;
7641@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7642 struct mm_struct *mm = current->mm;
7643 unsigned long addr = addr0;
7644 int do_colour_align;
7645+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7646 struct vm_unmapped_area_info info;
7647
7648 if (flags & MAP_FIXED) {
7649@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7650 if (filp || (flags & MAP_SHARED))
7651 do_colour_align = 1;
7652
7653+#ifdef CONFIG_PAX_RANDMMAP
7654+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7655+#endif
7656+
7657 /* requesting a specific address */
7658 if (addr) {
7659 if (do_colour_align)
7660@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7661 addr = PAGE_ALIGN(addr);
7662
7663 vma = find_vma(mm, addr);
7664- if (TASK_SIZE - len >= addr &&
7665- (!vma || addr + len <= vma->vm_start))
7666+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7667 return addr;
7668 }
7669
7670@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7671 VM_BUG_ON(addr != -ENOMEM);
7672 info.flags = 0;
7673 info.low_limit = TASK_UNMAPPED_BASE;
7674+
7675+#ifdef CONFIG_PAX_RANDMMAP
7676+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7677+ info.low_limit += mm->delta_mmap;
7678+#endif
7679+
7680 info.high_limit = TASK_SIZE;
7681 addr = vm_unmapped_area(&info);
7682 }
7683diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7684index be56a24..443328f 100644
7685--- a/arch/sparc/include/asm/atomic_64.h
7686+++ b/arch/sparc/include/asm/atomic_64.h
7687@@ -14,18 +14,40 @@
7688 #define ATOMIC64_INIT(i) { (i) }
7689
7690 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7691+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7692+{
7693+ return v->counter;
7694+}
7695 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7696+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7697+{
7698+ return v->counter;
7699+}
7700
7701 #define atomic_set(v, i) (((v)->counter) = i)
7702+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7703+{
7704+ v->counter = i;
7705+}
7706 #define atomic64_set(v, i) (((v)->counter) = i)
7707+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7708+{
7709+ v->counter = i;
7710+}
7711
7712 extern void atomic_add(int, atomic_t *);
7713+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7714 extern void atomic64_add(long, atomic64_t *);
7715+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7716 extern void atomic_sub(int, atomic_t *);
7717+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7718 extern void atomic64_sub(long, atomic64_t *);
7719+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7720
7721 extern int atomic_add_ret(int, atomic_t *);
7722+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7723 extern long atomic64_add_ret(long, atomic64_t *);
7724+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7725 extern int atomic_sub_ret(int, atomic_t *);
7726 extern long atomic64_sub_ret(long, atomic64_t *);
7727
7728@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7729 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7730
7731 #define atomic_inc_return(v) atomic_add_ret(1, v)
7732+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7733+{
7734+ return atomic_add_ret_unchecked(1, v);
7735+}
7736 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7737+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7738+{
7739+ return atomic64_add_ret_unchecked(1, v);
7740+}
7741
7742 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7743 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7744
7745 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7746+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7747+{
7748+ return atomic_add_ret_unchecked(i, v);
7749+}
7750 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7751+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7752+{
7753+ return atomic64_add_ret_unchecked(i, v);
7754+}
7755
7756 /*
7757 * atomic_inc_and_test - increment and test
7758@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7759 * other cases.
7760 */
7761 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7762+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7763+{
7764+ return atomic_inc_return_unchecked(v) == 0;
7765+}
7766 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7767
7768 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7769@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7770 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7771
7772 #define atomic_inc(v) atomic_add(1, v)
7773+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7774+{
7775+ atomic_add_unchecked(1, v);
7776+}
7777 #define atomic64_inc(v) atomic64_add(1, v)
7778+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7779+{
7780+ atomic64_add_unchecked(1, v);
7781+}
7782
7783 #define atomic_dec(v) atomic_sub(1, v)
7784+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7785+{
7786+ atomic_sub_unchecked(1, v);
7787+}
7788 #define atomic64_dec(v) atomic64_sub(1, v)
7789+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7790+{
7791+ atomic64_sub_unchecked(1, v);
7792+}
7793
7794 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7795 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7796
7797 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7798+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7799+{
7800+ return cmpxchg(&v->counter, old, new);
7801+}
7802 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7803+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7804+{
7805+ return xchg(&v->counter, new);
7806+}
7807
7808 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7809 {
7810- int c, old;
7811+ int c, old, new;
7812 c = atomic_read(v);
7813 for (;;) {
7814- if (unlikely(c == (u)))
7815+ if (unlikely(c == u))
7816 break;
7817- old = atomic_cmpxchg((v), c, c + (a));
7818+
7819+ asm volatile("addcc %2, %0, %0\n"
7820+
7821+#ifdef CONFIG_PAX_REFCOUNT
7822+ "tvs %%icc, 6\n"
7823+#endif
7824+
7825+ : "=r" (new)
7826+ : "0" (c), "ir" (a)
7827+ : "cc");
7828+
7829+ old = atomic_cmpxchg(v, c, new);
7830 if (likely(old == c))
7831 break;
7832 c = old;
7833@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7834 #define atomic64_cmpxchg(v, o, n) \
7835 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7836 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7837+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7838+{
7839+ return xchg(&v->counter, new);
7840+}
7841
7842 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7843 {
7844- long c, old;
7845+ long c, old, new;
7846 c = atomic64_read(v);
7847 for (;;) {
7848- if (unlikely(c == (u)))
7849+ if (unlikely(c == u))
7850 break;
7851- old = atomic64_cmpxchg((v), c, c + (a));
7852+
7853+ asm volatile("addcc %2, %0, %0\n"
7854+
7855+#ifdef CONFIG_PAX_REFCOUNT
7856+ "tvs %%xcc, 6\n"
7857+#endif
7858+
7859+ : "=r" (new)
7860+ : "0" (c), "ir" (a)
7861+ : "cc");
7862+
7863+ old = atomic64_cmpxchg(v, c, new);
7864 if (likely(old == c))
7865 break;
7866 c = old;
7867 }
7868- return c != (u);
7869+ return c != u;
7870 }
7871
7872 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7873diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7874index 5bb6991..5c2132e 100644
7875--- a/arch/sparc/include/asm/cache.h
7876+++ b/arch/sparc/include/asm/cache.h
7877@@ -7,10 +7,12 @@
7878 #ifndef _SPARC_CACHE_H
7879 #define _SPARC_CACHE_H
7880
7881+#include <linux/const.h>
7882+
7883 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7884
7885 #define L1_CACHE_SHIFT 5
7886-#define L1_CACHE_BYTES 32
7887+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7888
7889 #ifdef CONFIG_SPARC32
7890 #define SMP_CACHE_BYTES_SHIFT 5
7891diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7892index ac74a2c..a9e58af 100644
7893--- a/arch/sparc/include/asm/elf_32.h
7894+++ b/arch/sparc/include/asm/elf_32.h
7895@@ -114,6 +114,13 @@ typedef struct {
7896
7897 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7898
7899+#ifdef CONFIG_PAX_ASLR
7900+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7901+
7902+#define PAX_DELTA_MMAP_LEN 16
7903+#define PAX_DELTA_STACK_LEN 16
7904+#endif
7905+
7906 /* This yields a mask that user programs can use to figure out what
7907 instruction set this cpu supports. This can NOT be done in userspace
7908 on Sparc. */
7909diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7910index 370ca1e..d4f4a98 100644
7911--- a/arch/sparc/include/asm/elf_64.h
7912+++ b/arch/sparc/include/asm/elf_64.h
7913@@ -189,6 +189,13 @@ typedef struct {
7914 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7915 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7916
7917+#ifdef CONFIG_PAX_ASLR
7918+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7919+
7920+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7921+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7922+#endif
7923+
7924 extern unsigned long sparc64_elf_hwcap;
7925 #define ELF_HWCAP sparc64_elf_hwcap
7926
7927diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7928index 9b1c36d..209298b 100644
7929--- a/arch/sparc/include/asm/pgalloc_32.h
7930+++ b/arch/sparc/include/asm/pgalloc_32.h
7931@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7932 }
7933
7934 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7935+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7936
7937 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7938 unsigned long address)
7939diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7940index bcfe063..b333142 100644
7941--- a/arch/sparc/include/asm/pgalloc_64.h
7942+++ b/arch/sparc/include/asm/pgalloc_64.h
7943@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7944 }
7945
7946 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7947+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7948
7949 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7950 {
7951diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7952index 6fc1348..390c50a 100644
7953--- a/arch/sparc/include/asm/pgtable_32.h
7954+++ b/arch/sparc/include/asm/pgtable_32.h
7955@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7956 #define PAGE_SHARED SRMMU_PAGE_SHARED
7957 #define PAGE_COPY SRMMU_PAGE_COPY
7958 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7959+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7960+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7961+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7962 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7963
7964 /* Top-level page directory - dummy used by init-mm.
7965@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7966
7967 /* xwr */
7968 #define __P000 PAGE_NONE
7969-#define __P001 PAGE_READONLY
7970-#define __P010 PAGE_COPY
7971-#define __P011 PAGE_COPY
7972+#define __P001 PAGE_READONLY_NOEXEC
7973+#define __P010 PAGE_COPY_NOEXEC
7974+#define __P011 PAGE_COPY_NOEXEC
7975 #define __P100 PAGE_READONLY
7976 #define __P101 PAGE_READONLY
7977 #define __P110 PAGE_COPY
7978 #define __P111 PAGE_COPY
7979
7980 #define __S000 PAGE_NONE
7981-#define __S001 PAGE_READONLY
7982-#define __S010 PAGE_SHARED
7983-#define __S011 PAGE_SHARED
7984+#define __S001 PAGE_READONLY_NOEXEC
7985+#define __S010 PAGE_SHARED_NOEXEC
7986+#define __S011 PAGE_SHARED_NOEXEC
7987 #define __S100 PAGE_READONLY
7988 #define __S101 PAGE_READONLY
7989 #define __S110 PAGE_SHARED
7990diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7991index 79da178..c2eede8 100644
7992--- a/arch/sparc/include/asm/pgtsrmmu.h
7993+++ b/arch/sparc/include/asm/pgtsrmmu.h
7994@@ -115,6 +115,11 @@
7995 SRMMU_EXEC | SRMMU_REF)
7996 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7997 SRMMU_EXEC | SRMMU_REF)
7998+
7999+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
8000+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8001+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8002+
8003 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
8004 SRMMU_DIRTY | SRMMU_REF)
8005
8006diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
8007index 9689176..63c18ea 100644
8008--- a/arch/sparc/include/asm/spinlock_64.h
8009+++ b/arch/sparc/include/asm/spinlock_64.h
8010@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
8011
8012 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
8013
8014-static void inline arch_read_lock(arch_rwlock_t *lock)
8015+static inline void arch_read_lock(arch_rwlock_t *lock)
8016 {
8017 unsigned long tmp1, tmp2;
8018
8019 __asm__ __volatile__ (
8020 "1: ldsw [%2], %0\n"
8021 " brlz,pn %0, 2f\n"
8022-"4: add %0, 1, %1\n"
8023+"4: addcc %0, 1, %1\n"
8024+
8025+#ifdef CONFIG_PAX_REFCOUNT
8026+" tvs %%icc, 6\n"
8027+#endif
8028+
8029 " cas [%2], %0, %1\n"
8030 " cmp %0, %1\n"
8031 " bne,pn %%icc, 1b\n"
8032@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8033 " .previous"
8034 : "=&r" (tmp1), "=&r" (tmp2)
8035 : "r" (lock)
8036- : "memory");
8037+ : "memory", "cc");
8038 }
8039
8040-static int inline arch_read_trylock(arch_rwlock_t *lock)
8041+static inline int arch_read_trylock(arch_rwlock_t *lock)
8042 {
8043 int tmp1, tmp2;
8044
8045@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8046 "1: ldsw [%2], %0\n"
8047 " brlz,a,pn %0, 2f\n"
8048 " mov 0, %0\n"
8049-" add %0, 1, %1\n"
8050+" addcc %0, 1, %1\n"
8051+
8052+#ifdef CONFIG_PAX_REFCOUNT
8053+" tvs %%icc, 6\n"
8054+#endif
8055+
8056 " cas [%2], %0, %1\n"
8057 " cmp %0, %1\n"
8058 " bne,pn %%icc, 1b\n"
8059@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8060 return tmp1;
8061 }
8062
8063-static void inline arch_read_unlock(arch_rwlock_t *lock)
8064+static inline void arch_read_unlock(arch_rwlock_t *lock)
8065 {
8066 unsigned long tmp1, tmp2;
8067
8068 __asm__ __volatile__(
8069 "1: lduw [%2], %0\n"
8070-" sub %0, 1, %1\n"
8071+" subcc %0, 1, %1\n"
8072+
8073+#ifdef CONFIG_PAX_REFCOUNT
8074+" tvs %%icc, 6\n"
8075+#endif
8076+
8077 " cas [%2], %0, %1\n"
8078 " cmp %0, %1\n"
8079 " bne,pn %%xcc, 1b\n"
8080@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8081 : "memory");
8082 }
8083
8084-static void inline arch_write_lock(arch_rwlock_t *lock)
8085+static inline void arch_write_lock(arch_rwlock_t *lock)
8086 {
8087 unsigned long mask, tmp1, tmp2;
8088
8089@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8090 : "memory");
8091 }
8092
8093-static void inline arch_write_unlock(arch_rwlock_t *lock)
8094+static inline void arch_write_unlock(arch_rwlock_t *lock)
8095 {
8096 __asm__ __volatile__(
8097 " stw %%g0, [%0]"
8098@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8099 : "memory");
8100 }
8101
8102-static int inline arch_write_trylock(arch_rwlock_t *lock)
8103+static inline int arch_write_trylock(arch_rwlock_t *lock)
8104 {
8105 unsigned long mask, tmp1, tmp2, result;
8106
8107diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8108index 25849ae..924c54b 100644
8109--- a/arch/sparc/include/asm/thread_info_32.h
8110+++ b/arch/sparc/include/asm/thread_info_32.h
8111@@ -49,6 +49,8 @@ struct thread_info {
8112 unsigned long w_saved;
8113
8114 struct restart_block restart_block;
8115+
8116+ unsigned long lowest_stack;
8117 };
8118
8119 /*
8120diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8121index 269bd92..e46a9b8 100644
8122--- a/arch/sparc/include/asm/thread_info_64.h
8123+++ b/arch/sparc/include/asm/thread_info_64.h
8124@@ -63,6 +63,8 @@ struct thread_info {
8125 struct pt_regs *kern_una_regs;
8126 unsigned int kern_una_insn;
8127
8128+ unsigned long lowest_stack;
8129+
8130 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8131 };
8132
8133@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8134 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8135 /* flag bit 6 is available */
8136 #define TIF_32BIT 7 /* 32-bit binary */
8137-/* flag bit 8 is available */
8138+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8139 #define TIF_SECCOMP 9 /* secure computing */
8140 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8141 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8142+
8143 /* NOTE: Thread flags >= 12 should be ones we have no interest
8144 * in using in assembly, else we can't use the mask as
8145 * an immediate value in instructions such as andcc.
8146@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8147 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8148 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8149 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8150+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8151
8152 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8153 _TIF_DO_NOTIFY_RESUME_MASK | \
8154 _TIF_NEED_RESCHED)
8155 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8156
8157+#define _TIF_WORK_SYSCALL \
8158+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8159+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8160+
8161+
8162 /*
8163 * Thread-synchronous status.
8164 *
8165diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8166index 0167d26..9acd8ed 100644
8167--- a/arch/sparc/include/asm/uaccess.h
8168+++ b/arch/sparc/include/asm/uaccess.h
8169@@ -1,5 +1,13 @@
8170 #ifndef ___ASM_SPARC_UACCESS_H
8171 #define ___ASM_SPARC_UACCESS_H
8172+
8173+#ifdef __KERNEL__
8174+#ifndef __ASSEMBLY__
8175+#include <linux/types.h>
8176+extern void check_object_size(const void *ptr, unsigned long n, bool to);
8177+#endif
8178+#endif
8179+
8180 #if defined(__sparc__) && defined(__arch64__)
8181 #include <asm/uaccess_64.h>
8182 #else
8183diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8184index 53a28dd..50c38c3 100644
8185--- a/arch/sparc/include/asm/uaccess_32.h
8186+++ b/arch/sparc/include/asm/uaccess_32.h
8187@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8188
8189 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8190 {
8191- if (n && __access_ok((unsigned long) to, n))
8192+ if ((long)n < 0)
8193+ return n;
8194+
8195+ if (n && __access_ok((unsigned long) to, n)) {
8196+ if (!__builtin_constant_p(n))
8197+ check_object_size(from, n, true);
8198 return __copy_user(to, (__force void __user *) from, n);
8199- else
8200+ } else
8201 return n;
8202 }
8203
8204 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8205 {
8206+ if ((long)n < 0)
8207+ return n;
8208+
8209+ if (!__builtin_constant_p(n))
8210+ check_object_size(from, n, true);
8211+
8212 return __copy_user(to, (__force void __user *) from, n);
8213 }
8214
8215 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8216 {
8217- if (n && __access_ok((unsigned long) from, n))
8218+ if ((long)n < 0)
8219+ return n;
8220+
8221+ if (n && __access_ok((unsigned long) from, n)) {
8222+ if (!__builtin_constant_p(n))
8223+ check_object_size(to, n, false);
8224 return __copy_user((__force void __user *) to, from, n);
8225- else
8226+ } else
8227 return n;
8228 }
8229
8230 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8231 {
8232+ if ((long)n < 0)
8233+ return n;
8234+
8235 return __copy_user((__force void __user *) to, from, n);
8236 }
8237
8238diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8239index e562d3c..191f176 100644
8240--- a/arch/sparc/include/asm/uaccess_64.h
8241+++ b/arch/sparc/include/asm/uaccess_64.h
8242@@ -10,6 +10,7 @@
8243 #include <linux/compiler.h>
8244 #include <linux/string.h>
8245 #include <linux/thread_info.h>
8246+#include <linux/kernel.h>
8247 #include <asm/asi.h>
8248 #include <asm/spitfire.h>
8249 #include <asm-generic/uaccess-unaligned.h>
8250@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8251 static inline unsigned long __must_check
8252 copy_from_user(void *to, const void __user *from, unsigned long size)
8253 {
8254- unsigned long ret = ___copy_from_user(to, from, size);
8255+ unsigned long ret;
8256
8257+ if ((long)size < 0 || size > INT_MAX)
8258+ return size;
8259+
8260+ if (!__builtin_constant_p(size))
8261+ check_object_size(to, size, false);
8262+
8263+ ret = ___copy_from_user(to, from, size);
8264 if (unlikely(ret))
8265 ret = copy_from_user_fixup(to, from, size);
8266
8267@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8268 static inline unsigned long __must_check
8269 copy_to_user(void __user *to, const void *from, unsigned long size)
8270 {
8271- unsigned long ret = ___copy_to_user(to, from, size);
8272+ unsigned long ret;
8273
8274+ if ((long)size < 0 || size > INT_MAX)
8275+ return size;
8276+
8277+ if (!__builtin_constant_p(size))
8278+ check_object_size(from, size, true);
8279+
8280+ ret = ___copy_to_user(to, from, size);
8281 if (unlikely(ret))
8282 ret = copy_to_user_fixup(to, from, size);
8283 return ret;
8284diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8285index 6cf591b..b49e65a 100644
8286--- a/arch/sparc/kernel/Makefile
8287+++ b/arch/sparc/kernel/Makefile
8288@@ -3,7 +3,7 @@
8289 #
8290
8291 asflags-y := -ansi
8292-ccflags-y := -Werror
8293+#ccflags-y := -Werror
8294
8295 extra-y := head_$(BITS).o
8296
8297diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8298index be8e862..5b50b12 100644
8299--- a/arch/sparc/kernel/process_32.c
8300+++ b/arch/sparc/kernel/process_32.c
8301@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8302
8303 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8304 r->psr, r->pc, r->npc, r->y, print_tainted());
8305- printk("PC: <%pS>\n", (void *) r->pc);
8306+ printk("PC: <%pA>\n", (void *) r->pc);
8307 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8308 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8309 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8310 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8311 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8312 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8313- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8314+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8315
8316 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8317 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8318@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8319 rw = (struct reg_window32 *) fp;
8320 pc = rw->ins[7];
8321 printk("[%08lx : ", pc);
8322- printk("%pS ] ", (void *) pc);
8323+ printk("%pA ] ", (void *) pc);
8324 fp = rw->ins[6];
8325 } while (++count < 16);
8326 printk("\n");
8327diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8328index cdb80b2..5ca141d 100644
8329--- a/arch/sparc/kernel/process_64.c
8330+++ b/arch/sparc/kernel/process_64.c
8331@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8332 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8333 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8334 if (regs->tstate & TSTATE_PRIV)
8335- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8336+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8337 }
8338
8339 void show_regs(struct pt_regs *regs)
8340 {
8341 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8342 regs->tpc, regs->tnpc, regs->y, print_tainted());
8343- printk("TPC: <%pS>\n", (void *) regs->tpc);
8344+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8345 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8346 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8347 regs->u_regs[3]);
8348@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8349 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8350 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8351 regs->u_regs[15]);
8352- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8353+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8354 show_regwindow(regs);
8355 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8356 }
8357@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8358 ((tp && tp->task) ? tp->task->pid : -1));
8359
8360 if (gp->tstate & TSTATE_PRIV) {
8361- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8362+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8363 (void *) gp->tpc,
8364 (void *) gp->o7,
8365 (void *) gp->i7,
8366diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8367index 7ff45e4..a58f271 100644
8368--- a/arch/sparc/kernel/ptrace_64.c
8369+++ b/arch/sparc/kernel/ptrace_64.c
8370@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8371 return ret;
8372 }
8373
8374+#ifdef CONFIG_GRKERNSEC_SETXID
8375+extern void gr_delayed_cred_worker(void);
8376+#endif
8377+
8378 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8379 {
8380 int ret = 0;
8381@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8382 /* do the secure computing check first */
8383 secure_computing_strict(regs->u_regs[UREG_G1]);
8384
8385+#ifdef CONFIG_GRKERNSEC_SETXID
8386+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8387+ gr_delayed_cred_worker();
8388+#endif
8389+
8390 if (test_thread_flag(TIF_SYSCALL_TRACE))
8391 ret = tracehook_report_syscall_entry(regs);
8392
8393@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8394
8395 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8396 {
8397+#ifdef CONFIG_GRKERNSEC_SETXID
8398+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8399+ gr_delayed_cred_worker();
8400+#endif
8401+
8402 audit_syscall_exit(regs);
8403
8404 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8405diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8406index 2da0bdc..79128d2 100644
8407--- a/arch/sparc/kernel/sys_sparc_32.c
8408+++ b/arch/sparc/kernel/sys_sparc_32.c
8409@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8410 if (len > TASK_SIZE - PAGE_SIZE)
8411 return -ENOMEM;
8412 if (!addr)
8413- addr = TASK_UNMAPPED_BASE;
8414+ addr = current->mm->mmap_base;
8415
8416 info.flags = 0;
8417 info.length = len;
8418diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8419index 708bc29..f0129cb 100644
8420--- a/arch/sparc/kernel/sys_sparc_64.c
8421+++ b/arch/sparc/kernel/sys_sparc_64.c
8422@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8423 struct vm_area_struct * vma;
8424 unsigned long task_size = TASK_SIZE;
8425 int do_color_align;
8426+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8427 struct vm_unmapped_area_info info;
8428
8429 if (flags & MAP_FIXED) {
8430 /* We do not accept a shared mapping if it would violate
8431 * cache aliasing constraints.
8432 */
8433- if ((flags & MAP_SHARED) &&
8434+ if ((filp || (flags & MAP_SHARED)) &&
8435 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8436 return -EINVAL;
8437 return addr;
8438@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8439 if (filp || (flags & MAP_SHARED))
8440 do_color_align = 1;
8441
8442+#ifdef CONFIG_PAX_RANDMMAP
8443+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8444+#endif
8445+
8446 if (addr) {
8447 if (do_color_align)
8448 addr = COLOR_ALIGN(addr, pgoff);
8449@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8450 addr = PAGE_ALIGN(addr);
8451
8452 vma = find_vma(mm, addr);
8453- if (task_size - len >= addr &&
8454- (!vma || addr + len <= vma->vm_start))
8455+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8456 return addr;
8457 }
8458
8459 info.flags = 0;
8460 info.length = len;
8461- info.low_limit = TASK_UNMAPPED_BASE;
8462+ info.low_limit = mm->mmap_base;
8463 info.high_limit = min(task_size, VA_EXCLUDE_START);
8464 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8465 info.align_offset = pgoff << PAGE_SHIFT;
8466@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8467 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8468 VM_BUG_ON(addr != -ENOMEM);
8469 info.low_limit = VA_EXCLUDE_END;
8470+
8471+#ifdef CONFIG_PAX_RANDMMAP
8472+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8473+ info.low_limit += mm->delta_mmap;
8474+#endif
8475+
8476 info.high_limit = task_size;
8477 addr = vm_unmapped_area(&info);
8478 }
8479@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8480 unsigned long task_size = STACK_TOP32;
8481 unsigned long addr = addr0;
8482 int do_color_align;
8483+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8484 struct vm_unmapped_area_info info;
8485
8486 /* This should only ever run for 32-bit processes. */
8487@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8488 /* We do not accept a shared mapping if it would violate
8489 * cache aliasing constraints.
8490 */
8491- if ((flags & MAP_SHARED) &&
8492+ if ((filp || (flags & MAP_SHARED)) &&
8493 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8494 return -EINVAL;
8495 return addr;
8496@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8497 if (filp || (flags & MAP_SHARED))
8498 do_color_align = 1;
8499
8500+#ifdef CONFIG_PAX_RANDMMAP
8501+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8502+#endif
8503+
8504 /* requesting a specific address */
8505 if (addr) {
8506 if (do_color_align)
8507@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8508 addr = PAGE_ALIGN(addr);
8509
8510 vma = find_vma(mm, addr);
8511- if (task_size - len >= addr &&
8512- (!vma || addr + len <= vma->vm_start))
8513+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8514 return addr;
8515 }
8516
8517@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8518 VM_BUG_ON(addr != -ENOMEM);
8519 info.flags = 0;
8520 info.low_limit = TASK_UNMAPPED_BASE;
8521+
8522+#ifdef CONFIG_PAX_RANDMMAP
8523+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8524+ info.low_limit += mm->delta_mmap;
8525+#endif
8526+
8527 info.high_limit = STACK_TOP32;
8528 addr = vm_unmapped_area(&info);
8529 }
8530@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8531 {
8532 unsigned long rnd = 0UL;
8533
8534+#ifdef CONFIG_PAX_RANDMMAP
8535+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8536+#endif
8537+
8538 if (current->flags & PF_RANDOMIZE) {
8539 unsigned long val = get_random_int();
8540 if (test_thread_flag(TIF_32BIT))
8541@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8542 gap == RLIM_INFINITY ||
8543 sysctl_legacy_va_layout) {
8544 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8545+
8546+#ifdef CONFIG_PAX_RANDMMAP
8547+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8548+ mm->mmap_base += mm->delta_mmap;
8549+#endif
8550+
8551 mm->get_unmapped_area = arch_get_unmapped_area;
8552 mm->unmap_area = arch_unmap_area;
8553 } else {
8554@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8555 gap = (task_size / 6 * 5);
8556
8557 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8558+
8559+#ifdef CONFIG_PAX_RANDMMAP
8560+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8561+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8562+#endif
8563+
8564 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8565 mm->unmap_area = arch_unmap_area_topdown;
8566 }
8567diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8568index e0fed77..604a7e5 100644
8569--- a/arch/sparc/kernel/syscalls.S
8570+++ b/arch/sparc/kernel/syscalls.S
8571@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8572 #endif
8573 .align 32
8574 1: ldx [%g6 + TI_FLAGS], %l5
8575- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8576+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8577 be,pt %icc, rtrap
8578 nop
8579 call syscall_trace_leave
8580@@ -190,7 +190,7 @@ linux_sparc_syscall32:
8581
8582 srl %i5, 0, %o5 ! IEU1
8583 srl %i2, 0, %o2 ! IEU0 Group
8584- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8585+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8586 bne,pn %icc, linux_syscall_trace32 ! CTI
8587 mov %i0, %l5 ! IEU1
8588 call %l7 ! CTI Group brk forced
8589@@ -213,7 +213,7 @@ linux_sparc_syscall:
8590
8591 mov %i3, %o3 ! IEU1
8592 mov %i4, %o4 ! IEU0 Group
8593- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8594+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8595 bne,pn %icc, linux_syscall_trace ! CTI Group
8596 mov %i0, %l5 ! IEU0
8597 2: call %l7 ! CTI Group brk forced
8598@@ -229,7 +229,7 @@ ret_sys_call:
8599
8600 cmp %o0, -ERESTART_RESTARTBLOCK
8601 bgeu,pn %xcc, 1f
8602- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8603+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8604 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8605
8606 2:
8607diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8608index 654e8aa..45f431b 100644
8609--- a/arch/sparc/kernel/sysfs.c
8610+++ b/arch/sparc/kernel/sysfs.c
8611@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8612 return NOTIFY_OK;
8613 }
8614
8615-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8616+static struct notifier_block sysfs_cpu_nb = {
8617 .notifier_call = sysfs_cpu_notify,
8618 };
8619
8620diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8621index a5785ea..405c5f7 100644
8622--- a/arch/sparc/kernel/traps_32.c
8623+++ b/arch/sparc/kernel/traps_32.c
8624@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8625 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8626 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8627
8628+extern void gr_handle_kernel_exploit(void);
8629+
8630 void die_if_kernel(char *str, struct pt_regs *regs)
8631 {
8632 static int die_counter;
8633@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8634 count++ < 30 &&
8635 (((unsigned long) rw) >= PAGE_OFFSET) &&
8636 !(((unsigned long) rw) & 0x7)) {
8637- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8638+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8639 (void *) rw->ins[7]);
8640 rw = (struct reg_window32 *)rw->ins[6];
8641 }
8642 }
8643 printk("Instruction DUMP:");
8644 instruction_dump ((unsigned long *) regs->pc);
8645- if(regs->psr & PSR_PS)
8646+ if(regs->psr & PSR_PS) {
8647+ gr_handle_kernel_exploit();
8648 do_exit(SIGKILL);
8649+ }
8650 do_exit(SIGSEGV);
8651 }
8652
8653diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8654index e7ecf15..6520e65 100644
8655--- a/arch/sparc/kernel/traps_64.c
8656+++ b/arch/sparc/kernel/traps_64.c
8657@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8658 i + 1,
8659 p->trapstack[i].tstate, p->trapstack[i].tpc,
8660 p->trapstack[i].tnpc, p->trapstack[i].tt);
8661- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8662+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8663 }
8664 }
8665
8666@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8667
8668 lvl -= 0x100;
8669 if (regs->tstate & TSTATE_PRIV) {
8670+
8671+#ifdef CONFIG_PAX_REFCOUNT
8672+ if (lvl == 6)
8673+ pax_report_refcount_overflow(regs);
8674+#endif
8675+
8676 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8677 die_if_kernel(buffer, regs);
8678 }
8679@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8680 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8681 {
8682 char buffer[32];
8683-
8684+
8685 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8686 0, lvl, SIGTRAP) == NOTIFY_STOP)
8687 return;
8688
8689+#ifdef CONFIG_PAX_REFCOUNT
8690+ if (lvl == 6)
8691+ pax_report_refcount_overflow(regs);
8692+#endif
8693+
8694 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8695
8696 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8697@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8698 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8699 printk("%s" "ERROR(%d): ",
8700 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8701- printk("TPC<%pS>\n", (void *) regs->tpc);
8702+ printk("TPC<%pA>\n", (void *) regs->tpc);
8703 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8704 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8705 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8706@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8707 smp_processor_id(),
8708 (type & 0x1) ? 'I' : 'D',
8709 regs->tpc);
8710- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8711+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8712 panic("Irrecoverable Cheetah+ parity error.");
8713 }
8714
8715@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8716 smp_processor_id(),
8717 (type & 0x1) ? 'I' : 'D',
8718 regs->tpc);
8719- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8720+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8721 }
8722
8723 struct sun4v_error_entry {
8724@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8725
8726 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8727 regs->tpc, tl);
8728- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8729+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8730 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8731- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8732+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8733 (void *) regs->u_regs[UREG_I7]);
8734 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8735 "pte[%lx] error[%lx]\n",
8736@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8737
8738 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8739 regs->tpc, tl);
8740- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8741+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8742 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8743- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8744+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8745 (void *) regs->u_regs[UREG_I7]);
8746 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8747 "pte[%lx] error[%lx]\n",
8748@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8749 fp = (unsigned long)sf->fp + STACK_BIAS;
8750 }
8751
8752- printk(" [%016lx] %pS\n", pc, (void *) pc);
8753+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8754 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8755 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8756 int index = tsk->curr_ret_stack;
8757 if (tsk->ret_stack && index >= graph) {
8758 pc = tsk->ret_stack[index - graph].ret;
8759- printk(" [%016lx] %pS\n", pc, (void *) pc);
8760+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8761 graph++;
8762 }
8763 }
8764@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8765 return (struct reg_window *) (fp + STACK_BIAS);
8766 }
8767
8768+extern void gr_handle_kernel_exploit(void);
8769+
8770 void die_if_kernel(char *str, struct pt_regs *regs)
8771 {
8772 static int die_counter;
8773@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8774 while (rw &&
8775 count++ < 30 &&
8776 kstack_valid(tp, (unsigned long) rw)) {
8777- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8778+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8779 (void *) rw->ins[7]);
8780
8781 rw = kernel_stack_up(rw);
8782@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8783 }
8784 user_instruction_dump ((unsigned int __user *) regs->tpc);
8785 }
8786- if (regs->tstate & TSTATE_PRIV)
8787+ if (regs->tstate & TSTATE_PRIV) {
8788+ gr_handle_kernel_exploit();
8789 do_exit(SIGKILL);
8790+ }
8791 do_exit(SIGSEGV);
8792 }
8793 EXPORT_SYMBOL(die_if_kernel);
8794diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8795index 8201c25e..072a2a7 100644
8796--- a/arch/sparc/kernel/unaligned_64.c
8797+++ b/arch/sparc/kernel/unaligned_64.c
8798@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8799 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8800
8801 if (__ratelimit(&ratelimit)) {
8802- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8803+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8804 regs->tpc, (void *) regs->tpc);
8805 }
8806 }
8807diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8808index 8410065f2..4fd4ca22 100644
8809--- a/arch/sparc/lib/Makefile
8810+++ b/arch/sparc/lib/Makefile
8811@@ -2,7 +2,7 @@
8812 #
8813
8814 asflags-y := -ansi -DST_DIV0=0x02
8815-ccflags-y := -Werror
8816+#ccflags-y := -Werror
8817
8818 lib-$(CONFIG_SPARC32) += ashrdi3.o
8819 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8820diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8821index 85c233d..68500e0 100644
8822--- a/arch/sparc/lib/atomic_64.S
8823+++ b/arch/sparc/lib/atomic_64.S
8824@@ -17,7 +17,12 @@
8825 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8826 BACKOFF_SETUP(%o2)
8827 1: lduw [%o1], %g1
8828- add %g1, %o0, %g7
8829+ addcc %g1, %o0, %g7
8830+
8831+#ifdef CONFIG_PAX_REFCOUNT
8832+ tvs %icc, 6
8833+#endif
8834+
8835 cas [%o1], %g1, %g7
8836 cmp %g1, %g7
8837 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8838@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8839 2: BACKOFF_SPIN(%o2, %o3, 1b)
8840 ENDPROC(atomic_add)
8841
8842+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8843+ BACKOFF_SETUP(%o2)
8844+1: lduw [%o1], %g1
8845+ add %g1, %o0, %g7
8846+ cas [%o1], %g1, %g7
8847+ cmp %g1, %g7
8848+ bne,pn %icc, 2f
8849+ nop
8850+ retl
8851+ nop
8852+2: BACKOFF_SPIN(%o2, %o3, 1b)
8853+ENDPROC(atomic_add_unchecked)
8854+
8855 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8856 BACKOFF_SETUP(%o2)
8857 1: lduw [%o1], %g1
8858- sub %g1, %o0, %g7
8859+ subcc %g1, %o0, %g7
8860+
8861+#ifdef CONFIG_PAX_REFCOUNT
8862+ tvs %icc, 6
8863+#endif
8864+
8865 cas [%o1], %g1, %g7
8866 cmp %g1, %g7
8867 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8868@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8869 2: BACKOFF_SPIN(%o2, %o3, 1b)
8870 ENDPROC(atomic_sub)
8871
8872+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8873+ BACKOFF_SETUP(%o2)
8874+1: lduw [%o1], %g1
8875+ sub %g1, %o0, %g7
8876+ cas [%o1], %g1, %g7
8877+ cmp %g1, %g7
8878+ bne,pn %icc, 2f
8879+ nop
8880+ retl
8881+ nop
8882+2: BACKOFF_SPIN(%o2, %o3, 1b)
8883+ENDPROC(atomic_sub_unchecked)
8884+
8885 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8886 BACKOFF_SETUP(%o2)
8887 1: lduw [%o1], %g1
8888- add %g1, %o0, %g7
8889+ addcc %g1, %o0, %g7
8890+
8891+#ifdef CONFIG_PAX_REFCOUNT
8892+ tvs %icc, 6
8893+#endif
8894+
8895 cas [%o1], %g1, %g7
8896 cmp %g1, %g7
8897 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8898@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8899 2: BACKOFF_SPIN(%o2, %o3, 1b)
8900 ENDPROC(atomic_add_ret)
8901
8902+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8903+ BACKOFF_SETUP(%o2)
8904+1: lduw [%o1], %g1
8905+ addcc %g1, %o0, %g7
8906+ cas [%o1], %g1, %g7
8907+ cmp %g1, %g7
8908+ bne,pn %icc, 2f
8909+ add %g7, %o0, %g7
8910+ sra %g7, 0, %o0
8911+ retl
8912+ nop
8913+2: BACKOFF_SPIN(%o2, %o3, 1b)
8914+ENDPROC(atomic_add_ret_unchecked)
8915+
8916 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8917 BACKOFF_SETUP(%o2)
8918 1: lduw [%o1], %g1
8919- sub %g1, %o0, %g7
8920+ subcc %g1, %o0, %g7
8921+
8922+#ifdef CONFIG_PAX_REFCOUNT
8923+ tvs %icc, 6
8924+#endif
8925+
8926 cas [%o1], %g1, %g7
8927 cmp %g1, %g7
8928 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8929@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8930 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8931 BACKOFF_SETUP(%o2)
8932 1: ldx [%o1], %g1
8933- add %g1, %o0, %g7
8934+ addcc %g1, %o0, %g7
8935+
8936+#ifdef CONFIG_PAX_REFCOUNT
8937+ tvs %xcc, 6
8938+#endif
8939+
8940 casx [%o1], %g1, %g7
8941 cmp %g1, %g7
8942 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8943@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8944 2: BACKOFF_SPIN(%o2, %o3, 1b)
8945 ENDPROC(atomic64_add)
8946
8947+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8948+ BACKOFF_SETUP(%o2)
8949+1: ldx [%o1], %g1
8950+ addcc %g1, %o0, %g7
8951+ casx [%o1], %g1, %g7
8952+ cmp %g1, %g7
8953+ bne,pn %xcc, 2f
8954+ nop
8955+ retl
8956+ nop
8957+2: BACKOFF_SPIN(%o2, %o3, 1b)
8958+ENDPROC(atomic64_add_unchecked)
8959+
8960 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8961 BACKOFF_SETUP(%o2)
8962 1: ldx [%o1], %g1
8963- sub %g1, %o0, %g7
8964+ subcc %g1, %o0, %g7
8965+
8966+#ifdef CONFIG_PAX_REFCOUNT
8967+ tvs %xcc, 6
8968+#endif
8969+
8970 casx [%o1], %g1, %g7
8971 cmp %g1, %g7
8972 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8973@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8974 2: BACKOFF_SPIN(%o2, %o3, 1b)
8975 ENDPROC(atomic64_sub)
8976
8977+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8978+ BACKOFF_SETUP(%o2)
8979+1: ldx [%o1], %g1
8980+ subcc %g1, %o0, %g7
8981+ casx [%o1], %g1, %g7
8982+ cmp %g1, %g7
8983+ bne,pn %xcc, 2f
8984+ nop
8985+ retl
8986+ nop
8987+2: BACKOFF_SPIN(%o2, %o3, 1b)
8988+ENDPROC(atomic64_sub_unchecked)
8989+
8990 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8991 BACKOFF_SETUP(%o2)
8992 1: ldx [%o1], %g1
8993- add %g1, %o0, %g7
8994+ addcc %g1, %o0, %g7
8995+
8996+#ifdef CONFIG_PAX_REFCOUNT
8997+ tvs %xcc, 6
8998+#endif
8999+
9000 casx [%o1], %g1, %g7
9001 cmp %g1, %g7
9002 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9003@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9004 2: BACKOFF_SPIN(%o2, %o3, 1b)
9005 ENDPROC(atomic64_add_ret)
9006
9007+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9008+ BACKOFF_SETUP(%o2)
9009+1: ldx [%o1], %g1
9010+ addcc %g1, %o0, %g7
9011+ casx [%o1], %g1, %g7
9012+ cmp %g1, %g7
9013+ bne,pn %xcc, 2f
9014+ add %g7, %o0, %g7
9015+ mov %g7, %o0
9016+ retl
9017+ nop
9018+2: BACKOFF_SPIN(%o2, %o3, 1b)
9019+ENDPROC(atomic64_add_ret_unchecked)
9020+
9021 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9022 BACKOFF_SETUP(%o2)
9023 1: ldx [%o1], %g1
9024- sub %g1, %o0, %g7
9025+ subcc %g1, %o0, %g7
9026+
9027+#ifdef CONFIG_PAX_REFCOUNT
9028+ tvs %xcc, 6
9029+#endif
9030+
9031 casx [%o1], %g1, %g7
9032 cmp %g1, %g7
9033 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9034diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9035index 0c4e35e..745d3e4 100644
9036--- a/arch/sparc/lib/ksyms.c
9037+++ b/arch/sparc/lib/ksyms.c
9038@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9039
9040 /* Atomic counter implementation. */
9041 EXPORT_SYMBOL(atomic_add);
9042+EXPORT_SYMBOL(atomic_add_unchecked);
9043 EXPORT_SYMBOL(atomic_add_ret);
9044+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9045 EXPORT_SYMBOL(atomic_sub);
9046+EXPORT_SYMBOL(atomic_sub_unchecked);
9047 EXPORT_SYMBOL(atomic_sub_ret);
9048 EXPORT_SYMBOL(atomic64_add);
9049+EXPORT_SYMBOL(atomic64_add_unchecked);
9050 EXPORT_SYMBOL(atomic64_add_ret);
9051+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9052 EXPORT_SYMBOL(atomic64_sub);
9053+EXPORT_SYMBOL(atomic64_sub_unchecked);
9054 EXPORT_SYMBOL(atomic64_sub_ret);
9055 EXPORT_SYMBOL(atomic64_dec_if_positive);
9056
9057diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9058index 30c3ecc..736f015 100644
9059--- a/arch/sparc/mm/Makefile
9060+++ b/arch/sparc/mm/Makefile
9061@@ -2,7 +2,7 @@
9062 #
9063
9064 asflags-y := -ansi
9065-ccflags-y := -Werror
9066+#ccflags-y := -Werror
9067
9068 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9069 obj-y += fault_$(BITS).o
9070diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9071index e98bfda..ea8d221 100644
9072--- a/arch/sparc/mm/fault_32.c
9073+++ b/arch/sparc/mm/fault_32.c
9074@@ -21,6 +21,9 @@
9075 #include <linux/perf_event.h>
9076 #include <linux/interrupt.h>
9077 #include <linux/kdebug.h>
9078+#include <linux/slab.h>
9079+#include <linux/pagemap.h>
9080+#include <linux/compiler.h>
9081
9082 #include <asm/page.h>
9083 #include <asm/pgtable.h>
9084@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9085 return safe_compute_effective_address(regs, insn);
9086 }
9087
9088+#ifdef CONFIG_PAX_PAGEEXEC
9089+#ifdef CONFIG_PAX_DLRESOLVE
9090+static void pax_emuplt_close(struct vm_area_struct *vma)
9091+{
9092+ vma->vm_mm->call_dl_resolve = 0UL;
9093+}
9094+
9095+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9096+{
9097+ unsigned int *kaddr;
9098+
9099+ vmf->page = alloc_page(GFP_HIGHUSER);
9100+ if (!vmf->page)
9101+ return VM_FAULT_OOM;
9102+
9103+ kaddr = kmap(vmf->page);
9104+ memset(kaddr, 0, PAGE_SIZE);
9105+ kaddr[0] = 0x9DE3BFA8U; /* save */
9106+ flush_dcache_page(vmf->page);
9107+ kunmap(vmf->page);
9108+ return VM_FAULT_MAJOR;
9109+}
9110+
9111+static const struct vm_operations_struct pax_vm_ops = {
9112+ .close = pax_emuplt_close,
9113+ .fault = pax_emuplt_fault
9114+};
9115+
9116+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9117+{
9118+ int ret;
9119+
9120+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9121+ vma->vm_mm = current->mm;
9122+ vma->vm_start = addr;
9123+ vma->vm_end = addr + PAGE_SIZE;
9124+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9125+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9126+ vma->vm_ops = &pax_vm_ops;
9127+
9128+ ret = insert_vm_struct(current->mm, vma);
9129+ if (ret)
9130+ return ret;
9131+
9132+ ++current->mm->total_vm;
9133+ return 0;
9134+}
9135+#endif
9136+
9137+/*
9138+ * PaX: decide what to do with offenders (regs->pc = fault address)
9139+ *
9140+ * returns 1 when task should be killed
9141+ * 2 when patched PLT trampoline was detected
9142+ * 3 when unpatched PLT trampoline was detected
9143+ */
9144+static int pax_handle_fetch_fault(struct pt_regs *regs)
9145+{
9146+
9147+#ifdef CONFIG_PAX_EMUPLT
9148+ int err;
9149+
9150+ do { /* PaX: patched PLT emulation #1 */
9151+ unsigned int sethi1, sethi2, jmpl;
9152+
9153+ err = get_user(sethi1, (unsigned int *)regs->pc);
9154+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9155+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9156+
9157+ if (err)
9158+ break;
9159+
9160+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9161+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9162+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9163+ {
9164+ unsigned int addr;
9165+
9166+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9167+ addr = regs->u_regs[UREG_G1];
9168+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9169+ regs->pc = addr;
9170+ regs->npc = addr+4;
9171+ return 2;
9172+ }
9173+ } while (0);
9174+
9175+ do { /* PaX: patched PLT emulation #2 */
9176+ unsigned int ba;
9177+
9178+ err = get_user(ba, (unsigned int *)regs->pc);
9179+
9180+ if (err)
9181+ break;
9182+
9183+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9184+ unsigned int addr;
9185+
9186+ if ((ba & 0xFFC00000U) == 0x30800000U)
9187+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9188+ else
9189+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9190+ regs->pc = addr;
9191+ regs->npc = addr+4;
9192+ return 2;
9193+ }
9194+ } while (0);
9195+
9196+ do { /* PaX: patched PLT emulation #3 */
9197+ unsigned int sethi, bajmpl, nop;
9198+
9199+ err = get_user(sethi, (unsigned int *)regs->pc);
9200+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9201+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9202+
9203+ if (err)
9204+ break;
9205+
9206+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9207+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9208+ nop == 0x01000000U)
9209+ {
9210+ unsigned int addr;
9211+
9212+ addr = (sethi & 0x003FFFFFU) << 10;
9213+ regs->u_regs[UREG_G1] = addr;
9214+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9215+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9216+ else
9217+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9218+ regs->pc = addr;
9219+ regs->npc = addr+4;
9220+ return 2;
9221+ }
9222+ } while (0);
9223+
9224+ do { /* PaX: unpatched PLT emulation step 1 */
9225+ unsigned int sethi, ba, nop;
9226+
9227+ err = get_user(sethi, (unsigned int *)regs->pc);
9228+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9229+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9230+
9231+ if (err)
9232+ break;
9233+
9234+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9235+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9236+ nop == 0x01000000U)
9237+ {
9238+ unsigned int addr, save, call;
9239+
9240+ if ((ba & 0xFFC00000U) == 0x30800000U)
9241+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9242+ else
9243+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9244+
9245+ err = get_user(save, (unsigned int *)addr);
9246+ err |= get_user(call, (unsigned int *)(addr+4));
9247+ err |= get_user(nop, (unsigned int *)(addr+8));
9248+ if (err)
9249+ break;
9250+
9251+#ifdef CONFIG_PAX_DLRESOLVE
9252+ if (save == 0x9DE3BFA8U &&
9253+ (call & 0xC0000000U) == 0x40000000U &&
9254+ nop == 0x01000000U)
9255+ {
9256+ struct vm_area_struct *vma;
9257+ unsigned long call_dl_resolve;
9258+
9259+ down_read(&current->mm->mmap_sem);
9260+ call_dl_resolve = current->mm->call_dl_resolve;
9261+ up_read(&current->mm->mmap_sem);
9262+ if (likely(call_dl_resolve))
9263+ goto emulate;
9264+
9265+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9266+
9267+ down_write(&current->mm->mmap_sem);
9268+ if (current->mm->call_dl_resolve) {
9269+ call_dl_resolve = current->mm->call_dl_resolve;
9270+ up_write(&current->mm->mmap_sem);
9271+ if (vma)
9272+ kmem_cache_free(vm_area_cachep, vma);
9273+ goto emulate;
9274+ }
9275+
9276+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9277+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9278+ up_write(&current->mm->mmap_sem);
9279+ if (vma)
9280+ kmem_cache_free(vm_area_cachep, vma);
9281+ return 1;
9282+ }
9283+
9284+ if (pax_insert_vma(vma, call_dl_resolve)) {
9285+ up_write(&current->mm->mmap_sem);
9286+ kmem_cache_free(vm_area_cachep, vma);
9287+ return 1;
9288+ }
9289+
9290+ current->mm->call_dl_resolve = call_dl_resolve;
9291+ up_write(&current->mm->mmap_sem);
9292+
9293+emulate:
9294+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9295+ regs->pc = call_dl_resolve;
9296+ regs->npc = addr+4;
9297+ return 3;
9298+ }
9299+#endif
9300+
9301+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9302+ if ((save & 0xFFC00000U) == 0x05000000U &&
9303+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9304+ nop == 0x01000000U)
9305+ {
9306+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9307+ regs->u_regs[UREG_G2] = addr + 4;
9308+ addr = (save & 0x003FFFFFU) << 10;
9309+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9310+ regs->pc = addr;
9311+ regs->npc = addr+4;
9312+ return 3;
9313+ }
9314+ }
9315+ } while (0);
9316+
9317+ do { /* PaX: unpatched PLT emulation step 2 */
9318+ unsigned int save, call, nop;
9319+
9320+ err = get_user(save, (unsigned int *)(regs->pc-4));
9321+ err |= get_user(call, (unsigned int *)regs->pc);
9322+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9323+ if (err)
9324+ break;
9325+
9326+ if (save == 0x9DE3BFA8U &&
9327+ (call & 0xC0000000U) == 0x40000000U &&
9328+ nop == 0x01000000U)
9329+ {
9330+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9331+
9332+ regs->u_regs[UREG_RETPC] = regs->pc;
9333+ regs->pc = dl_resolve;
9334+ regs->npc = dl_resolve+4;
9335+ return 3;
9336+ }
9337+ } while (0);
9338+#endif
9339+
9340+ return 1;
9341+}
9342+
9343+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9344+{
9345+ unsigned long i;
9346+
9347+ printk(KERN_ERR "PAX: bytes at PC: ");
9348+ for (i = 0; i < 8; i++) {
9349+ unsigned int c;
9350+ if (get_user(c, (unsigned int *)pc+i))
9351+ printk(KERN_CONT "???????? ");
9352+ else
9353+ printk(KERN_CONT "%08x ", c);
9354+ }
9355+ printk("\n");
9356+}
9357+#endif
9358+
9359 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9360 int text_fault)
9361 {
9362@@ -230,6 +504,24 @@ good_area:
9363 if (!(vma->vm_flags & VM_WRITE))
9364 goto bad_area;
9365 } else {
9366+
9367+#ifdef CONFIG_PAX_PAGEEXEC
9368+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9369+ up_read(&mm->mmap_sem);
9370+ switch (pax_handle_fetch_fault(regs)) {
9371+
9372+#ifdef CONFIG_PAX_EMUPLT
9373+ case 2:
9374+ case 3:
9375+ return;
9376+#endif
9377+
9378+ }
9379+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9380+ do_group_exit(SIGKILL);
9381+ }
9382+#endif
9383+
9384 /* Allow reads even for write-only mappings */
9385 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9386 goto bad_area;
9387diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9388index 5062ff3..e0b75f3 100644
9389--- a/arch/sparc/mm/fault_64.c
9390+++ b/arch/sparc/mm/fault_64.c
9391@@ -21,6 +21,9 @@
9392 #include <linux/kprobes.h>
9393 #include <linux/kdebug.h>
9394 #include <linux/percpu.h>
9395+#include <linux/slab.h>
9396+#include <linux/pagemap.h>
9397+#include <linux/compiler.h>
9398
9399 #include <asm/page.h>
9400 #include <asm/pgtable.h>
9401@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9402 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9403 regs->tpc);
9404 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9405- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9406+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9407 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9408 dump_stack();
9409 unhandled_fault(regs->tpc, current, regs);
9410@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9411 show_regs(regs);
9412 }
9413
9414+#ifdef CONFIG_PAX_PAGEEXEC
9415+#ifdef CONFIG_PAX_DLRESOLVE
9416+static void pax_emuplt_close(struct vm_area_struct *vma)
9417+{
9418+ vma->vm_mm->call_dl_resolve = 0UL;
9419+}
9420+
9421+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9422+{
9423+ unsigned int *kaddr;
9424+
9425+ vmf->page = alloc_page(GFP_HIGHUSER);
9426+ if (!vmf->page)
9427+ return VM_FAULT_OOM;
9428+
9429+ kaddr = kmap(vmf->page);
9430+ memset(kaddr, 0, PAGE_SIZE);
9431+ kaddr[0] = 0x9DE3BFA8U; /* save */
9432+ flush_dcache_page(vmf->page);
9433+ kunmap(vmf->page);
9434+ return VM_FAULT_MAJOR;
9435+}
9436+
9437+static const struct vm_operations_struct pax_vm_ops = {
9438+ .close = pax_emuplt_close,
9439+ .fault = pax_emuplt_fault
9440+};
9441+
9442+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9443+{
9444+ int ret;
9445+
9446+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9447+ vma->vm_mm = current->mm;
9448+ vma->vm_start = addr;
9449+ vma->vm_end = addr + PAGE_SIZE;
9450+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9451+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9452+ vma->vm_ops = &pax_vm_ops;
9453+
9454+ ret = insert_vm_struct(current->mm, vma);
9455+ if (ret)
9456+ return ret;
9457+
9458+ ++current->mm->total_vm;
9459+ return 0;
9460+}
9461+#endif
9462+
9463+/*
9464+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9465+ *
9466+ * returns 1 when task should be killed
9467+ * 2 when patched PLT trampoline was detected
9468+ * 3 when unpatched PLT trampoline was detected
9469+ */
9470+static int pax_handle_fetch_fault(struct pt_regs *regs)
9471+{
9472+
9473+#ifdef CONFIG_PAX_EMUPLT
9474+ int err;
9475+
9476+ do { /* PaX: patched PLT emulation #1 */
9477+ unsigned int sethi1, sethi2, jmpl;
9478+
9479+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9480+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9481+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9482+
9483+ if (err)
9484+ break;
9485+
9486+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9487+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9488+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9489+ {
9490+ unsigned long addr;
9491+
9492+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9493+ addr = regs->u_regs[UREG_G1];
9494+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9495+
9496+ if (test_thread_flag(TIF_32BIT))
9497+ addr &= 0xFFFFFFFFUL;
9498+
9499+ regs->tpc = addr;
9500+ regs->tnpc = addr+4;
9501+ return 2;
9502+ }
9503+ } while (0);
9504+
9505+ do { /* PaX: patched PLT emulation #2 */
9506+ unsigned int ba;
9507+
9508+ err = get_user(ba, (unsigned int *)regs->tpc);
9509+
9510+ if (err)
9511+ break;
9512+
9513+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9514+ unsigned long addr;
9515+
9516+ if ((ba & 0xFFC00000U) == 0x30800000U)
9517+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9518+ else
9519+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9520+
9521+ if (test_thread_flag(TIF_32BIT))
9522+ addr &= 0xFFFFFFFFUL;
9523+
9524+ regs->tpc = addr;
9525+ regs->tnpc = addr+4;
9526+ return 2;
9527+ }
9528+ } while (0);
9529+
9530+ do { /* PaX: patched PLT emulation #3 */
9531+ unsigned int sethi, bajmpl, nop;
9532+
9533+ err = get_user(sethi, (unsigned int *)regs->tpc);
9534+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9535+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9536+
9537+ if (err)
9538+ break;
9539+
9540+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9541+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9542+ nop == 0x01000000U)
9543+ {
9544+ unsigned long addr;
9545+
9546+ addr = (sethi & 0x003FFFFFU) << 10;
9547+ regs->u_regs[UREG_G1] = addr;
9548+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9549+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9550+ else
9551+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9552+
9553+ if (test_thread_flag(TIF_32BIT))
9554+ addr &= 0xFFFFFFFFUL;
9555+
9556+ regs->tpc = addr;
9557+ regs->tnpc = addr+4;
9558+ return 2;
9559+ }
9560+ } while (0);
9561+
9562+ do { /* PaX: patched PLT emulation #4 */
9563+ unsigned int sethi, mov1, call, mov2;
9564+
9565+ err = get_user(sethi, (unsigned int *)regs->tpc);
9566+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9567+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9568+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9569+
9570+ if (err)
9571+ break;
9572+
9573+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9574+ mov1 == 0x8210000FU &&
9575+ (call & 0xC0000000U) == 0x40000000U &&
9576+ mov2 == 0x9E100001U)
9577+ {
9578+ unsigned long addr;
9579+
9580+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9581+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9582+
9583+ if (test_thread_flag(TIF_32BIT))
9584+ addr &= 0xFFFFFFFFUL;
9585+
9586+ regs->tpc = addr;
9587+ regs->tnpc = addr+4;
9588+ return 2;
9589+ }
9590+ } while (0);
9591+
9592+ do { /* PaX: patched PLT emulation #5 */
9593+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9594+
9595+ err = get_user(sethi, (unsigned int *)regs->tpc);
9596+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9597+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9598+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9599+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9600+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9601+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9602+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9603+
9604+ if (err)
9605+ break;
9606+
9607+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9608+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9609+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9610+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9611+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9612+ sllx == 0x83287020U &&
9613+ jmpl == 0x81C04005U &&
9614+ nop == 0x01000000U)
9615+ {
9616+ unsigned long addr;
9617+
9618+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9619+ regs->u_regs[UREG_G1] <<= 32;
9620+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9621+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9622+ regs->tpc = addr;
9623+ regs->tnpc = addr+4;
9624+ return 2;
9625+ }
9626+ } while (0);
9627+
9628+ do { /* PaX: patched PLT emulation #6 */
9629+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9630+
9631+ err = get_user(sethi, (unsigned int *)regs->tpc);
9632+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9633+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9634+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9635+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9636+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9637+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9638+
9639+ if (err)
9640+ break;
9641+
9642+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9643+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9644+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9645+ sllx == 0x83287020U &&
9646+ (or & 0xFFFFE000U) == 0x8A116000U &&
9647+ jmpl == 0x81C04005U &&
9648+ nop == 0x01000000U)
9649+ {
9650+ unsigned long addr;
9651+
9652+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9653+ regs->u_regs[UREG_G1] <<= 32;
9654+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9655+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9656+ regs->tpc = addr;
9657+ regs->tnpc = addr+4;
9658+ return 2;
9659+ }
9660+ } while (0);
9661+
9662+ do { /* PaX: unpatched PLT emulation step 1 */
9663+ unsigned int sethi, ba, nop;
9664+
9665+ err = get_user(sethi, (unsigned int *)regs->tpc);
9666+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9667+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9668+
9669+ if (err)
9670+ break;
9671+
9672+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9673+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9674+ nop == 0x01000000U)
9675+ {
9676+ unsigned long addr;
9677+ unsigned int save, call;
9678+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9679+
9680+ if ((ba & 0xFFC00000U) == 0x30800000U)
9681+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9682+ else
9683+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9684+
9685+ if (test_thread_flag(TIF_32BIT))
9686+ addr &= 0xFFFFFFFFUL;
9687+
9688+ err = get_user(save, (unsigned int *)addr);
9689+ err |= get_user(call, (unsigned int *)(addr+4));
9690+ err |= get_user(nop, (unsigned int *)(addr+8));
9691+ if (err)
9692+ break;
9693+
9694+#ifdef CONFIG_PAX_DLRESOLVE
9695+ if (save == 0x9DE3BFA8U &&
9696+ (call & 0xC0000000U) == 0x40000000U &&
9697+ nop == 0x01000000U)
9698+ {
9699+ struct vm_area_struct *vma;
9700+ unsigned long call_dl_resolve;
9701+
9702+ down_read(&current->mm->mmap_sem);
9703+ call_dl_resolve = current->mm->call_dl_resolve;
9704+ up_read(&current->mm->mmap_sem);
9705+ if (likely(call_dl_resolve))
9706+ goto emulate;
9707+
9708+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9709+
9710+ down_write(&current->mm->mmap_sem);
9711+ if (current->mm->call_dl_resolve) {
9712+ call_dl_resolve = current->mm->call_dl_resolve;
9713+ up_write(&current->mm->mmap_sem);
9714+ if (vma)
9715+ kmem_cache_free(vm_area_cachep, vma);
9716+ goto emulate;
9717+ }
9718+
9719+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9720+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9721+ up_write(&current->mm->mmap_sem);
9722+ if (vma)
9723+ kmem_cache_free(vm_area_cachep, vma);
9724+ return 1;
9725+ }
9726+
9727+ if (pax_insert_vma(vma, call_dl_resolve)) {
9728+ up_write(&current->mm->mmap_sem);
9729+ kmem_cache_free(vm_area_cachep, vma);
9730+ return 1;
9731+ }
9732+
9733+ current->mm->call_dl_resolve = call_dl_resolve;
9734+ up_write(&current->mm->mmap_sem);
9735+
9736+emulate:
9737+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9738+ regs->tpc = call_dl_resolve;
9739+ regs->tnpc = addr+4;
9740+ return 3;
9741+ }
9742+#endif
9743+
9744+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9745+ if ((save & 0xFFC00000U) == 0x05000000U &&
9746+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9747+ nop == 0x01000000U)
9748+ {
9749+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9750+ regs->u_regs[UREG_G2] = addr + 4;
9751+ addr = (save & 0x003FFFFFU) << 10;
9752+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9753+
9754+ if (test_thread_flag(TIF_32BIT))
9755+ addr &= 0xFFFFFFFFUL;
9756+
9757+ regs->tpc = addr;
9758+ regs->tnpc = addr+4;
9759+ return 3;
9760+ }
9761+
9762+ /* PaX: 64-bit PLT stub */
9763+ err = get_user(sethi1, (unsigned int *)addr);
9764+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9765+ err |= get_user(or1, (unsigned int *)(addr+8));
9766+ err |= get_user(or2, (unsigned int *)(addr+12));
9767+ err |= get_user(sllx, (unsigned int *)(addr+16));
9768+ err |= get_user(add, (unsigned int *)(addr+20));
9769+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9770+ err |= get_user(nop, (unsigned int *)(addr+28));
9771+ if (err)
9772+ break;
9773+
9774+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9775+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9776+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9777+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9778+ sllx == 0x89293020U &&
9779+ add == 0x8A010005U &&
9780+ jmpl == 0x89C14000U &&
9781+ nop == 0x01000000U)
9782+ {
9783+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9784+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9785+ regs->u_regs[UREG_G4] <<= 32;
9786+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9787+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9788+ regs->u_regs[UREG_G4] = addr + 24;
9789+ addr = regs->u_regs[UREG_G5];
9790+ regs->tpc = addr;
9791+ regs->tnpc = addr+4;
9792+ return 3;
9793+ }
9794+ }
9795+ } while (0);
9796+
9797+#ifdef CONFIG_PAX_DLRESOLVE
9798+ do { /* PaX: unpatched PLT emulation step 2 */
9799+ unsigned int save, call, nop;
9800+
9801+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9802+ err |= get_user(call, (unsigned int *)regs->tpc);
9803+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9804+ if (err)
9805+ break;
9806+
9807+ if (save == 0x9DE3BFA8U &&
9808+ (call & 0xC0000000U) == 0x40000000U &&
9809+ nop == 0x01000000U)
9810+ {
9811+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9812+
9813+ if (test_thread_flag(TIF_32BIT))
9814+ dl_resolve &= 0xFFFFFFFFUL;
9815+
9816+ regs->u_regs[UREG_RETPC] = regs->tpc;
9817+ regs->tpc = dl_resolve;
9818+ regs->tnpc = dl_resolve+4;
9819+ return 3;
9820+ }
9821+ } while (0);
9822+#endif
9823+
9824+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9825+ unsigned int sethi, ba, nop;
9826+
9827+ err = get_user(sethi, (unsigned int *)regs->tpc);
9828+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9829+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9830+
9831+ if (err)
9832+ break;
9833+
9834+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9835+ (ba & 0xFFF00000U) == 0x30600000U &&
9836+ nop == 0x01000000U)
9837+ {
9838+ unsigned long addr;
9839+
9840+ addr = (sethi & 0x003FFFFFU) << 10;
9841+ regs->u_regs[UREG_G1] = addr;
9842+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9843+
9844+ if (test_thread_flag(TIF_32BIT))
9845+ addr &= 0xFFFFFFFFUL;
9846+
9847+ regs->tpc = addr;
9848+ regs->tnpc = addr+4;
9849+ return 2;
9850+ }
9851+ } while (0);
9852+
9853+#endif
9854+
9855+ return 1;
9856+}
9857+
9858+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9859+{
9860+ unsigned long i;
9861+
9862+ printk(KERN_ERR "PAX: bytes at PC: ");
9863+ for (i = 0; i < 8; i++) {
9864+ unsigned int c;
9865+ if (get_user(c, (unsigned int *)pc+i))
9866+ printk(KERN_CONT "???????? ");
9867+ else
9868+ printk(KERN_CONT "%08x ", c);
9869+ }
9870+ printk("\n");
9871+}
9872+#endif
9873+
9874 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9875 {
9876 struct mm_struct *mm = current->mm;
9877@@ -341,6 +804,29 @@ retry:
9878 if (!vma)
9879 goto bad_area;
9880
9881+#ifdef CONFIG_PAX_PAGEEXEC
9882+ /* PaX: detect ITLB misses on non-exec pages */
9883+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9884+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9885+ {
9886+ if (address != regs->tpc)
9887+ goto good_area;
9888+
9889+ up_read(&mm->mmap_sem);
9890+ switch (pax_handle_fetch_fault(regs)) {
9891+
9892+#ifdef CONFIG_PAX_EMUPLT
9893+ case 2:
9894+ case 3:
9895+ return;
9896+#endif
9897+
9898+ }
9899+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9900+ do_group_exit(SIGKILL);
9901+ }
9902+#endif
9903+
9904 /* Pure DTLB misses do not tell us whether the fault causing
9905 * load/store/atomic was a write or not, it only says that there
9906 * was no match. So in such a case we (carefully) read the
9907diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9908index d2b5944..bd813f2 100644
9909--- a/arch/sparc/mm/hugetlbpage.c
9910+++ b/arch/sparc/mm/hugetlbpage.c
9911@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9912
9913 info.flags = 0;
9914 info.length = len;
9915- info.low_limit = TASK_UNMAPPED_BASE;
9916+ info.low_limit = mm->mmap_base;
9917 info.high_limit = min(task_size, VA_EXCLUDE_START);
9918 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9919 info.align_offset = 0;
9920@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9921 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9922 VM_BUG_ON(addr != -ENOMEM);
9923 info.low_limit = VA_EXCLUDE_END;
9924+
9925+#ifdef CONFIG_PAX_RANDMMAP
9926+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9927+ info.low_limit += mm->delta_mmap;
9928+#endif
9929+
9930 info.high_limit = task_size;
9931 addr = vm_unmapped_area(&info);
9932 }
9933@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9934 VM_BUG_ON(addr != -ENOMEM);
9935 info.flags = 0;
9936 info.low_limit = TASK_UNMAPPED_BASE;
9937+
9938+#ifdef CONFIG_PAX_RANDMMAP
9939+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9940+ info.low_limit += mm->delta_mmap;
9941+#endif
9942+
9943 info.high_limit = STACK_TOP32;
9944 addr = vm_unmapped_area(&info);
9945 }
9946@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9947 struct mm_struct *mm = current->mm;
9948 struct vm_area_struct *vma;
9949 unsigned long task_size = TASK_SIZE;
9950+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9951
9952 if (test_thread_flag(TIF_32BIT))
9953 task_size = STACK_TOP32;
9954@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9955 return addr;
9956 }
9957
9958+#ifdef CONFIG_PAX_RANDMMAP
9959+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9960+#endif
9961+
9962 if (addr) {
9963 addr = ALIGN(addr, HPAGE_SIZE);
9964 vma = find_vma(mm, addr);
9965- if (task_size - len >= addr &&
9966- (!vma || addr + len <= vma->vm_start))
9967+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9968 return addr;
9969 }
9970 if (mm->get_unmapped_area == arch_get_unmapped_area)
9971diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9972index f4500c6..889656c 100644
9973--- a/arch/tile/include/asm/atomic_64.h
9974+++ b/arch/tile/include/asm/atomic_64.h
9975@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9976
9977 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9978
9979+#define atomic64_read_unchecked(v) atomic64_read(v)
9980+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9981+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9982+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9983+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9984+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9985+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9986+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9987+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9988+
9989 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9990 #define smp_mb__before_atomic_dec() smp_mb()
9991 #define smp_mb__after_atomic_dec() smp_mb()
9992diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9993index a9a5299..0fce79e 100644
9994--- a/arch/tile/include/asm/cache.h
9995+++ b/arch/tile/include/asm/cache.h
9996@@ -15,11 +15,12 @@
9997 #ifndef _ASM_TILE_CACHE_H
9998 #define _ASM_TILE_CACHE_H
9999
10000+#include <linux/const.h>
10001 #include <arch/chip.h>
10002
10003 /* bytes per L1 data cache line */
10004 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10005-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10006+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10007
10008 /* bytes per L2 cache line */
10009 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10010diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10011index 9ab078a..d6635c2 100644
10012--- a/arch/tile/include/asm/uaccess.h
10013+++ b/arch/tile/include/asm/uaccess.h
10014@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10015 const void __user *from,
10016 unsigned long n)
10017 {
10018- int sz = __compiletime_object_size(to);
10019+ size_t sz = __compiletime_object_size(to);
10020
10021- if (likely(sz == -1 || sz >= n))
10022+ if (likely(sz == (size_t)-1 || sz >= n))
10023 n = _copy_from_user(to, from, n);
10024 else
10025 copy_from_user_overflow();
10026diff --git a/arch/um/Makefile b/arch/um/Makefile
10027index 133f7de..1d6f2f1 100644
10028--- a/arch/um/Makefile
10029+++ b/arch/um/Makefile
10030@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10031 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10032 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10033
10034+ifdef CONSTIFY_PLUGIN
10035+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10036+endif
10037+
10038 #This will adjust *FLAGS accordingly to the platform.
10039 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10040
10041diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10042index 19e1bdd..3665b77 100644
10043--- a/arch/um/include/asm/cache.h
10044+++ b/arch/um/include/asm/cache.h
10045@@ -1,6 +1,7 @@
10046 #ifndef __UM_CACHE_H
10047 #define __UM_CACHE_H
10048
10049+#include <linux/const.h>
10050
10051 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10052 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10053@@ -12,6 +13,6 @@
10054 # define L1_CACHE_SHIFT 5
10055 #endif
10056
10057-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10058+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10059
10060 #endif
10061diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10062index 2e0a6b1..a64d0f5 100644
10063--- a/arch/um/include/asm/kmap_types.h
10064+++ b/arch/um/include/asm/kmap_types.h
10065@@ -8,6 +8,6 @@
10066
10067 /* No more #include "asm/arch/kmap_types.h" ! */
10068
10069-#define KM_TYPE_NR 14
10070+#define KM_TYPE_NR 15
10071
10072 #endif
10073diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10074index 5ff53d9..5850cdf 100644
10075--- a/arch/um/include/asm/page.h
10076+++ b/arch/um/include/asm/page.h
10077@@ -14,6 +14,9 @@
10078 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10079 #define PAGE_MASK (~(PAGE_SIZE-1))
10080
10081+#define ktla_ktva(addr) (addr)
10082+#define ktva_ktla(addr) (addr)
10083+
10084 #ifndef __ASSEMBLY__
10085
10086 struct page;
10087diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10088index 0032f92..cd151e0 100644
10089--- a/arch/um/include/asm/pgtable-3level.h
10090+++ b/arch/um/include/asm/pgtable-3level.h
10091@@ -58,6 +58,7 @@
10092 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10093 #define pud_populate(mm, pud, pmd) \
10094 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10095+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10096
10097 #ifdef CONFIG_64BIT
10098 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10099diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10100index b462b13..e7a19aa 100644
10101--- a/arch/um/kernel/process.c
10102+++ b/arch/um/kernel/process.c
10103@@ -386,22 +386,6 @@ int singlestepping(void * t)
10104 return 2;
10105 }
10106
10107-/*
10108- * Only x86 and x86_64 have an arch_align_stack().
10109- * All other arches have "#define arch_align_stack(x) (x)"
10110- * in their asm/system.h
10111- * As this is included in UML from asm-um/system-generic.h,
10112- * we can use it to behave as the subarch does.
10113- */
10114-#ifndef arch_align_stack
10115-unsigned long arch_align_stack(unsigned long sp)
10116-{
10117- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10118- sp -= get_random_int() % 8192;
10119- return sp & ~0xf;
10120-}
10121-#endif
10122-
10123 unsigned long get_wchan(struct task_struct *p)
10124 {
10125 unsigned long stack_page, sp, ip;
10126diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10127index ad8f795..2c7eec6 100644
10128--- a/arch/unicore32/include/asm/cache.h
10129+++ b/arch/unicore32/include/asm/cache.h
10130@@ -12,8 +12,10 @@
10131 #ifndef __UNICORE_CACHE_H__
10132 #define __UNICORE_CACHE_H__
10133
10134-#define L1_CACHE_SHIFT (5)
10135-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10136+#include <linux/const.h>
10137+
10138+#define L1_CACHE_SHIFT 5
10139+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10140
10141 /*
10142 * Memory returned by kmalloc() may be used for DMA, so we must make
10143diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10144index 0694d09..b58b3aa 100644
10145--- a/arch/x86/Kconfig
10146+++ b/arch/x86/Kconfig
10147@@ -238,7 +238,7 @@ config X86_HT
10148
10149 config X86_32_LAZY_GS
10150 def_bool y
10151- depends on X86_32 && !CC_STACKPROTECTOR
10152+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10153
10154 config ARCH_HWEIGHT_CFLAGS
10155 string
10156@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
10157
10158 config X86_MSR
10159 tristate "/dev/cpu/*/msr - Model-specific register support"
10160+ depends on !GRKERNSEC_KMEM
10161 ---help---
10162 This device gives privileged processes access to the x86
10163 Model-Specific Registers (MSRs). It is a character device with
10164@@ -1054,7 +1055,7 @@ choice
10165
10166 config NOHIGHMEM
10167 bool "off"
10168- depends on !X86_NUMAQ
10169+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10170 ---help---
10171 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10172 However, the address space of 32-bit x86 processors is only 4
10173@@ -1091,7 +1092,7 @@ config NOHIGHMEM
10174
10175 config HIGHMEM4G
10176 bool "4GB"
10177- depends on !X86_NUMAQ
10178+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10179 ---help---
10180 Select this if you have a 32-bit processor and between 1 and 4
10181 gigabytes of physical RAM.
10182@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
10183 hex
10184 default 0xB0000000 if VMSPLIT_3G_OPT
10185 default 0x80000000 if VMSPLIT_2G
10186- default 0x78000000 if VMSPLIT_2G_OPT
10187+ default 0x70000000 if VMSPLIT_2G_OPT
10188 default 0x40000000 if VMSPLIT_1G
10189 default 0xC0000000
10190 depends on X86_32
10191@@ -1542,6 +1543,7 @@ config SECCOMP
10192
10193 config CC_STACKPROTECTOR
10194 bool "Enable -fstack-protector buffer overflow detection"
10195+ depends on X86_64 || !PAX_MEMORY_UDEREF
10196 ---help---
10197 This option turns on the -fstack-protector GCC feature. This
10198 feature puts, at the beginning of functions, a canary value on
10199@@ -1599,6 +1601,7 @@ config KEXEC_JUMP
10200 config PHYSICAL_START
10201 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
10202 default "0x1000000"
10203+ range 0x400000 0x40000000
10204 ---help---
10205 This gives the physical address where the kernel is loaded.
10206
10207@@ -1662,6 +1665,7 @@ config X86_NEED_RELOCS
10208 config PHYSICAL_ALIGN
10209 hex "Alignment value to which kernel should be aligned" if X86_32
10210 default "0x1000000"
10211+ range 0x400000 0x1000000 if PAX_KERNEXEC
10212 range 0x2000 0x1000000
10213 ---help---
10214 This value puts the alignment restrictions on physical address
10215@@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
10216 If unsure, say N.
10217
10218 config COMPAT_VDSO
10219- def_bool y
10220+ def_bool n
10221 prompt "Compat VDSO support"
10222 depends on X86_32 || IA32_EMULATION
10223+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10224 ---help---
10225 Map the 32-bit VDSO to the predictable old-style address too.
10226
10227diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10228index c026cca..14657ae 100644
10229--- a/arch/x86/Kconfig.cpu
10230+++ b/arch/x86/Kconfig.cpu
10231@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10232
10233 config X86_F00F_BUG
10234 def_bool y
10235- depends on M586MMX || M586TSC || M586 || M486
10236+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10237
10238 config X86_INVD_BUG
10239 def_bool y
10240@@ -327,7 +327,7 @@ config X86_INVD_BUG
10241
10242 config X86_ALIGNMENT_16
10243 def_bool y
10244- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10245+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10246
10247 config X86_INTEL_USERCOPY
10248 def_bool y
10249@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10250 # generates cmov.
10251 config X86_CMOV
10252 def_bool y
10253- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10254+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10255
10256 config X86_MINIMUM_CPU_FAMILY
10257 int
10258diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10259index b322f12..652d0d9 100644
10260--- a/arch/x86/Kconfig.debug
10261+++ b/arch/x86/Kconfig.debug
10262@@ -84,7 +84,7 @@ config X86_PTDUMP
10263 config DEBUG_RODATA
10264 bool "Write protect kernel read-only data structures"
10265 default y
10266- depends on DEBUG_KERNEL
10267+ depends on DEBUG_KERNEL && BROKEN
10268 ---help---
10269 Mark the kernel read-only data as write-protected in the pagetables,
10270 in order to catch accidental (and incorrect) writes to such const
10271@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10272
10273 config DEBUG_SET_MODULE_RONX
10274 bool "Set loadable kernel module data as NX and text as RO"
10275- depends on MODULES
10276+ depends on MODULES && BROKEN
10277 ---help---
10278 This option helps catch unintended modifications to loadable
10279 kernel module's text and read-only data. It also prevents execution
10280@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10281
10282 config DEBUG_STRICT_USER_COPY_CHECKS
10283 bool "Strict copy size checks"
10284- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10285+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10286 ---help---
10287 Enabling this option turns a certain set of sanity checks for user
10288 copy operations into compile time failures.
10289diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10290index e71fc42..7829607 100644
10291--- a/arch/x86/Makefile
10292+++ b/arch/x86/Makefile
10293@@ -50,6 +50,7 @@ else
10294 UTS_MACHINE := x86_64
10295 CHECKFLAGS += -D__x86_64__ -m64
10296
10297+ biarch := $(call cc-option,-m64)
10298 KBUILD_AFLAGS += -m64
10299 KBUILD_CFLAGS += -m64
10300
10301@@ -230,3 +231,12 @@ define archhelp
10302 echo ' FDARGS="..." arguments for the booted kernel'
10303 echo ' FDINITRD=file initrd for the booted kernel'
10304 endef
10305+
10306+define OLD_LD
10307+
10308+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10309+*** Please upgrade your binutils to 2.18 or newer
10310+endef
10311+
10312+archprepare:
10313+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10314diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10315index 379814b..add62ce 100644
10316--- a/arch/x86/boot/Makefile
10317+++ b/arch/x86/boot/Makefile
10318@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10319 $(call cc-option, -fno-stack-protector) \
10320 $(call cc-option, -mpreferred-stack-boundary=2)
10321 KBUILD_CFLAGS += $(call cc-option, -m32)
10322+ifdef CONSTIFY_PLUGIN
10323+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10324+endif
10325 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10326 GCOV_PROFILE := n
10327
10328diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10329index 878e4b9..20537ab 100644
10330--- a/arch/x86/boot/bitops.h
10331+++ b/arch/x86/boot/bitops.h
10332@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10333 u8 v;
10334 const u32 *p = (const u32 *)addr;
10335
10336- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10337+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10338 return v;
10339 }
10340
10341@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10342
10343 static inline void set_bit(int nr, void *addr)
10344 {
10345- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10346+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10347 }
10348
10349 #endif /* BOOT_BITOPS_H */
10350diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10351index 18997e5..83d9c67 100644
10352--- a/arch/x86/boot/boot.h
10353+++ b/arch/x86/boot/boot.h
10354@@ -85,7 +85,7 @@ static inline void io_delay(void)
10355 static inline u16 ds(void)
10356 {
10357 u16 seg;
10358- asm("movw %%ds,%0" : "=rm" (seg));
10359+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10360 return seg;
10361 }
10362
10363@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10364 static inline int memcmp(const void *s1, const void *s2, size_t len)
10365 {
10366 u8 diff;
10367- asm("repe; cmpsb; setnz %0"
10368+ asm volatile("repe; cmpsb; setnz %0"
10369 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10370 return diff;
10371 }
10372diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10373index 8a84501..b2d165f 100644
10374--- a/arch/x86/boot/compressed/Makefile
10375+++ b/arch/x86/boot/compressed/Makefile
10376@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10377 KBUILD_CFLAGS += $(cflags-y)
10378 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10379 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10380+ifdef CONSTIFY_PLUGIN
10381+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10382+endif
10383
10384 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10385 GCOV_PROFILE := n
10386diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10387index c205035..5853587 100644
10388--- a/arch/x86/boot/compressed/eboot.c
10389+++ b/arch/x86/boot/compressed/eboot.c
10390@@ -150,7 +150,6 @@ again:
10391 *addr = max_addr;
10392 }
10393
10394-free_pool:
10395 efi_call_phys1(sys_table->boottime->free_pool, map);
10396
10397 fail:
10398@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10399 if (i == map_size / desc_size)
10400 status = EFI_NOT_FOUND;
10401
10402-free_pool:
10403 efi_call_phys1(sys_table->boottime->free_pool, map);
10404 fail:
10405 return status;
10406diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10407index 1e3184f..0d11e2e 100644
10408--- a/arch/x86/boot/compressed/head_32.S
10409+++ b/arch/x86/boot/compressed/head_32.S
10410@@ -118,7 +118,7 @@ preferred_addr:
10411 notl %eax
10412 andl %eax, %ebx
10413 #else
10414- movl $LOAD_PHYSICAL_ADDR, %ebx
10415+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10416 #endif
10417
10418 /* Target address to relocate to for decompression */
10419@@ -204,7 +204,7 @@ relocated:
10420 * and where it was actually loaded.
10421 */
10422 movl %ebp, %ebx
10423- subl $LOAD_PHYSICAL_ADDR, %ebx
10424+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10425 jz 2f /* Nothing to be done if loaded at compiled addr. */
10426 /*
10427 * Process relocations.
10428@@ -212,8 +212,7 @@ relocated:
10429
10430 1: subl $4, %edi
10431 movl (%edi), %ecx
10432- testl %ecx, %ecx
10433- jz 2f
10434+ jecxz 2f
10435 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10436 jmp 1b
10437 2:
10438diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10439index f5d1aaa..cce11dc 100644
10440--- a/arch/x86/boot/compressed/head_64.S
10441+++ b/arch/x86/boot/compressed/head_64.S
10442@@ -91,7 +91,7 @@ ENTRY(startup_32)
10443 notl %eax
10444 andl %eax, %ebx
10445 #else
10446- movl $LOAD_PHYSICAL_ADDR, %ebx
10447+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10448 #endif
10449
10450 /* Target address to relocate to for decompression */
10451@@ -273,7 +273,7 @@ preferred_addr:
10452 notq %rax
10453 andq %rax, %rbp
10454 #else
10455- movq $LOAD_PHYSICAL_ADDR, %rbp
10456+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10457 #endif
10458
10459 /* Target address to relocate to for decompression */
10460diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10461index 88f7ff6..ed695dd 100644
10462--- a/arch/x86/boot/compressed/misc.c
10463+++ b/arch/x86/boot/compressed/misc.c
10464@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10465 case PT_LOAD:
10466 #ifdef CONFIG_RELOCATABLE
10467 dest = output;
10468- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10469+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10470 #else
10471 dest = (void *)(phdr->p_paddr);
10472 #endif
10473@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10474 error("Destination address too large");
10475 #endif
10476 #ifndef CONFIG_RELOCATABLE
10477- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10478+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10479 error("Wrong destination address");
10480 #endif
10481
10482diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10483index 4d3ff03..e4972ff 100644
10484--- a/arch/x86/boot/cpucheck.c
10485+++ b/arch/x86/boot/cpucheck.c
10486@@ -74,7 +74,7 @@ static int has_fpu(void)
10487 u16 fcw = -1, fsw = -1;
10488 u32 cr0;
10489
10490- asm("movl %%cr0,%0" : "=r" (cr0));
10491+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10492 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10493 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10494 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10495@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10496 {
10497 u32 f0, f1;
10498
10499- asm("pushfl ; "
10500+ asm volatile("pushfl ; "
10501 "pushfl ; "
10502 "popl %0 ; "
10503 "movl %0,%1 ; "
10504@@ -115,7 +115,7 @@ static void get_flags(void)
10505 set_bit(X86_FEATURE_FPU, cpu.flags);
10506
10507 if (has_eflag(X86_EFLAGS_ID)) {
10508- asm("cpuid"
10509+ asm volatile("cpuid"
10510 : "=a" (max_intel_level),
10511 "=b" (cpu_vendor[0]),
10512 "=d" (cpu_vendor[1]),
10513@@ -124,7 +124,7 @@ static void get_flags(void)
10514
10515 if (max_intel_level >= 0x00000001 &&
10516 max_intel_level <= 0x0000ffff) {
10517- asm("cpuid"
10518+ asm volatile("cpuid"
10519 : "=a" (tfms),
10520 "=c" (cpu.flags[4]),
10521 "=d" (cpu.flags[0])
10522@@ -136,7 +136,7 @@ static void get_flags(void)
10523 cpu.model += ((tfms >> 16) & 0xf) << 4;
10524 }
10525
10526- asm("cpuid"
10527+ asm volatile("cpuid"
10528 : "=a" (max_amd_level)
10529 : "a" (0x80000000)
10530 : "ebx", "ecx", "edx");
10531@@ -144,7 +144,7 @@ static void get_flags(void)
10532 if (max_amd_level >= 0x80000001 &&
10533 max_amd_level <= 0x8000ffff) {
10534 u32 eax = 0x80000001;
10535- asm("cpuid"
10536+ asm volatile("cpuid"
10537 : "+a" (eax),
10538 "=c" (cpu.flags[6]),
10539 "=d" (cpu.flags[1])
10540@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10541 u32 ecx = MSR_K7_HWCR;
10542 u32 eax, edx;
10543
10544- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10545+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10546 eax &= ~(1 << 15);
10547- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10548+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10549
10550 get_flags(); /* Make sure it really did something */
10551 err = check_flags();
10552@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10553 u32 ecx = MSR_VIA_FCR;
10554 u32 eax, edx;
10555
10556- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10557+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10558 eax |= (1<<1)|(1<<7);
10559- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10560+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10561
10562 set_bit(X86_FEATURE_CX8, cpu.flags);
10563 err = check_flags();
10564@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10565 u32 eax, edx;
10566 u32 level = 1;
10567
10568- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10569- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10570- asm("cpuid"
10571+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10572+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10573+ asm volatile("cpuid"
10574 : "+a" (level), "=d" (cpu.flags[0])
10575 : : "ecx", "ebx");
10576- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10577+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10578
10579 err = check_flags();
10580 }
10581diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10582index 944ce59..87ee37a 100644
10583--- a/arch/x86/boot/header.S
10584+++ b/arch/x86/boot/header.S
10585@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10586 # single linked list of
10587 # struct setup_data
10588
10589-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10590+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10591
10592 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10593+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10594+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10595+#else
10596 #define VO_INIT_SIZE (VO__end - VO__text)
10597+#endif
10598 #if ZO_INIT_SIZE > VO_INIT_SIZE
10599 #define INIT_SIZE ZO_INIT_SIZE
10600 #else
10601diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10602index db75d07..8e6d0af 100644
10603--- a/arch/x86/boot/memory.c
10604+++ b/arch/x86/boot/memory.c
10605@@ -19,7 +19,7 @@
10606
10607 static int detect_memory_e820(void)
10608 {
10609- int count = 0;
10610+ unsigned int count = 0;
10611 struct biosregs ireg, oreg;
10612 struct e820entry *desc = boot_params.e820_map;
10613 static struct e820entry buf; /* static so it is zeroed */
10614diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10615index 11e8c6e..fdbb1ed 100644
10616--- a/arch/x86/boot/video-vesa.c
10617+++ b/arch/x86/boot/video-vesa.c
10618@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10619
10620 boot_params.screen_info.vesapm_seg = oreg.es;
10621 boot_params.screen_info.vesapm_off = oreg.di;
10622+ boot_params.screen_info.vesapm_size = oreg.cx;
10623 }
10624
10625 /*
10626diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10627index 43eda28..5ab5fdb 100644
10628--- a/arch/x86/boot/video.c
10629+++ b/arch/x86/boot/video.c
10630@@ -96,7 +96,7 @@ static void store_mode_params(void)
10631 static unsigned int get_entry(void)
10632 {
10633 char entry_buf[4];
10634- int i, len = 0;
10635+ unsigned int i, len = 0;
10636 int key;
10637 unsigned int v;
10638
10639diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10640index 5b577d5..3c1fed4 100644
10641--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10642+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10643@@ -8,6 +8,8 @@
10644 * including this sentence is retained in full.
10645 */
10646
10647+#include <asm/alternative-asm.h>
10648+
10649 .extern crypto_ft_tab
10650 .extern crypto_it_tab
10651 .extern crypto_fl_tab
10652@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10653 je B192; \
10654 leaq 32(r9),r9;
10655
10656+#define ret pax_force_retaddr 0, 1; ret
10657+
10658 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10659 movq r1,r2; \
10660 movq r3,r4; \
10661diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10662index 3470624..201259d 100644
10663--- a/arch/x86/crypto/aesni-intel_asm.S
10664+++ b/arch/x86/crypto/aesni-intel_asm.S
10665@@ -31,6 +31,7 @@
10666
10667 #include <linux/linkage.h>
10668 #include <asm/inst.h>
10669+#include <asm/alternative-asm.h>
10670
10671 #ifdef __x86_64__
10672 .data
10673@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10674 pop %r14
10675 pop %r13
10676 pop %r12
10677+ pax_force_retaddr 0, 1
10678 ret
10679+ENDPROC(aesni_gcm_dec)
10680
10681
10682 /*****************************************************************************
10683@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10684 pop %r14
10685 pop %r13
10686 pop %r12
10687+ pax_force_retaddr 0, 1
10688 ret
10689+ENDPROC(aesni_gcm_enc)
10690
10691 #endif
10692
10693@@ -1714,6 +1719,7 @@ _key_expansion_256a:
10694 pxor %xmm1, %xmm0
10695 movaps %xmm0, (TKEYP)
10696 add $0x10, TKEYP
10697+ pax_force_retaddr_bts
10698 ret
10699
10700 .align 4
10701@@ -1738,6 +1744,7 @@ _key_expansion_192a:
10702 shufps $0b01001110, %xmm2, %xmm1
10703 movaps %xmm1, 0x10(TKEYP)
10704 add $0x20, TKEYP
10705+ pax_force_retaddr_bts
10706 ret
10707
10708 .align 4
10709@@ -1757,6 +1764,7 @@ _key_expansion_192b:
10710
10711 movaps %xmm0, (TKEYP)
10712 add $0x10, TKEYP
10713+ pax_force_retaddr_bts
10714 ret
10715
10716 .align 4
10717@@ -1769,6 +1777,7 @@ _key_expansion_256b:
10718 pxor %xmm1, %xmm2
10719 movaps %xmm2, (TKEYP)
10720 add $0x10, TKEYP
10721+ pax_force_retaddr_bts
10722 ret
10723
10724 /*
10725@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10726 #ifndef __x86_64__
10727 popl KEYP
10728 #endif
10729+ pax_force_retaddr 0, 1
10730 ret
10731+ENDPROC(aesni_set_key)
10732
10733 /*
10734 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10735@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10736 popl KLEN
10737 popl KEYP
10738 #endif
10739+ pax_force_retaddr 0, 1
10740 ret
10741+ENDPROC(aesni_enc)
10742
10743 /*
10744 * _aesni_enc1: internal ABI
10745@@ -1959,6 +1972,7 @@ _aesni_enc1:
10746 AESENC KEY STATE
10747 movaps 0x70(TKEYP), KEY
10748 AESENCLAST KEY STATE
10749+ pax_force_retaddr_bts
10750 ret
10751
10752 /*
10753@@ -2067,6 +2081,7 @@ _aesni_enc4:
10754 AESENCLAST KEY STATE2
10755 AESENCLAST KEY STATE3
10756 AESENCLAST KEY STATE4
10757+ pax_force_retaddr_bts
10758 ret
10759
10760 /*
10761@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10762 popl KLEN
10763 popl KEYP
10764 #endif
10765+ pax_force_retaddr 0, 1
10766 ret
10767+ENDPROC(aesni_dec)
10768
10769 /*
10770 * _aesni_dec1: internal ABI
10771@@ -2146,6 +2163,7 @@ _aesni_dec1:
10772 AESDEC KEY STATE
10773 movaps 0x70(TKEYP), KEY
10774 AESDECLAST KEY STATE
10775+ pax_force_retaddr_bts
10776 ret
10777
10778 /*
10779@@ -2254,6 +2272,7 @@ _aesni_dec4:
10780 AESDECLAST KEY STATE2
10781 AESDECLAST KEY STATE3
10782 AESDECLAST KEY STATE4
10783+ pax_force_retaddr_bts
10784 ret
10785
10786 /*
10787@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10788 popl KEYP
10789 popl LEN
10790 #endif
10791+ pax_force_retaddr 0, 1
10792 ret
10793+ENDPROC(aesni_ecb_enc)
10794
10795 /*
10796 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10797@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10798 popl KEYP
10799 popl LEN
10800 #endif
10801+ pax_force_retaddr 0, 1
10802 ret
10803+ENDPROC(aesni_ecb_dec)
10804
10805 /*
10806 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10807@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10808 popl LEN
10809 popl IVP
10810 #endif
10811+ pax_force_retaddr 0, 1
10812 ret
10813+ENDPROC(aesni_cbc_enc)
10814
10815 /*
10816 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10817@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10818 popl LEN
10819 popl IVP
10820 #endif
10821+ pax_force_retaddr 0, 1
10822 ret
10823+ENDPROC(aesni_cbc_dec)
10824
10825 #ifdef __x86_64__
10826 .align 16
10827@@ -2526,6 +2553,7 @@ _aesni_inc_init:
10828 mov $1, TCTR_LOW
10829 MOVQ_R64_XMM TCTR_LOW INC
10830 MOVQ_R64_XMM CTR TCTR_LOW
10831+ pax_force_retaddr_bts
10832 ret
10833
10834 /*
10835@@ -2554,6 +2582,7 @@ _aesni_inc:
10836 .Linc_low:
10837 movaps CTR, IV
10838 PSHUFB_XMM BSWAP_MASK IV
10839+ pax_force_retaddr_bts
10840 ret
10841
10842 /*
10843@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10844 .Lctr_enc_ret:
10845 movups IV, (IVP)
10846 .Lctr_enc_just_ret:
10847+ pax_force_retaddr 0, 1
10848 ret
10849+ENDPROC(aesni_ctr_enc)
10850 #endif
10851diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10852index 391d245..67f35c2 100644
10853--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10854+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10855@@ -20,6 +20,8 @@
10856 *
10857 */
10858
10859+#include <asm/alternative-asm.h>
10860+
10861 .file "blowfish-x86_64-asm.S"
10862 .text
10863
10864@@ -151,9 +153,11 @@ __blowfish_enc_blk:
10865 jnz __enc_xor;
10866
10867 write_block();
10868+ pax_force_retaddr 0, 1
10869 ret;
10870 __enc_xor:
10871 xor_block();
10872+ pax_force_retaddr 0, 1
10873 ret;
10874
10875 .align 8
10876@@ -188,6 +192,7 @@ blowfish_dec_blk:
10877
10878 movq %r11, %rbp;
10879
10880+ pax_force_retaddr 0, 1
10881 ret;
10882
10883 /**********************************************************************
10884@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10885
10886 popq %rbx;
10887 popq %rbp;
10888+ pax_force_retaddr 0, 1
10889 ret;
10890
10891 __enc_xor4:
10892@@ -349,6 +355,7 @@ __enc_xor4:
10893
10894 popq %rbx;
10895 popq %rbp;
10896+ pax_force_retaddr 0, 1
10897 ret;
10898
10899 .align 8
10900@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10901 popq %rbx;
10902 popq %rbp;
10903
10904+ pax_force_retaddr 0, 1
10905 ret;
10906
10907diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10908index 0b33743..7a56206 100644
10909--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10910+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10911@@ -20,6 +20,8 @@
10912 *
10913 */
10914
10915+#include <asm/alternative-asm.h>
10916+
10917 .file "camellia-x86_64-asm_64.S"
10918 .text
10919
10920@@ -229,12 +231,14 @@ __enc_done:
10921 enc_outunpack(mov, RT1);
10922
10923 movq RRBP, %rbp;
10924+ pax_force_retaddr 0, 1
10925 ret;
10926
10927 __enc_xor:
10928 enc_outunpack(xor, RT1);
10929
10930 movq RRBP, %rbp;
10931+ pax_force_retaddr 0, 1
10932 ret;
10933
10934 .global camellia_dec_blk;
10935@@ -275,6 +279,7 @@ __dec_rounds16:
10936 dec_outunpack();
10937
10938 movq RRBP, %rbp;
10939+ pax_force_retaddr 0, 1
10940 ret;
10941
10942 /**********************************************************************
10943@@ -468,6 +473,7 @@ __enc2_done:
10944
10945 movq RRBP, %rbp;
10946 popq %rbx;
10947+ pax_force_retaddr 0, 1
10948 ret;
10949
10950 __enc2_xor:
10951@@ -475,6 +481,7 @@ __enc2_xor:
10952
10953 movq RRBP, %rbp;
10954 popq %rbx;
10955+ pax_force_retaddr 0, 1
10956 ret;
10957
10958 .global camellia_dec_blk_2way;
10959@@ -517,4 +524,5 @@ __dec2_rounds16:
10960
10961 movq RRBP, %rbp;
10962 movq RXOR, %rbx;
10963+ pax_force_retaddr 0, 1
10964 ret;
10965diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10966index 15b00ac..2071784 100644
10967--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10968+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10969@@ -23,6 +23,8 @@
10970 *
10971 */
10972
10973+#include <asm/alternative-asm.h>
10974+
10975 .file "cast5-avx-x86_64-asm_64.S"
10976
10977 .extern cast_s1
10978@@ -281,6 +283,7 @@ __skip_enc:
10979 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10980 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10981
10982+ pax_force_retaddr 0, 1
10983 ret;
10984
10985 .align 16
10986@@ -353,6 +356,7 @@ __dec_tail:
10987 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10988 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10989
10990+ pax_force_retaddr 0, 1
10991 ret;
10992
10993 __skip_dec:
10994@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10995 vmovdqu RR4, (6*4*4)(%r11);
10996 vmovdqu RL4, (7*4*4)(%r11);
10997
10998+ pax_force_retaddr
10999 ret;
11000
11001 .align 16
11002@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
11003 vmovdqu RR4, (6*4*4)(%r11);
11004 vmovdqu RL4, (7*4*4)(%r11);
11005
11006+ pax_force_retaddr
11007 ret;
11008
11009 .align 16
11010@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
11011
11012 popq %r12;
11013
11014+ pax_force_retaddr
11015 ret;
11016
11017 .align 16
11018@@ -555,4 +562,5 @@ cast5_ctr_16way:
11019
11020 popq %r12;
11021
11022+ pax_force_retaddr
11023 ret;
11024diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11025index 2569d0d..637c289 100644
11026--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11027+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11028@@ -23,6 +23,8 @@
11029 *
11030 */
11031
11032+#include <asm/alternative-asm.h>
11033+
11034 #include "glue_helper-asm-avx.S"
11035
11036 .file "cast6-avx-x86_64-asm_64.S"
11037@@ -294,6 +296,7 @@ __cast6_enc_blk8:
11038 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11039 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11040
11041+ pax_force_retaddr 0, 1
11042 ret;
11043
11044 .align 8
11045@@ -340,6 +343,7 @@ __cast6_dec_blk8:
11046 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11047 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11048
11049+ pax_force_retaddr 0, 1
11050 ret;
11051
11052 .align 8
11053@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
11054
11055 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11056
11057+ pax_force_retaddr
11058 ret;
11059
11060 .align 8
11061@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
11062
11063 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11064
11065+ pax_force_retaddr
11066 ret;
11067
11068 .align 8
11069@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
11070
11071 popq %r12;
11072
11073+ pax_force_retaddr
11074 ret;
11075
11076 .align 8
11077@@ -436,4 +443,5 @@ cast6_ctr_8way:
11078
11079 popq %r12;
11080
11081+ pax_force_retaddr
11082 ret;
11083diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11084index 6214a9b..1f4fc9a 100644
11085--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11086+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11087@@ -1,3 +1,5 @@
11088+#include <asm/alternative-asm.h>
11089+
11090 # enter ECRYPT_encrypt_bytes
11091 .text
11092 .p2align 5
11093@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
11094 add %r11,%rsp
11095 mov %rdi,%rax
11096 mov %rsi,%rdx
11097+ pax_force_retaddr 0, 1
11098 ret
11099 # bytesatleast65:
11100 ._bytesatleast65:
11101@@ -891,6 +894,7 @@ ECRYPT_keysetup:
11102 add %r11,%rsp
11103 mov %rdi,%rax
11104 mov %rsi,%rdx
11105+ pax_force_retaddr
11106 ret
11107 # enter ECRYPT_ivsetup
11108 .text
11109@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
11110 add %r11,%rsp
11111 mov %rdi,%rax
11112 mov %rsi,%rdx
11113+ pax_force_retaddr
11114 ret
11115diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11116index 02b0e9f..cf4cf5c 100644
11117--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11118+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11119@@ -24,6 +24,8 @@
11120 *
11121 */
11122
11123+#include <asm/alternative-asm.h>
11124+
11125 #include "glue_helper-asm-avx.S"
11126
11127 .file "serpent-avx-x86_64-asm_64.S"
11128@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
11129 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11130 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11131
11132+ pax_force_retaddr
11133 ret;
11134
11135 .align 8
11136@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
11137 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11138 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11139
11140+ pax_force_retaddr
11141 ret;
11142
11143 .align 8
11144@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
11145
11146 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11147
11148+ pax_force_retaddr
11149 ret;
11150
11151 .align 8
11152@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
11153
11154 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11155
11156+ pax_force_retaddr
11157 ret;
11158
11159 .align 8
11160@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
11161
11162 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11163
11164+ pax_force_retaddr
11165 ret;
11166
11167 .align 8
11168@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
11169
11170 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11171
11172+ pax_force_retaddr
11173 ret;
11174diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11175index 3ee1ff0..cbc568b 100644
11176--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11177+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11178@@ -24,6 +24,8 @@
11179 *
11180 */
11181
11182+#include <asm/alternative-asm.h>
11183+
11184 .file "serpent-sse2-x86_64-asm_64.S"
11185 .text
11186
11187@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
11188 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11189 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11190
11191+ pax_force_retaddr
11192 ret;
11193
11194 __enc_xor8:
11195 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11196 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11197
11198+ pax_force_retaddr
11199 ret;
11200
11201 .align 8
11202@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
11203 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11204 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11205
11206+ pax_force_retaddr
11207 ret;
11208diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11209index 49d6987..df66bd4 100644
11210--- a/arch/x86/crypto/sha1_ssse3_asm.S
11211+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11212@@ -28,6 +28,8 @@
11213 * (at your option) any later version.
11214 */
11215
11216+#include <asm/alternative-asm.h>
11217+
11218 #define CTX %rdi // arg1
11219 #define BUF %rsi // arg2
11220 #define CNT %rdx // arg3
11221@@ -104,6 +106,7 @@
11222 pop %r12
11223 pop %rbp
11224 pop %rbx
11225+ pax_force_retaddr 0, 1
11226 ret
11227
11228 .size \name, .-\name
11229diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11230index ebac16b..8092eb9 100644
11231--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11232+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11233@@ -23,6 +23,8 @@
11234 *
11235 */
11236
11237+#include <asm/alternative-asm.h>
11238+
11239 #include "glue_helper-asm-avx.S"
11240
11241 .file "twofish-avx-x86_64-asm_64.S"
11242@@ -283,6 +285,7 @@ __twofish_enc_blk8:
11243 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11244 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11245
11246+ pax_force_retaddr 0, 1
11247 ret;
11248
11249 .align 8
11250@@ -324,6 +327,7 @@ __twofish_dec_blk8:
11251 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11252 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11253
11254+ pax_force_retaddr 0, 1
11255 ret;
11256
11257 .align 8
11258@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
11259
11260 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11261
11262+ pax_force_retaddr 0, 1
11263 ret;
11264
11265 .align 8
11266@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
11267
11268 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11269
11270+ pax_force_retaddr 0, 1
11271 ret;
11272
11273 .align 8
11274@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
11275
11276 popq %r12;
11277
11278+ pax_force_retaddr 0, 1
11279 ret;
11280
11281 .align 8
11282@@ -420,4 +427,5 @@ twofish_ctr_8way:
11283
11284 popq %r12;
11285
11286+ pax_force_retaddr 0, 1
11287 ret;
11288diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11289index 5b012a2..36d5364 100644
11290--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11291+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11292@@ -20,6 +20,8 @@
11293 *
11294 */
11295
11296+#include <asm/alternative-asm.h>
11297+
11298 .file "twofish-x86_64-asm-3way.S"
11299 .text
11300
11301@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
11302 popq %r13;
11303 popq %r14;
11304 popq %r15;
11305+ pax_force_retaddr 0, 1
11306 ret;
11307
11308 __enc_xor3:
11309@@ -271,6 +274,7 @@ __enc_xor3:
11310 popq %r13;
11311 popq %r14;
11312 popq %r15;
11313+ pax_force_retaddr 0, 1
11314 ret;
11315
11316 .global twofish_dec_blk_3way
11317@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11318 popq %r13;
11319 popq %r14;
11320 popq %r15;
11321+ pax_force_retaddr 0, 1
11322 ret;
11323
11324diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11325index 7bcf3fc..f53832f 100644
11326--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11327+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11328@@ -21,6 +21,7 @@
11329 .text
11330
11331 #include <asm/asm-offsets.h>
11332+#include <asm/alternative-asm.h>
11333
11334 #define a_offset 0
11335 #define b_offset 4
11336@@ -268,6 +269,7 @@ twofish_enc_blk:
11337
11338 popq R1
11339 movq $1,%rax
11340+ pax_force_retaddr 0, 1
11341 ret
11342
11343 twofish_dec_blk:
11344@@ -319,4 +321,5 @@ twofish_dec_blk:
11345
11346 popq R1
11347 movq $1,%rax
11348+ pax_force_retaddr 0, 1
11349 ret
11350diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11351index a703af1..f5b9c36 100644
11352--- a/arch/x86/ia32/ia32_aout.c
11353+++ b/arch/x86/ia32/ia32_aout.c
11354@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11355 unsigned long dump_start, dump_size;
11356 struct user32 dump;
11357
11358+ memset(&dump, 0, sizeof(dump));
11359+
11360 fs = get_fs();
11361 set_fs(KERNEL_DS);
11362 has_dumped = 1;
11363diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11364index a1daf4a..f8c4537 100644
11365--- a/arch/x86/ia32/ia32_signal.c
11366+++ b/arch/x86/ia32/ia32_signal.c
11367@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11368 sp -= frame_size;
11369 /* Align the stack pointer according to the i386 ABI,
11370 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11371- sp = ((sp + 4) & -16ul) - 4;
11372+ sp = ((sp - 12) & -16ul) - 4;
11373 return (void __user *) sp;
11374 }
11375
11376@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11377 * These are actually not used anymore, but left because some
11378 * gdb versions depend on them as a marker.
11379 */
11380- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11381+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11382 } put_user_catch(err);
11383
11384 if (err)
11385@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11386 0xb8,
11387 __NR_ia32_rt_sigreturn,
11388 0x80cd,
11389- 0,
11390+ 0
11391 };
11392
11393 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11394@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11395
11396 if (ka->sa.sa_flags & SA_RESTORER)
11397 restorer = ka->sa.sa_restorer;
11398+ else if (current->mm->context.vdso)
11399+ /* Return stub is in 32bit vsyscall page */
11400+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11401 else
11402- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11403- rt_sigreturn);
11404+ restorer = &frame->retcode;
11405 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11406
11407 /*
11408 * Not actually used anymore, but left because some gdb
11409 * versions need it.
11410 */
11411- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11412+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11413 } put_user_catch(err);
11414
11415 err |= copy_siginfo_to_user32(&frame->info, info);
11416diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11417index 142c4ce..19b683f 100644
11418--- a/arch/x86/ia32/ia32entry.S
11419+++ b/arch/x86/ia32/ia32entry.S
11420@@ -15,8 +15,10 @@
11421 #include <asm/irqflags.h>
11422 #include <asm/asm.h>
11423 #include <asm/smap.h>
11424+#include <asm/pgtable.h>
11425 #include <linux/linkage.h>
11426 #include <linux/err.h>
11427+#include <asm/alternative-asm.h>
11428
11429 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11430 #include <linux/elf-em.h>
11431@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11432 ENDPROC(native_irq_enable_sysexit)
11433 #endif
11434
11435+ .macro pax_enter_kernel_user
11436+ pax_set_fptr_mask
11437+#ifdef CONFIG_PAX_MEMORY_UDEREF
11438+ call pax_enter_kernel_user
11439+#endif
11440+ .endm
11441+
11442+ .macro pax_exit_kernel_user
11443+#ifdef CONFIG_PAX_MEMORY_UDEREF
11444+ call pax_exit_kernel_user
11445+#endif
11446+#ifdef CONFIG_PAX_RANDKSTACK
11447+ pushq %rax
11448+ pushq %r11
11449+ call pax_randomize_kstack
11450+ popq %r11
11451+ popq %rax
11452+#endif
11453+ .endm
11454+
11455+.macro pax_erase_kstack
11456+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11457+ call pax_erase_kstack
11458+#endif
11459+.endm
11460+
11461 /*
11462 * 32bit SYSENTER instruction entry.
11463 *
11464@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11465 CFI_REGISTER rsp,rbp
11466 SWAPGS_UNSAFE_STACK
11467 movq PER_CPU_VAR(kernel_stack), %rsp
11468- addq $(KERNEL_STACK_OFFSET),%rsp
11469- /*
11470- * No need to follow this irqs on/off section: the syscall
11471- * disabled irqs, here we enable it straight after entry:
11472- */
11473- ENABLE_INTERRUPTS(CLBR_NONE)
11474 movl %ebp,%ebp /* zero extension */
11475 pushq_cfi $__USER32_DS
11476 /*CFI_REL_OFFSET ss,0*/
11477@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11478 CFI_REL_OFFSET rsp,0
11479 pushfq_cfi
11480 /*CFI_REL_OFFSET rflags,0*/
11481- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11482- CFI_REGISTER rip,r10
11483+ orl $X86_EFLAGS_IF,(%rsp)
11484+ GET_THREAD_INFO(%r11)
11485+ movl TI_sysenter_return(%r11), %r11d
11486+ CFI_REGISTER rip,r11
11487 pushq_cfi $__USER32_CS
11488 /*CFI_REL_OFFSET cs,0*/
11489 movl %eax, %eax
11490- pushq_cfi %r10
11491+ pushq_cfi %r11
11492 CFI_REL_OFFSET rip,0
11493 pushq_cfi %rax
11494 cld
11495 SAVE_ARGS 0,1,0
11496+ pax_enter_kernel_user
11497+
11498+#ifdef CONFIG_PAX_RANDKSTACK
11499+ pax_erase_kstack
11500+#endif
11501+
11502+ /*
11503+ * No need to follow this irqs on/off section: the syscall
11504+ * disabled irqs, here we enable it straight after entry:
11505+ */
11506+ ENABLE_INTERRUPTS(CLBR_NONE)
11507 /* no need to do an access_ok check here because rbp has been
11508 32bit zero extended */
11509+
11510+#ifdef CONFIG_PAX_MEMORY_UDEREF
11511+ mov $PAX_USER_SHADOW_BASE,%r11
11512+ add %r11,%rbp
11513+#endif
11514+
11515 ASM_STAC
11516 1: movl (%rbp),%ebp
11517 _ASM_EXTABLE(1b,ia32_badarg)
11518 ASM_CLAC
11519- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11520- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11521+ GET_THREAD_INFO(%r11)
11522+ orl $TS_COMPAT,TI_status(%r11)
11523+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11524 CFI_REMEMBER_STATE
11525 jnz sysenter_tracesys
11526 cmpq $(IA32_NR_syscalls-1),%rax
11527@@ -162,12 +204,15 @@ sysenter_do_call:
11528 sysenter_dispatch:
11529 call *ia32_sys_call_table(,%rax,8)
11530 movq %rax,RAX-ARGOFFSET(%rsp)
11531+ GET_THREAD_INFO(%r11)
11532 DISABLE_INTERRUPTS(CLBR_NONE)
11533 TRACE_IRQS_OFF
11534- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11535+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11536 jnz sysexit_audit
11537 sysexit_from_sys_call:
11538- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11539+ pax_exit_kernel_user
11540+ pax_erase_kstack
11541+ andl $~TS_COMPAT,TI_status(%r11)
11542 /* clear IF, that popfq doesn't enable interrupts early */
11543 andl $~0x200,EFLAGS-R11(%rsp)
11544 movl RIP-R11(%rsp),%edx /* User %eip */
11545@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11546 movl %eax,%esi /* 2nd arg: syscall number */
11547 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11548 call __audit_syscall_entry
11549+
11550+ pax_erase_kstack
11551+
11552 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11553 cmpq $(IA32_NR_syscalls-1),%rax
11554 ja ia32_badsys
11555@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11556 .endm
11557
11558 .macro auditsys_exit exit
11559- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11560+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11561 jnz ia32_ret_from_sys_call
11562 TRACE_IRQS_ON
11563 ENABLE_INTERRUPTS(CLBR_NONE)
11564@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11565 1: setbe %al /* 1 if error, 0 if not */
11566 movzbl %al,%edi /* zero-extend that into %edi */
11567 call __audit_syscall_exit
11568+ GET_THREAD_INFO(%r11)
11569 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11570 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11571 DISABLE_INTERRUPTS(CLBR_NONE)
11572 TRACE_IRQS_OFF
11573- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11574+ testl %edi,TI_flags(%r11)
11575 jz \exit
11576 CLEAR_RREGS -ARGOFFSET
11577 jmp int_with_check
11578@@ -237,7 +286,7 @@ sysexit_audit:
11579
11580 sysenter_tracesys:
11581 #ifdef CONFIG_AUDITSYSCALL
11582- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11583+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11584 jz sysenter_auditsys
11585 #endif
11586 SAVE_REST
11587@@ -249,6 +298,9 @@ sysenter_tracesys:
11588 RESTORE_REST
11589 cmpq $(IA32_NR_syscalls-1),%rax
11590 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11591+
11592+ pax_erase_kstack
11593+
11594 jmp sysenter_do_call
11595 CFI_ENDPROC
11596 ENDPROC(ia32_sysenter_target)
11597@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11598 ENTRY(ia32_cstar_target)
11599 CFI_STARTPROC32 simple
11600 CFI_SIGNAL_FRAME
11601- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11602+ CFI_DEF_CFA rsp,0
11603 CFI_REGISTER rip,rcx
11604 /*CFI_REGISTER rflags,r11*/
11605 SWAPGS_UNSAFE_STACK
11606 movl %esp,%r8d
11607 CFI_REGISTER rsp,r8
11608 movq PER_CPU_VAR(kernel_stack),%rsp
11609+ SAVE_ARGS 8*6,0,0
11610+ pax_enter_kernel_user
11611+
11612+#ifdef CONFIG_PAX_RANDKSTACK
11613+ pax_erase_kstack
11614+#endif
11615+
11616 /*
11617 * No need to follow this irqs on/off section: the syscall
11618 * disabled irqs and here we enable it straight after entry:
11619 */
11620 ENABLE_INTERRUPTS(CLBR_NONE)
11621- SAVE_ARGS 8,0,0
11622 movl %eax,%eax /* zero extension */
11623 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11624 movq %rcx,RIP-ARGOFFSET(%rsp)
11625@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11626 /* no need to do an access_ok check here because r8 has been
11627 32bit zero extended */
11628 /* hardware stack frame is complete now */
11629+
11630+#ifdef CONFIG_PAX_MEMORY_UDEREF
11631+ mov $PAX_USER_SHADOW_BASE,%r11
11632+ add %r11,%r8
11633+#endif
11634+
11635 ASM_STAC
11636 1: movl (%r8),%r9d
11637 _ASM_EXTABLE(1b,ia32_badarg)
11638 ASM_CLAC
11639- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11640- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11641+ GET_THREAD_INFO(%r11)
11642+ orl $TS_COMPAT,TI_status(%r11)
11643+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11644 CFI_REMEMBER_STATE
11645 jnz cstar_tracesys
11646 cmpq $IA32_NR_syscalls-1,%rax
11647@@ -319,12 +384,15 @@ cstar_do_call:
11648 cstar_dispatch:
11649 call *ia32_sys_call_table(,%rax,8)
11650 movq %rax,RAX-ARGOFFSET(%rsp)
11651+ GET_THREAD_INFO(%r11)
11652 DISABLE_INTERRUPTS(CLBR_NONE)
11653 TRACE_IRQS_OFF
11654- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11655+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11656 jnz sysretl_audit
11657 sysretl_from_sys_call:
11658- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11659+ pax_exit_kernel_user
11660+ pax_erase_kstack
11661+ andl $~TS_COMPAT,TI_status(%r11)
11662 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11663 movl RIP-ARGOFFSET(%rsp),%ecx
11664 CFI_REGISTER rip,rcx
11665@@ -352,7 +420,7 @@ sysretl_audit:
11666
11667 cstar_tracesys:
11668 #ifdef CONFIG_AUDITSYSCALL
11669- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11670+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11671 jz cstar_auditsys
11672 #endif
11673 xchgl %r9d,%ebp
11674@@ -366,6 +434,9 @@ cstar_tracesys:
11675 xchgl %ebp,%r9d
11676 cmpq $(IA32_NR_syscalls-1),%rax
11677 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11678+
11679+ pax_erase_kstack
11680+
11681 jmp cstar_do_call
11682 END(ia32_cstar_target)
11683
11684@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11685 CFI_REL_OFFSET rip,RIP-RIP
11686 PARAVIRT_ADJUST_EXCEPTION_FRAME
11687 SWAPGS
11688- /*
11689- * No need to follow this irqs on/off section: the syscall
11690- * disabled irqs and here we enable it straight after entry:
11691- */
11692- ENABLE_INTERRUPTS(CLBR_NONE)
11693 movl %eax,%eax
11694 pushq_cfi %rax
11695 cld
11696 /* note the registers are not zero extended to the sf.
11697 this could be a problem. */
11698 SAVE_ARGS 0,1,0
11699- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11700- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11701+ pax_enter_kernel_user
11702+
11703+#ifdef CONFIG_PAX_RANDKSTACK
11704+ pax_erase_kstack
11705+#endif
11706+
11707+ /*
11708+ * No need to follow this irqs on/off section: the syscall
11709+ * disabled irqs and here we enable it straight after entry:
11710+ */
11711+ ENABLE_INTERRUPTS(CLBR_NONE)
11712+ GET_THREAD_INFO(%r11)
11713+ orl $TS_COMPAT,TI_status(%r11)
11714+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11715 jnz ia32_tracesys
11716 cmpq $(IA32_NR_syscalls-1),%rax
11717 ja ia32_badsys
11718@@ -442,6 +520,9 @@ ia32_tracesys:
11719 RESTORE_REST
11720 cmpq $(IA32_NR_syscalls-1),%rax
11721 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11722+
11723+ pax_erase_kstack
11724+
11725 jmp ia32_do_call
11726 END(ia32_syscall)
11727
11728diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11729index d0b689b..34be51d 100644
11730--- a/arch/x86/ia32/sys_ia32.c
11731+++ b/arch/x86/ia32/sys_ia32.c
11732@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11733 */
11734 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11735 {
11736- typeof(ubuf->st_uid) uid = 0;
11737- typeof(ubuf->st_gid) gid = 0;
11738+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11739+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11740 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11741 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11742 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11743@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11744 mm_segment_t old_fs = get_fs();
11745
11746 set_fs(KERNEL_DS);
11747- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11748+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11749 set_fs(old_fs);
11750 if (put_compat_timespec(&t, interval))
11751 return -EFAULT;
11752@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11753 mm_segment_t old_fs = get_fs();
11754
11755 set_fs(KERNEL_DS);
11756- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11757+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11758 set_fs(old_fs);
11759 if (!ret) {
11760 switch (_NSIG_WORDS) {
11761@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11762 if (copy_siginfo_from_user32(&info, uinfo))
11763 return -EFAULT;
11764 set_fs(KERNEL_DS);
11765- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11766+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11767 set_fs(old_fs);
11768 return ret;
11769 }
11770@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11771 return -EFAULT;
11772
11773 set_fs(KERNEL_DS);
11774- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11775+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11776 count);
11777 set_fs(old_fs);
11778
11779diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11780index 372231c..a5aa1a1 100644
11781--- a/arch/x86/include/asm/alternative-asm.h
11782+++ b/arch/x86/include/asm/alternative-asm.h
11783@@ -18,6 +18,45 @@
11784 .endm
11785 #endif
11786
11787+#ifdef KERNEXEC_PLUGIN
11788+ .macro pax_force_retaddr_bts rip=0
11789+ btsq $63,\rip(%rsp)
11790+ .endm
11791+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11792+ .macro pax_force_retaddr rip=0, reload=0
11793+ btsq $63,\rip(%rsp)
11794+ .endm
11795+ .macro pax_force_fptr ptr
11796+ btsq $63,\ptr
11797+ .endm
11798+ .macro pax_set_fptr_mask
11799+ .endm
11800+#endif
11801+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11802+ .macro pax_force_retaddr rip=0, reload=0
11803+ .if \reload
11804+ pax_set_fptr_mask
11805+ .endif
11806+ orq %r10,\rip(%rsp)
11807+ .endm
11808+ .macro pax_force_fptr ptr
11809+ orq %r10,\ptr
11810+ .endm
11811+ .macro pax_set_fptr_mask
11812+ movabs $0x8000000000000000,%r10
11813+ .endm
11814+#endif
11815+#else
11816+ .macro pax_force_retaddr rip=0, reload=0
11817+ .endm
11818+ .macro pax_force_fptr ptr
11819+ .endm
11820+ .macro pax_force_retaddr_bts rip=0
11821+ .endm
11822+ .macro pax_set_fptr_mask
11823+ .endm
11824+#endif
11825+
11826 .macro altinstruction_entry orig alt feature orig_len alt_len
11827 .long \orig - .
11828 .long \alt - .
11829diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11830index 58ed6d9..f1cbe58 100644
11831--- a/arch/x86/include/asm/alternative.h
11832+++ b/arch/x86/include/asm/alternative.h
11833@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11834 ".pushsection .discard,\"aw\",@progbits\n" \
11835 DISCARD_ENTRY(1) \
11836 ".popsection\n" \
11837- ".pushsection .altinstr_replacement, \"ax\"\n" \
11838+ ".pushsection .altinstr_replacement, \"a\"\n" \
11839 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11840 ".popsection"
11841
11842@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11843 DISCARD_ENTRY(1) \
11844 DISCARD_ENTRY(2) \
11845 ".popsection\n" \
11846- ".pushsection .altinstr_replacement, \"ax\"\n" \
11847+ ".pushsection .altinstr_replacement, \"a\"\n" \
11848 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11849 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11850 ".popsection"
11851diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11852index 3388034..050f0b9 100644
11853--- a/arch/x86/include/asm/apic.h
11854+++ b/arch/x86/include/asm/apic.h
11855@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11856
11857 #ifdef CONFIG_X86_LOCAL_APIC
11858
11859-extern unsigned int apic_verbosity;
11860+extern int apic_verbosity;
11861 extern int local_apic_timer_c2_ok;
11862
11863 extern int disable_apic;
11864diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11865index 20370c6..a2eb9b0 100644
11866--- a/arch/x86/include/asm/apm.h
11867+++ b/arch/x86/include/asm/apm.h
11868@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11869 __asm__ __volatile__(APM_DO_ZERO_SEGS
11870 "pushl %%edi\n\t"
11871 "pushl %%ebp\n\t"
11872- "lcall *%%cs:apm_bios_entry\n\t"
11873+ "lcall *%%ss:apm_bios_entry\n\t"
11874 "setc %%al\n\t"
11875 "popl %%ebp\n\t"
11876 "popl %%edi\n\t"
11877@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11878 __asm__ __volatile__(APM_DO_ZERO_SEGS
11879 "pushl %%edi\n\t"
11880 "pushl %%ebp\n\t"
11881- "lcall *%%cs:apm_bios_entry\n\t"
11882+ "lcall *%%ss:apm_bios_entry\n\t"
11883 "setc %%bl\n\t"
11884 "popl %%ebp\n\t"
11885 "popl %%edi\n\t"
11886diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11887index 722aa3b..3a0bb27 100644
11888--- a/arch/x86/include/asm/atomic.h
11889+++ b/arch/x86/include/asm/atomic.h
11890@@ -22,7 +22,18 @@
11891 */
11892 static inline int atomic_read(const atomic_t *v)
11893 {
11894- return (*(volatile int *)&(v)->counter);
11895+ return (*(volatile const int *)&(v)->counter);
11896+}
11897+
11898+/**
11899+ * atomic_read_unchecked - read atomic variable
11900+ * @v: pointer of type atomic_unchecked_t
11901+ *
11902+ * Atomically reads the value of @v.
11903+ */
11904+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11905+{
11906+ return (*(volatile const int *)&(v)->counter);
11907 }
11908
11909 /**
11910@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11911 }
11912
11913 /**
11914+ * atomic_set_unchecked - set atomic variable
11915+ * @v: pointer of type atomic_unchecked_t
11916+ * @i: required value
11917+ *
11918+ * Atomically sets the value of @v to @i.
11919+ */
11920+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11921+{
11922+ v->counter = i;
11923+}
11924+
11925+/**
11926 * atomic_add - add integer to atomic variable
11927 * @i: integer value to add
11928 * @v: pointer of type atomic_t
11929@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11930 */
11931 static inline void atomic_add(int i, atomic_t *v)
11932 {
11933- asm volatile(LOCK_PREFIX "addl %1,%0"
11934+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11935+
11936+#ifdef CONFIG_PAX_REFCOUNT
11937+ "jno 0f\n"
11938+ LOCK_PREFIX "subl %1,%0\n"
11939+ "int $4\n0:\n"
11940+ _ASM_EXTABLE(0b, 0b)
11941+#endif
11942+
11943+ : "+m" (v->counter)
11944+ : "ir" (i));
11945+}
11946+
11947+/**
11948+ * atomic_add_unchecked - add integer to atomic variable
11949+ * @i: integer value to add
11950+ * @v: pointer of type atomic_unchecked_t
11951+ *
11952+ * Atomically adds @i to @v.
11953+ */
11954+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11955+{
11956+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11957 : "+m" (v->counter)
11958 : "ir" (i));
11959 }
11960@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11961 */
11962 static inline void atomic_sub(int i, atomic_t *v)
11963 {
11964- asm volatile(LOCK_PREFIX "subl %1,%0"
11965+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11966+
11967+#ifdef CONFIG_PAX_REFCOUNT
11968+ "jno 0f\n"
11969+ LOCK_PREFIX "addl %1,%0\n"
11970+ "int $4\n0:\n"
11971+ _ASM_EXTABLE(0b, 0b)
11972+#endif
11973+
11974+ : "+m" (v->counter)
11975+ : "ir" (i));
11976+}
11977+
11978+/**
11979+ * atomic_sub_unchecked - subtract integer from atomic variable
11980+ * @i: integer value to subtract
11981+ * @v: pointer of type atomic_unchecked_t
11982+ *
11983+ * Atomically subtracts @i from @v.
11984+ */
11985+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11986+{
11987+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11988 : "+m" (v->counter)
11989 : "ir" (i));
11990 }
11991@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11992 {
11993 unsigned char c;
11994
11995- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11996+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
11997+
11998+#ifdef CONFIG_PAX_REFCOUNT
11999+ "jno 0f\n"
12000+ LOCK_PREFIX "addl %2,%0\n"
12001+ "int $4\n0:\n"
12002+ _ASM_EXTABLE(0b, 0b)
12003+#endif
12004+
12005+ "sete %1\n"
12006 : "+m" (v->counter), "=qm" (c)
12007 : "ir" (i) : "memory");
12008 return c;
12009@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12010 */
12011 static inline void atomic_inc(atomic_t *v)
12012 {
12013- asm volatile(LOCK_PREFIX "incl %0"
12014+ asm volatile(LOCK_PREFIX "incl %0\n"
12015+
12016+#ifdef CONFIG_PAX_REFCOUNT
12017+ "jno 0f\n"
12018+ LOCK_PREFIX "decl %0\n"
12019+ "int $4\n0:\n"
12020+ _ASM_EXTABLE(0b, 0b)
12021+#endif
12022+
12023+ : "+m" (v->counter));
12024+}
12025+
12026+/**
12027+ * atomic_inc_unchecked - increment atomic variable
12028+ * @v: pointer of type atomic_unchecked_t
12029+ *
12030+ * Atomically increments @v by 1.
12031+ */
12032+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12033+{
12034+ asm volatile(LOCK_PREFIX "incl %0\n"
12035 : "+m" (v->counter));
12036 }
12037
12038@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12039 */
12040 static inline void atomic_dec(atomic_t *v)
12041 {
12042- asm volatile(LOCK_PREFIX "decl %0"
12043+ asm volatile(LOCK_PREFIX "decl %0\n"
12044+
12045+#ifdef CONFIG_PAX_REFCOUNT
12046+ "jno 0f\n"
12047+ LOCK_PREFIX "incl %0\n"
12048+ "int $4\n0:\n"
12049+ _ASM_EXTABLE(0b, 0b)
12050+#endif
12051+
12052+ : "+m" (v->counter));
12053+}
12054+
12055+/**
12056+ * atomic_dec_unchecked - decrement atomic variable
12057+ * @v: pointer of type atomic_unchecked_t
12058+ *
12059+ * Atomically decrements @v by 1.
12060+ */
12061+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12062+{
12063+ asm volatile(LOCK_PREFIX "decl %0\n"
12064 : "+m" (v->counter));
12065 }
12066
12067@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12068 {
12069 unsigned char c;
12070
12071- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12072+ asm volatile(LOCK_PREFIX "decl %0\n"
12073+
12074+#ifdef CONFIG_PAX_REFCOUNT
12075+ "jno 0f\n"
12076+ LOCK_PREFIX "incl %0\n"
12077+ "int $4\n0:\n"
12078+ _ASM_EXTABLE(0b, 0b)
12079+#endif
12080+
12081+ "sete %1\n"
12082 : "+m" (v->counter), "=qm" (c)
12083 : : "memory");
12084 return c != 0;
12085@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12086 {
12087 unsigned char c;
12088
12089- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12090+ asm volatile(LOCK_PREFIX "incl %0\n"
12091+
12092+#ifdef CONFIG_PAX_REFCOUNT
12093+ "jno 0f\n"
12094+ LOCK_PREFIX "decl %0\n"
12095+ "int $4\n0:\n"
12096+ _ASM_EXTABLE(0b, 0b)
12097+#endif
12098+
12099+ "sete %1\n"
12100+ : "+m" (v->counter), "=qm" (c)
12101+ : : "memory");
12102+ return c != 0;
12103+}
12104+
12105+/**
12106+ * atomic_inc_and_test_unchecked - increment and test
12107+ * @v: pointer of type atomic_unchecked_t
12108+ *
12109+ * Atomically increments @v by 1
12110+ * and returns true if the result is zero, or false for all
12111+ * other cases.
12112+ */
12113+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12114+{
12115+ unsigned char c;
12116+
12117+ asm volatile(LOCK_PREFIX "incl %0\n"
12118+ "sete %1\n"
12119 : "+m" (v->counter), "=qm" (c)
12120 : : "memory");
12121 return c != 0;
12122@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12123 {
12124 unsigned char c;
12125
12126- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12127+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12128+
12129+#ifdef CONFIG_PAX_REFCOUNT
12130+ "jno 0f\n"
12131+ LOCK_PREFIX "subl %2,%0\n"
12132+ "int $4\n0:\n"
12133+ _ASM_EXTABLE(0b, 0b)
12134+#endif
12135+
12136+ "sets %1\n"
12137 : "+m" (v->counter), "=qm" (c)
12138 : "ir" (i) : "memory");
12139 return c;
12140@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12141 */
12142 static inline int atomic_add_return(int i, atomic_t *v)
12143 {
12144+ return i + xadd_check_overflow(&v->counter, i);
12145+}
12146+
12147+/**
12148+ * atomic_add_return_unchecked - add integer and return
12149+ * @i: integer value to add
12150+ * @v: pointer of type atomic_unchecked_t
12151+ *
12152+ * Atomically adds @i to @v and returns @i + @v
12153+ */
12154+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12155+{
12156 return i + xadd(&v->counter, i);
12157 }
12158
12159@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12160 }
12161
12162 #define atomic_inc_return(v) (atomic_add_return(1, v))
12163+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12164+{
12165+ return atomic_add_return_unchecked(1, v);
12166+}
12167 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12168
12169 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12170@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12171 return cmpxchg(&v->counter, old, new);
12172 }
12173
12174+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12175+{
12176+ return cmpxchg(&v->counter, old, new);
12177+}
12178+
12179 static inline int atomic_xchg(atomic_t *v, int new)
12180 {
12181 return xchg(&v->counter, new);
12182 }
12183
12184+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12185+{
12186+ return xchg(&v->counter, new);
12187+}
12188+
12189 /**
12190 * __atomic_add_unless - add unless the number is already a given value
12191 * @v: pointer of type atomic_t
12192@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12193 */
12194 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12195 {
12196- int c, old;
12197+ int c, old, new;
12198 c = atomic_read(v);
12199 for (;;) {
12200- if (unlikely(c == (u)))
12201+ if (unlikely(c == u))
12202 break;
12203- old = atomic_cmpxchg((v), c, c + (a));
12204+
12205+ asm volatile("addl %2,%0\n"
12206+
12207+#ifdef CONFIG_PAX_REFCOUNT
12208+ "jno 0f\n"
12209+ "subl %2,%0\n"
12210+ "int $4\n0:\n"
12211+ _ASM_EXTABLE(0b, 0b)
12212+#endif
12213+
12214+ : "=r" (new)
12215+ : "0" (c), "ir" (a));
12216+
12217+ old = atomic_cmpxchg(v, c, new);
12218 if (likely(old == c))
12219 break;
12220 c = old;
12221@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12222 }
12223
12224 /**
12225+ * atomic_inc_not_zero_hint - increment if not null
12226+ * @v: pointer of type atomic_t
12227+ * @hint: probable value of the atomic before the increment
12228+ *
12229+ * This version of atomic_inc_not_zero() gives a hint of probable
12230+ * value of the atomic. This helps processor to not read the memory
12231+ * before doing the atomic read/modify/write cycle, lowering
12232+ * number of bus transactions on some arches.
12233+ *
12234+ * Returns: 0 if increment was not done, 1 otherwise.
12235+ */
12236+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12237+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12238+{
12239+ int val, c = hint, new;
12240+
12241+ /* sanity test, should be removed by compiler if hint is a constant */
12242+ if (!hint)
12243+ return __atomic_add_unless(v, 1, 0);
12244+
12245+ do {
12246+ asm volatile("incl %0\n"
12247+
12248+#ifdef CONFIG_PAX_REFCOUNT
12249+ "jno 0f\n"
12250+ "decl %0\n"
12251+ "int $4\n0:\n"
12252+ _ASM_EXTABLE(0b, 0b)
12253+#endif
12254+
12255+ : "=r" (new)
12256+ : "0" (c));
12257+
12258+ val = atomic_cmpxchg(v, c, new);
12259+ if (val == c)
12260+ return 1;
12261+ c = val;
12262+ } while (c);
12263+
12264+ return 0;
12265+}
12266+
12267+/**
12268 * atomic_inc_short - increment of a short integer
12269 * @v: pointer to type int
12270 *
12271@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12272 #endif
12273
12274 /* These are x86-specific, used by some header files */
12275-#define atomic_clear_mask(mask, addr) \
12276- asm volatile(LOCK_PREFIX "andl %0,%1" \
12277- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12278+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12279+{
12280+ asm volatile(LOCK_PREFIX "andl %1,%0"
12281+ : "+m" (v->counter)
12282+ : "r" (~(mask))
12283+ : "memory");
12284+}
12285
12286-#define atomic_set_mask(mask, addr) \
12287- asm volatile(LOCK_PREFIX "orl %0,%1" \
12288- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12289- : "memory")
12290+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12291+{
12292+ asm volatile(LOCK_PREFIX "andl %1,%0"
12293+ : "+m" (v->counter)
12294+ : "r" (~(mask))
12295+ : "memory");
12296+}
12297+
12298+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12299+{
12300+ asm volatile(LOCK_PREFIX "orl %1,%0"
12301+ : "+m" (v->counter)
12302+ : "r" (mask)
12303+ : "memory");
12304+}
12305+
12306+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12307+{
12308+ asm volatile(LOCK_PREFIX "orl %1,%0"
12309+ : "+m" (v->counter)
12310+ : "r" (mask)
12311+ : "memory");
12312+}
12313
12314 /* Atomic operations are already serializing on x86 */
12315 #define smp_mb__before_atomic_dec() barrier()
12316diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12317index b154de7..aadebd8 100644
12318--- a/arch/x86/include/asm/atomic64_32.h
12319+++ b/arch/x86/include/asm/atomic64_32.h
12320@@ -12,6 +12,14 @@ typedef struct {
12321 u64 __aligned(8) counter;
12322 } atomic64_t;
12323
12324+#ifdef CONFIG_PAX_REFCOUNT
12325+typedef struct {
12326+ u64 __aligned(8) counter;
12327+} atomic64_unchecked_t;
12328+#else
12329+typedef atomic64_t atomic64_unchecked_t;
12330+#endif
12331+
12332 #define ATOMIC64_INIT(val) { (val) }
12333
12334 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12335@@ -37,21 +45,31 @@ typedef struct {
12336 ATOMIC64_DECL_ONE(sym##_386)
12337
12338 ATOMIC64_DECL_ONE(add_386);
12339+ATOMIC64_DECL_ONE(add_unchecked_386);
12340 ATOMIC64_DECL_ONE(sub_386);
12341+ATOMIC64_DECL_ONE(sub_unchecked_386);
12342 ATOMIC64_DECL_ONE(inc_386);
12343+ATOMIC64_DECL_ONE(inc_unchecked_386);
12344 ATOMIC64_DECL_ONE(dec_386);
12345+ATOMIC64_DECL_ONE(dec_unchecked_386);
12346 #endif
12347
12348 #define alternative_atomic64(f, out, in...) \
12349 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12350
12351 ATOMIC64_DECL(read);
12352+ATOMIC64_DECL(read_unchecked);
12353 ATOMIC64_DECL(set);
12354+ATOMIC64_DECL(set_unchecked);
12355 ATOMIC64_DECL(xchg);
12356 ATOMIC64_DECL(add_return);
12357+ATOMIC64_DECL(add_return_unchecked);
12358 ATOMIC64_DECL(sub_return);
12359+ATOMIC64_DECL(sub_return_unchecked);
12360 ATOMIC64_DECL(inc_return);
12361+ATOMIC64_DECL(inc_return_unchecked);
12362 ATOMIC64_DECL(dec_return);
12363+ATOMIC64_DECL(dec_return_unchecked);
12364 ATOMIC64_DECL(dec_if_positive);
12365 ATOMIC64_DECL(inc_not_zero);
12366 ATOMIC64_DECL(add_unless);
12367@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12368 }
12369
12370 /**
12371+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12372+ * @p: pointer to type atomic64_unchecked_t
12373+ * @o: expected value
12374+ * @n: new value
12375+ *
12376+ * Atomically sets @v to @n if it was equal to @o and returns
12377+ * the old value.
12378+ */
12379+
12380+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12381+{
12382+ return cmpxchg64(&v->counter, o, n);
12383+}
12384+
12385+/**
12386 * atomic64_xchg - xchg atomic64 variable
12387 * @v: pointer to type atomic64_t
12388 * @n: value to assign
12389@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12390 }
12391
12392 /**
12393+ * atomic64_set_unchecked - set atomic64 variable
12394+ * @v: pointer to type atomic64_unchecked_t
12395+ * @n: value to assign
12396+ *
12397+ * Atomically sets the value of @v to @n.
12398+ */
12399+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12400+{
12401+ unsigned high = (unsigned)(i >> 32);
12402+ unsigned low = (unsigned)i;
12403+ alternative_atomic64(set, /* no output */,
12404+ "S" (v), "b" (low), "c" (high)
12405+ : "eax", "edx", "memory");
12406+}
12407+
12408+/**
12409 * atomic64_read - read atomic64 variable
12410 * @v: pointer to type atomic64_t
12411 *
12412@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12413 }
12414
12415 /**
12416+ * atomic64_read_unchecked - read atomic64 variable
12417+ * @v: pointer to type atomic64_unchecked_t
12418+ *
12419+ * Atomically reads the value of @v and returns it.
12420+ */
12421+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12422+{
12423+ long long r;
12424+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12425+ return r;
12426+ }
12427+
12428+/**
12429 * atomic64_add_return - add and return
12430 * @i: integer value to add
12431 * @v: pointer to type atomic64_t
12432@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12433 return i;
12434 }
12435
12436+/**
12437+ * atomic64_add_return_unchecked - add and return
12438+ * @i: integer value to add
12439+ * @v: pointer to type atomic64_unchecked_t
12440+ *
12441+ * Atomically adds @i to @v and returns @i + *@v
12442+ */
12443+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12444+{
12445+ alternative_atomic64(add_return_unchecked,
12446+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12447+ ASM_NO_INPUT_CLOBBER("memory"));
12448+ return i;
12449+}
12450+
12451 /*
12452 * Other variants with different arithmetic operators:
12453 */
12454@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12455 return a;
12456 }
12457
12458+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12459+{
12460+ long long a;
12461+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12462+ "S" (v) : "memory", "ecx");
12463+ return a;
12464+}
12465+
12466 static inline long long atomic64_dec_return(atomic64_t *v)
12467 {
12468 long long a;
12469@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12470 }
12471
12472 /**
12473+ * atomic64_add_unchecked - add integer to atomic64 variable
12474+ * @i: integer value to add
12475+ * @v: pointer to type atomic64_unchecked_t
12476+ *
12477+ * Atomically adds @i to @v.
12478+ */
12479+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12480+{
12481+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12482+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12483+ ASM_NO_INPUT_CLOBBER("memory"));
12484+ return i;
12485+}
12486+
12487+/**
12488 * atomic64_sub - subtract the atomic64 variable
12489 * @i: integer value to subtract
12490 * @v: pointer to type atomic64_t
12491diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12492index 0e1cbfc..5623683 100644
12493--- a/arch/x86/include/asm/atomic64_64.h
12494+++ b/arch/x86/include/asm/atomic64_64.h
12495@@ -18,7 +18,19 @@
12496 */
12497 static inline long atomic64_read(const atomic64_t *v)
12498 {
12499- return (*(volatile long *)&(v)->counter);
12500+ return (*(volatile const long *)&(v)->counter);
12501+}
12502+
12503+/**
12504+ * atomic64_read_unchecked - read atomic64 variable
12505+ * @v: pointer of type atomic64_unchecked_t
12506+ *
12507+ * Atomically reads the value of @v.
12508+ * Doesn't imply a read memory barrier.
12509+ */
12510+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12511+{
12512+ return (*(volatile const long *)&(v)->counter);
12513 }
12514
12515 /**
12516@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12517 }
12518
12519 /**
12520+ * atomic64_set_unchecked - set atomic64 variable
12521+ * @v: pointer to type atomic64_unchecked_t
12522+ * @i: required value
12523+ *
12524+ * Atomically sets the value of @v to @i.
12525+ */
12526+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12527+{
12528+ v->counter = i;
12529+}
12530+
12531+/**
12532 * atomic64_add - add integer to atomic64 variable
12533 * @i: integer value to add
12534 * @v: pointer to type atomic64_t
12535@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12536 */
12537 static inline void atomic64_add(long i, atomic64_t *v)
12538 {
12539+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12540+
12541+#ifdef CONFIG_PAX_REFCOUNT
12542+ "jno 0f\n"
12543+ LOCK_PREFIX "subq %1,%0\n"
12544+ "int $4\n0:\n"
12545+ _ASM_EXTABLE(0b, 0b)
12546+#endif
12547+
12548+ : "=m" (v->counter)
12549+ : "er" (i), "m" (v->counter));
12550+}
12551+
12552+/**
12553+ * atomic64_add_unchecked - add integer to atomic64 variable
12554+ * @i: integer value to add
12555+ * @v: pointer to type atomic64_unchecked_t
12556+ *
12557+ * Atomically adds @i to @v.
12558+ */
12559+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12560+{
12561 asm volatile(LOCK_PREFIX "addq %1,%0"
12562 : "=m" (v->counter)
12563 : "er" (i), "m" (v->counter));
12564@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12565 */
12566 static inline void atomic64_sub(long i, atomic64_t *v)
12567 {
12568- asm volatile(LOCK_PREFIX "subq %1,%0"
12569+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12570+
12571+#ifdef CONFIG_PAX_REFCOUNT
12572+ "jno 0f\n"
12573+ LOCK_PREFIX "addq %1,%0\n"
12574+ "int $4\n0:\n"
12575+ _ASM_EXTABLE(0b, 0b)
12576+#endif
12577+
12578+ : "=m" (v->counter)
12579+ : "er" (i), "m" (v->counter));
12580+}
12581+
12582+/**
12583+ * atomic64_sub_unchecked - subtract the atomic64 variable
12584+ * @i: integer value to subtract
12585+ * @v: pointer to type atomic64_unchecked_t
12586+ *
12587+ * Atomically subtracts @i from @v.
12588+ */
12589+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12590+{
12591+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12592 : "=m" (v->counter)
12593 : "er" (i), "m" (v->counter));
12594 }
12595@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12596 {
12597 unsigned char c;
12598
12599- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12600+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12601+
12602+#ifdef CONFIG_PAX_REFCOUNT
12603+ "jno 0f\n"
12604+ LOCK_PREFIX "addq %2,%0\n"
12605+ "int $4\n0:\n"
12606+ _ASM_EXTABLE(0b, 0b)
12607+#endif
12608+
12609+ "sete %1\n"
12610 : "=m" (v->counter), "=qm" (c)
12611 : "er" (i), "m" (v->counter) : "memory");
12612 return c;
12613@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12614 */
12615 static inline void atomic64_inc(atomic64_t *v)
12616 {
12617+ asm volatile(LOCK_PREFIX "incq %0\n"
12618+
12619+#ifdef CONFIG_PAX_REFCOUNT
12620+ "jno 0f\n"
12621+ LOCK_PREFIX "decq %0\n"
12622+ "int $4\n0:\n"
12623+ _ASM_EXTABLE(0b, 0b)
12624+#endif
12625+
12626+ : "=m" (v->counter)
12627+ : "m" (v->counter));
12628+}
12629+
12630+/**
12631+ * atomic64_inc_unchecked - increment atomic64 variable
12632+ * @v: pointer to type atomic64_unchecked_t
12633+ *
12634+ * Atomically increments @v by 1.
12635+ */
12636+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12637+{
12638 asm volatile(LOCK_PREFIX "incq %0"
12639 : "=m" (v->counter)
12640 : "m" (v->counter));
12641@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12642 */
12643 static inline void atomic64_dec(atomic64_t *v)
12644 {
12645- asm volatile(LOCK_PREFIX "decq %0"
12646+ asm volatile(LOCK_PREFIX "decq %0\n"
12647+
12648+#ifdef CONFIG_PAX_REFCOUNT
12649+ "jno 0f\n"
12650+ LOCK_PREFIX "incq %0\n"
12651+ "int $4\n0:\n"
12652+ _ASM_EXTABLE(0b, 0b)
12653+#endif
12654+
12655+ : "=m" (v->counter)
12656+ : "m" (v->counter));
12657+}
12658+
12659+/**
12660+ * atomic64_dec_unchecked - decrement atomic64 variable
12661+ * @v: pointer to type atomic64_t
12662+ *
12663+ * Atomically decrements @v by 1.
12664+ */
12665+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12666+{
12667+ asm volatile(LOCK_PREFIX "decq %0\n"
12668 : "=m" (v->counter)
12669 : "m" (v->counter));
12670 }
12671@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12672 {
12673 unsigned char c;
12674
12675- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12676+ asm volatile(LOCK_PREFIX "decq %0\n"
12677+
12678+#ifdef CONFIG_PAX_REFCOUNT
12679+ "jno 0f\n"
12680+ LOCK_PREFIX "incq %0\n"
12681+ "int $4\n0:\n"
12682+ _ASM_EXTABLE(0b, 0b)
12683+#endif
12684+
12685+ "sete %1\n"
12686 : "=m" (v->counter), "=qm" (c)
12687 : "m" (v->counter) : "memory");
12688 return c != 0;
12689@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12690 {
12691 unsigned char c;
12692
12693- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12694+ asm volatile(LOCK_PREFIX "incq %0\n"
12695+
12696+#ifdef CONFIG_PAX_REFCOUNT
12697+ "jno 0f\n"
12698+ LOCK_PREFIX "decq %0\n"
12699+ "int $4\n0:\n"
12700+ _ASM_EXTABLE(0b, 0b)
12701+#endif
12702+
12703+ "sete %1\n"
12704 : "=m" (v->counter), "=qm" (c)
12705 : "m" (v->counter) : "memory");
12706 return c != 0;
12707@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12708 {
12709 unsigned char c;
12710
12711- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12712+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12713+
12714+#ifdef CONFIG_PAX_REFCOUNT
12715+ "jno 0f\n"
12716+ LOCK_PREFIX "subq %2,%0\n"
12717+ "int $4\n0:\n"
12718+ _ASM_EXTABLE(0b, 0b)
12719+#endif
12720+
12721+ "sets %1\n"
12722 : "=m" (v->counter), "=qm" (c)
12723 : "er" (i), "m" (v->counter) : "memory");
12724 return c;
12725@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12726 */
12727 static inline long atomic64_add_return(long i, atomic64_t *v)
12728 {
12729+ return i + xadd_check_overflow(&v->counter, i);
12730+}
12731+
12732+/**
12733+ * atomic64_add_return_unchecked - add and return
12734+ * @i: integer value to add
12735+ * @v: pointer to type atomic64_unchecked_t
12736+ *
12737+ * Atomically adds @i to @v and returns @i + @v
12738+ */
12739+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12740+{
12741 return i + xadd(&v->counter, i);
12742 }
12743
12744@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12745 }
12746
12747 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12748+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12749+{
12750+ return atomic64_add_return_unchecked(1, v);
12751+}
12752 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12753
12754 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12755@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12756 return cmpxchg(&v->counter, old, new);
12757 }
12758
12759+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12760+{
12761+ return cmpxchg(&v->counter, old, new);
12762+}
12763+
12764 static inline long atomic64_xchg(atomic64_t *v, long new)
12765 {
12766 return xchg(&v->counter, new);
12767@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12768 */
12769 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12770 {
12771- long c, old;
12772+ long c, old, new;
12773 c = atomic64_read(v);
12774 for (;;) {
12775- if (unlikely(c == (u)))
12776+ if (unlikely(c == u))
12777 break;
12778- old = atomic64_cmpxchg((v), c, c + (a));
12779+
12780+ asm volatile("add %2,%0\n"
12781+
12782+#ifdef CONFIG_PAX_REFCOUNT
12783+ "jno 0f\n"
12784+ "sub %2,%0\n"
12785+ "int $4\n0:\n"
12786+ _ASM_EXTABLE(0b, 0b)
12787+#endif
12788+
12789+ : "=r" (new)
12790+ : "0" (c), "ir" (a));
12791+
12792+ old = atomic64_cmpxchg(v, c, new);
12793 if (likely(old == c))
12794 break;
12795 c = old;
12796 }
12797- return c != (u);
12798+ return c != u;
12799 }
12800
12801 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12802diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12803index 6dfd019..28e188d 100644
12804--- a/arch/x86/include/asm/bitops.h
12805+++ b/arch/x86/include/asm/bitops.h
12806@@ -40,7 +40,7 @@
12807 * a mask operation on a byte.
12808 */
12809 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12810-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12811+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12812 #define CONST_MASK(nr) (1 << ((nr) & 7))
12813
12814 /**
12815@@ -486,7 +486,7 @@ static inline int fls(int x)
12816 * at position 64.
12817 */
12818 #ifdef CONFIG_X86_64
12819-static __always_inline int fls64(__u64 x)
12820+static __always_inline long fls64(__u64 x)
12821 {
12822 int bitpos = -1;
12823 /*
12824diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12825index 4fa687a..60f2d39 100644
12826--- a/arch/x86/include/asm/boot.h
12827+++ b/arch/x86/include/asm/boot.h
12828@@ -6,10 +6,15 @@
12829 #include <uapi/asm/boot.h>
12830
12831 /* Physical address where kernel should be loaded. */
12832-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12833+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12834 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12835 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12836
12837+#ifndef __ASSEMBLY__
12838+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12839+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12840+#endif
12841+
12842 /* Minimum kernel alignment, as a power of two */
12843 #ifdef CONFIG_X86_64
12844 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12845diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12846index 48f99f1..d78ebf9 100644
12847--- a/arch/x86/include/asm/cache.h
12848+++ b/arch/x86/include/asm/cache.h
12849@@ -5,12 +5,13 @@
12850
12851 /* L1 cache line size */
12852 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12853-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12854+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12855
12856 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12857+#define __read_only __attribute__((__section__(".data..read_only")))
12858
12859 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12860-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12861+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12862
12863 #ifdef CONFIG_X86_VSMP
12864 #ifdef CONFIG_SMP
12865diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12866index 9863ee3..4a1f8e1 100644
12867--- a/arch/x86/include/asm/cacheflush.h
12868+++ b/arch/x86/include/asm/cacheflush.h
12869@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12870 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12871
12872 if (pg_flags == _PGMT_DEFAULT)
12873- return -1;
12874+ return ~0UL;
12875 else if (pg_flags == _PGMT_WC)
12876 return _PAGE_CACHE_WC;
12877 else if (pg_flags == _PGMT_UC_MINUS)
12878diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12879index 46fc474..b02b0f9 100644
12880--- a/arch/x86/include/asm/checksum_32.h
12881+++ b/arch/x86/include/asm/checksum_32.h
12882@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12883 int len, __wsum sum,
12884 int *src_err_ptr, int *dst_err_ptr);
12885
12886+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12887+ int len, __wsum sum,
12888+ int *src_err_ptr, int *dst_err_ptr);
12889+
12890+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12891+ int len, __wsum sum,
12892+ int *src_err_ptr, int *dst_err_ptr);
12893+
12894 /*
12895 * Note: when you get a NULL pointer exception here this means someone
12896 * passed in an incorrect kernel address to one of these functions.
12897@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12898 int *err_ptr)
12899 {
12900 might_sleep();
12901- return csum_partial_copy_generic((__force void *)src, dst,
12902+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
12903 len, sum, err_ptr, NULL);
12904 }
12905
12906@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12907 {
12908 might_sleep();
12909 if (access_ok(VERIFY_WRITE, dst, len))
12910- return csum_partial_copy_generic(src, (__force void *)dst,
12911+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12912 len, sum, NULL, err_ptr);
12913
12914 if (len)
12915diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12916index 8d871ea..c1a0dc9 100644
12917--- a/arch/x86/include/asm/cmpxchg.h
12918+++ b/arch/x86/include/asm/cmpxchg.h
12919@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12920 __compiletime_error("Bad argument size for cmpxchg");
12921 extern void __xadd_wrong_size(void)
12922 __compiletime_error("Bad argument size for xadd");
12923+extern void __xadd_check_overflow_wrong_size(void)
12924+ __compiletime_error("Bad argument size for xadd_check_overflow");
12925 extern void __add_wrong_size(void)
12926 __compiletime_error("Bad argument size for add");
12927+extern void __add_check_overflow_wrong_size(void)
12928+ __compiletime_error("Bad argument size for add_check_overflow");
12929
12930 /*
12931 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12932@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12933 __ret; \
12934 })
12935
12936+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12937+ ({ \
12938+ __typeof__ (*(ptr)) __ret = (arg); \
12939+ switch (sizeof(*(ptr))) { \
12940+ case __X86_CASE_L: \
12941+ asm volatile (lock #op "l %0, %1\n" \
12942+ "jno 0f\n" \
12943+ "mov %0,%1\n" \
12944+ "int $4\n0:\n" \
12945+ _ASM_EXTABLE(0b, 0b) \
12946+ : "+r" (__ret), "+m" (*(ptr)) \
12947+ : : "memory", "cc"); \
12948+ break; \
12949+ case __X86_CASE_Q: \
12950+ asm volatile (lock #op "q %q0, %1\n" \
12951+ "jno 0f\n" \
12952+ "mov %0,%1\n" \
12953+ "int $4\n0:\n" \
12954+ _ASM_EXTABLE(0b, 0b) \
12955+ : "+r" (__ret), "+m" (*(ptr)) \
12956+ : : "memory", "cc"); \
12957+ break; \
12958+ default: \
12959+ __ ## op ## _check_overflow_wrong_size(); \
12960+ } \
12961+ __ret; \
12962+ })
12963+
12964 /*
12965 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12966 * Since this is generally used to protect other memory information, we
12967@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12968 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12969 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12970
12971+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12972+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12973+
12974 #define __add(ptr, inc, lock) \
12975 ({ \
12976 __typeof__ (*(ptr)) __ret = (inc); \
12977diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12978index 2d9075e..b75a844 100644
12979--- a/arch/x86/include/asm/cpufeature.h
12980+++ b/arch/x86/include/asm/cpufeature.h
12981@@ -206,7 +206,7 @@
12982 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12983 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12984 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12985-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12986+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12987 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12988 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12989 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12990@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12991 ".section .discard,\"aw\",@progbits\n"
12992 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12993 ".previous\n"
12994- ".section .altinstr_replacement,\"ax\"\n"
12995+ ".section .altinstr_replacement,\"a\"\n"
12996 "3: movb $1,%0\n"
12997 "4:\n"
12998 ".previous\n"
12999diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13000index 8bf1c06..b6ae785 100644
13001--- a/arch/x86/include/asm/desc.h
13002+++ b/arch/x86/include/asm/desc.h
13003@@ -4,6 +4,7 @@
13004 #include <asm/desc_defs.h>
13005 #include <asm/ldt.h>
13006 #include <asm/mmu.h>
13007+#include <asm/pgtable.h>
13008
13009 #include <linux/smp.h>
13010 #include <linux/percpu.h>
13011@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13012
13013 desc->type = (info->read_exec_only ^ 1) << 1;
13014 desc->type |= info->contents << 2;
13015+ desc->type |= info->seg_not_present ^ 1;
13016
13017 desc->s = 1;
13018 desc->dpl = 0x3;
13019@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13020 }
13021
13022 extern struct desc_ptr idt_descr;
13023-extern gate_desc idt_table[];
13024 extern struct desc_ptr nmi_idt_descr;
13025-extern gate_desc nmi_idt_table[];
13026-
13027-struct gdt_page {
13028- struct desc_struct gdt[GDT_ENTRIES];
13029-} __attribute__((aligned(PAGE_SIZE)));
13030-
13031-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13032+extern gate_desc idt_table[256];
13033+extern gate_desc nmi_idt_table[256];
13034
13035+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13036 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13037 {
13038- return per_cpu(gdt_page, cpu).gdt;
13039+ return cpu_gdt_table[cpu];
13040 }
13041
13042 #ifdef CONFIG_X86_64
13043@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13044 unsigned long base, unsigned dpl, unsigned flags,
13045 unsigned short seg)
13046 {
13047- gate->a = (seg << 16) | (base & 0xffff);
13048- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13049+ gate->gate.offset_low = base;
13050+ gate->gate.seg = seg;
13051+ gate->gate.reserved = 0;
13052+ gate->gate.type = type;
13053+ gate->gate.s = 0;
13054+ gate->gate.dpl = dpl;
13055+ gate->gate.p = 1;
13056+ gate->gate.offset_high = base >> 16;
13057 }
13058
13059 #endif
13060@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13061
13062 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13063 {
13064+ pax_open_kernel();
13065 memcpy(&idt[entry], gate, sizeof(*gate));
13066+ pax_close_kernel();
13067 }
13068
13069 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13070 {
13071+ pax_open_kernel();
13072 memcpy(&ldt[entry], desc, 8);
13073+ pax_close_kernel();
13074 }
13075
13076 static inline void
13077@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13078 default: size = sizeof(*gdt); break;
13079 }
13080
13081+ pax_open_kernel();
13082 memcpy(&gdt[entry], desc, size);
13083+ pax_close_kernel();
13084 }
13085
13086 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13087@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13088
13089 static inline void native_load_tr_desc(void)
13090 {
13091+ pax_open_kernel();
13092 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13093+ pax_close_kernel();
13094 }
13095
13096 static inline void native_load_gdt(const struct desc_ptr *dtr)
13097@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13098 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13099 unsigned int i;
13100
13101+ pax_open_kernel();
13102 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13103 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13104+ pax_close_kernel();
13105 }
13106
13107 #define _LDT_empty(info) \
13108@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13109 preempt_enable();
13110 }
13111
13112-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13113+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13114 {
13115 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13116 }
13117@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13118 }
13119
13120 #ifdef CONFIG_X86_64
13121-static inline void set_nmi_gate(int gate, void *addr)
13122+static inline void set_nmi_gate(int gate, const void *addr)
13123 {
13124 gate_desc s;
13125
13126@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13127 }
13128 #endif
13129
13130-static inline void _set_gate(int gate, unsigned type, void *addr,
13131+static inline void _set_gate(int gate, unsigned type, const void *addr,
13132 unsigned dpl, unsigned ist, unsigned seg)
13133 {
13134 gate_desc s;
13135@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13136 * Pentium F0 0F bugfix can have resulted in the mapped
13137 * IDT being write-protected.
13138 */
13139-static inline void set_intr_gate(unsigned int n, void *addr)
13140+static inline void set_intr_gate(unsigned int n, const void *addr)
13141 {
13142 BUG_ON((unsigned)n > 0xFF);
13143 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13144@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13145 /*
13146 * This routine sets up an interrupt gate at directory privilege level 3.
13147 */
13148-static inline void set_system_intr_gate(unsigned int n, void *addr)
13149+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13150 {
13151 BUG_ON((unsigned)n > 0xFF);
13152 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13153 }
13154
13155-static inline void set_system_trap_gate(unsigned int n, void *addr)
13156+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13157 {
13158 BUG_ON((unsigned)n > 0xFF);
13159 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13160 }
13161
13162-static inline void set_trap_gate(unsigned int n, void *addr)
13163+static inline void set_trap_gate(unsigned int n, const void *addr)
13164 {
13165 BUG_ON((unsigned)n > 0xFF);
13166 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13167@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13168 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13169 {
13170 BUG_ON((unsigned)n > 0xFF);
13171- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13172+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13173 }
13174
13175-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13176+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13177 {
13178 BUG_ON((unsigned)n > 0xFF);
13179 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13180 }
13181
13182-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13183+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13184 {
13185 BUG_ON((unsigned)n > 0xFF);
13186 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13187 }
13188
13189+#ifdef CONFIG_X86_32
13190+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13191+{
13192+ struct desc_struct d;
13193+
13194+ if (likely(limit))
13195+ limit = (limit - 1UL) >> PAGE_SHIFT;
13196+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13197+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13198+}
13199+#endif
13200+
13201 #endif /* _ASM_X86_DESC_H */
13202diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13203index 278441f..b95a174 100644
13204--- a/arch/x86/include/asm/desc_defs.h
13205+++ b/arch/x86/include/asm/desc_defs.h
13206@@ -31,6 +31,12 @@ struct desc_struct {
13207 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13208 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13209 };
13210+ struct {
13211+ u16 offset_low;
13212+ u16 seg;
13213+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13214+ unsigned offset_high: 16;
13215+ } gate;
13216 };
13217 } __attribute__((packed));
13218
13219diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13220index ced283a..ffe04cc 100644
13221--- a/arch/x86/include/asm/div64.h
13222+++ b/arch/x86/include/asm/div64.h
13223@@ -39,7 +39,7 @@
13224 __mod; \
13225 })
13226
13227-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13228+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13229 {
13230 union {
13231 u64 v64;
13232diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13233index 9c999c1..3860cb8 100644
13234--- a/arch/x86/include/asm/elf.h
13235+++ b/arch/x86/include/asm/elf.h
13236@@ -243,7 +243,25 @@ extern int force_personality32;
13237 the loader. We need to make sure that it is out of the way of the program
13238 that it will "exec", and that there is sufficient room for the brk. */
13239
13240+#ifdef CONFIG_PAX_SEGMEXEC
13241+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13242+#else
13243 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13244+#endif
13245+
13246+#ifdef CONFIG_PAX_ASLR
13247+#ifdef CONFIG_X86_32
13248+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13249+
13250+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13251+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13252+#else
13253+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13254+
13255+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13256+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13257+#endif
13258+#endif
13259
13260 /* This yields a mask that user programs can use to figure out what
13261 instruction set this CPU supports. This could be done in user space,
13262@@ -296,16 +314,12 @@ do { \
13263
13264 #define ARCH_DLINFO \
13265 do { \
13266- if (vdso_enabled) \
13267- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13268- (unsigned long)current->mm->context.vdso); \
13269+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13270 } while (0)
13271
13272 #define ARCH_DLINFO_X32 \
13273 do { \
13274- if (vdso_enabled) \
13275- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13276- (unsigned long)current->mm->context.vdso); \
13277+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13278 } while (0)
13279
13280 #define AT_SYSINFO 32
13281@@ -320,7 +334,7 @@ else \
13282
13283 #endif /* !CONFIG_X86_32 */
13284
13285-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13286+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13287
13288 #define VDSO_ENTRY \
13289 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13290@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13291 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13292 #define compat_arch_setup_additional_pages syscall32_setup_pages
13293
13294-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13295-#define arch_randomize_brk arch_randomize_brk
13296-
13297 /*
13298 * True on X86_32 or when emulating IA32 on X86_64
13299 */
13300diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13301index 75ce3f4..882e801 100644
13302--- a/arch/x86/include/asm/emergency-restart.h
13303+++ b/arch/x86/include/asm/emergency-restart.h
13304@@ -13,6 +13,6 @@ enum reboot_type {
13305
13306 extern enum reboot_type reboot_type;
13307
13308-extern void machine_emergency_restart(void);
13309+extern void machine_emergency_restart(void) __noreturn;
13310
13311 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13312diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13313index 41ab26e..a88c9e6 100644
13314--- a/arch/x86/include/asm/fpu-internal.h
13315+++ b/arch/x86/include/asm/fpu-internal.h
13316@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13317 ({ \
13318 int err; \
13319 asm volatile(ASM_STAC "\n" \
13320- "1:" #insn "\n\t" \
13321+ "1:" \
13322+ __copyuser_seg \
13323+ #insn "\n\t" \
13324 "2: " ASM_CLAC "\n" \
13325 ".section .fixup,\"ax\"\n" \
13326 "3: movl $-1,%[err]\n" \
13327@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13328 "emms\n\t" /* clear stack tags */
13329 "fildl %P[addr]", /* set F?P to defined value */
13330 X86_FEATURE_FXSAVE_LEAK,
13331- [addr] "m" (tsk->thread.fpu.has_fpu));
13332+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13333
13334 return fpu_restore_checking(&tsk->thread.fpu);
13335 }
13336diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13337index be27ba1..8f13ff9 100644
13338--- a/arch/x86/include/asm/futex.h
13339+++ b/arch/x86/include/asm/futex.h
13340@@ -12,6 +12,7 @@
13341 #include <asm/smap.h>
13342
13343 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13344+ typecheck(u32 __user *, uaddr); \
13345 asm volatile("\t" ASM_STAC "\n" \
13346 "1:\t" insn "\n" \
13347 "2:\t" ASM_CLAC "\n" \
13348@@ -20,15 +21,16 @@
13349 "\tjmp\t2b\n" \
13350 "\t.previous\n" \
13351 _ASM_EXTABLE(1b, 3b) \
13352- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13353+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13354 : "i" (-EFAULT), "0" (oparg), "1" (0))
13355
13356 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13357+ typecheck(u32 __user *, uaddr); \
13358 asm volatile("\t" ASM_STAC "\n" \
13359 "1:\tmovl %2, %0\n" \
13360 "\tmovl\t%0, %3\n" \
13361 "\t" insn "\n" \
13362- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13363+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13364 "\tjnz\t1b\n" \
13365 "3:\t" ASM_CLAC "\n" \
13366 "\t.section .fixup,\"ax\"\n" \
13367@@ -38,7 +40,7 @@
13368 _ASM_EXTABLE(1b, 4b) \
13369 _ASM_EXTABLE(2b, 4b) \
13370 : "=&a" (oldval), "=&r" (ret), \
13371- "+m" (*uaddr), "=&r" (tem) \
13372+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13373 : "r" (oparg), "i" (-EFAULT), "1" (0))
13374
13375 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13376@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13377
13378 switch (op) {
13379 case FUTEX_OP_SET:
13380- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13381+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13382 break;
13383 case FUTEX_OP_ADD:
13384- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13385+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13386 uaddr, oparg);
13387 break;
13388 case FUTEX_OP_OR:
13389@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13390 return -EFAULT;
13391
13392 asm volatile("\t" ASM_STAC "\n"
13393- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13394+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13395 "2:\t" ASM_CLAC "\n"
13396 "\t.section .fixup, \"ax\"\n"
13397 "3:\tmov %3, %0\n"
13398 "\tjmp 2b\n"
13399 "\t.previous\n"
13400 _ASM_EXTABLE(1b, 3b)
13401- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13402+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13403 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13404 : "memory"
13405 );
13406diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13407index eb92a6e..b98b2f4 100644
13408--- a/arch/x86/include/asm/hw_irq.h
13409+++ b/arch/x86/include/asm/hw_irq.h
13410@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13411 extern void enable_IO_APIC(void);
13412
13413 /* Statistics */
13414-extern atomic_t irq_err_count;
13415-extern atomic_t irq_mis_count;
13416+extern atomic_unchecked_t irq_err_count;
13417+extern atomic_unchecked_t irq_mis_count;
13418
13419 /* EISA */
13420 extern void eisa_set_level_irq(unsigned int irq);
13421diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13422index a203659..9889f1c 100644
13423--- a/arch/x86/include/asm/i8259.h
13424+++ b/arch/x86/include/asm/i8259.h
13425@@ -62,7 +62,7 @@ struct legacy_pic {
13426 void (*init)(int auto_eoi);
13427 int (*irq_pending)(unsigned int irq);
13428 void (*make_irq)(unsigned int irq);
13429-};
13430+} __do_const;
13431
13432 extern struct legacy_pic *legacy_pic;
13433 extern struct legacy_pic null_legacy_pic;
13434diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13435index d8e8eef..1765f78 100644
13436--- a/arch/x86/include/asm/io.h
13437+++ b/arch/x86/include/asm/io.h
13438@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13439 "m" (*(volatile type __force *)addr) barrier); }
13440
13441 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13442-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13443-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13444+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13445+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13446
13447 build_mmio_read(__readb, "b", unsigned char, "=q", )
13448-build_mmio_read(__readw, "w", unsigned short, "=r", )
13449-build_mmio_read(__readl, "l", unsigned int, "=r", )
13450+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13451+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13452
13453 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13454 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13455@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13456 return ioremap_nocache(offset, size);
13457 }
13458
13459-extern void iounmap(volatile void __iomem *addr);
13460+extern void iounmap(const volatile void __iomem *addr);
13461
13462 extern void set_iounmap_nonlazy(void);
13463
13464@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13465
13466 #include <linux/vmalloc.h>
13467
13468+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13469+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13470+{
13471+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13472+}
13473+
13474+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13475+{
13476+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13477+}
13478+
13479 /*
13480 * Convert a virtual cached pointer to an uncached pointer
13481 */
13482diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13483index bba3cf8..06bc8da 100644
13484--- a/arch/x86/include/asm/irqflags.h
13485+++ b/arch/x86/include/asm/irqflags.h
13486@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13487 sti; \
13488 sysexit
13489
13490+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13491+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13492+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13493+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13494+
13495 #else
13496 #define INTERRUPT_RETURN iret
13497 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13498diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13499index d3ddd17..c9fb0cc 100644
13500--- a/arch/x86/include/asm/kprobes.h
13501+++ b/arch/x86/include/asm/kprobes.h
13502@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13503 #define RELATIVEJUMP_SIZE 5
13504 #define RELATIVECALL_OPCODE 0xe8
13505 #define RELATIVE_ADDR_SIZE 4
13506-#define MAX_STACK_SIZE 64
13507-#define MIN_STACK_SIZE(ADDR) \
13508- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13509- THREAD_SIZE - (unsigned long)(ADDR))) \
13510- ? (MAX_STACK_SIZE) \
13511- : (((unsigned long)current_thread_info()) + \
13512- THREAD_SIZE - (unsigned long)(ADDR)))
13513+#define MAX_STACK_SIZE 64UL
13514+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13515
13516 #define flush_insn_slot(p) do { } while (0)
13517
13518diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13519index 2d89e39..baee879 100644
13520--- a/arch/x86/include/asm/local.h
13521+++ b/arch/x86/include/asm/local.h
13522@@ -10,33 +10,97 @@ typedef struct {
13523 atomic_long_t a;
13524 } local_t;
13525
13526+typedef struct {
13527+ atomic_long_unchecked_t a;
13528+} local_unchecked_t;
13529+
13530 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13531
13532 #define local_read(l) atomic_long_read(&(l)->a)
13533+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13534 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13535+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13536
13537 static inline void local_inc(local_t *l)
13538 {
13539- asm volatile(_ASM_INC "%0"
13540+ asm volatile(_ASM_INC "%0\n"
13541+
13542+#ifdef CONFIG_PAX_REFCOUNT
13543+ "jno 0f\n"
13544+ _ASM_DEC "%0\n"
13545+ "int $4\n0:\n"
13546+ _ASM_EXTABLE(0b, 0b)
13547+#endif
13548+
13549+ : "+m" (l->a.counter));
13550+}
13551+
13552+static inline void local_inc_unchecked(local_unchecked_t *l)
13553+{
13554+ asm volatile(_ASM_INC "%0\n"
13555 : "+m" (l->a.counter));
13556 }
13557
13558 static inline void local_dec(local_t *l)
13559 {
13560- asm volatile(_ASM_DEC "%0"
13561+ asm volatile(_ASM_DEC "%0\n"
13562+
13563+#ifdef CONFIG_PAX_REFCOUNT
13564+ "jno 0f\n"
13565+ _ASM_INC "%0\n"
13566+ "int $4\n0:\n"
13567+ _ASM_EXTABLE(0b, 0b)
13568+#endif
13569+
13570+ : "+m" (l->a.counter));
13571+}
13572+
13573+static inline void local_dec_unchecked(local_unchecked_t *l)
13574+{
13575+ asm volatile(_ASM_DEC "%0\n"
13576 : "+m" (l->a.counter));
13577 }
13578
13579 static inline void local_add(long i, local_t *l)
13580 {
13581- asm volatile(_ASM_ADD "%1,%0"
13582+ asm volatile(_ASM_ADD "%1,%0\n"
13583+
13584+#ifdef CONFIG_PAX_REFCOUNT
13585+ "jno 0f\n"
13586+ _ASM_SUB "%1,%0\n"
13587+ "int $4\n0:\n"
13588+ _ASM_EXTABLE(0b, 0b)
13589+#endif
13590+
13591+ : "+m" (l->a.counter)
13592+ : "ir" (i));
13593+}
13594+
13595+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13596+{
13597+ asm volatile(_ASM_ADD "%1,%0\n"
13598 : "+m" (l->a.counter)
13599 : "ir" (i));
13600 }
13601
13602 static inline void local_sub(long i, local_t *l)
13603 {
13604- asm volatile(_ASM_SUB "%1,%0"
13605+ asm volatile(_ASM_SUB "%1,%0\n"
13606+
13607+#ifdef CONFIG_PAX_REFCOUNT
13608+ "jno 0f\n"
13609+ _ASM_ADD "%1,%0\n"
13610+ "int $4\n0:\n"
13611+ _ASM_EXTABLE(0b, 0b)
13612+#endif
13613+
13614+ : "+m" (l->a.counter)
13615+ : "ir" (i));
13616+}
13617+
13618+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13619+{
13620+ asm volatile(_ASM_SUB "%1,%0\n"
13621 : "+m" (l->a.counter)
13622 : "ir" (i));
13623 }
13624@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13625 {
13626 unsigned char c;
13627
13628- asm volatile(_ASM_SUB "%2,%0; sete %1"
13629+ asm volatile(_ASM_SUB "%2,%0\n"
13630+
13631+#ifdef CONFIG_PAX_REFCOUNT
13632+ "jno 0f\n"
13633+ _ASM_ADD "%2,%0\n"
13634+ "int $4\n0:\n"
13635+ _ASM_EXTABLE(0b, 0b)
13636+#endif
13637+
13638+ "sete %1\n"
13639 : "+m" (l->a.counter), "=qm" (c)
13640 : "ir" (i) : "memory");
13641 return c;
13642@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13643 {
13644 unsigned char c;
13645
13646- asm volatile(_ASM_DEC "%0; sete %1"
13647+ asm volatile(_ASM_DEC "%0\n"
13648+
13649+#ifdef CONFIG_PAX_REFCOUNT
13650+ "jno 0f\n"
13651+ _ASM_INC "%0\n"
13652+ "int $4\n0:\n"
13653+ _ASM_EXTABLE(0b, 0b)
13654+#endif
13655+
13656+ "sete %1\n"
13657 : "+m" (l->a.counter), "=qm" (c)
13658 : : "memory");
13659 return c != 0;
13660@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13661 {
13662 unsigned char c;
13663
13664- asm volatile(_ASM_INC "%0; sete %1"
13665+ asm volatile(_ASM_INC "%0\n"
13666+
13667+#ifdef CONFIG_PAX_REFCOUNT
13668+ "jno 0f\n"
13669+ _ASM_DEC "%0\n"
13670+ "int $4\n0:\n"
13671+ _ASM_EXTABLE(0b, 0b)
13672+#endif
13673+
13674+ "sete %1\n"
13675 : "+m" (l->a.counter), "=qm" (c)
13676 : : "memory");
13677 return c != 0;
13678@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13679 {
13680 unsigned char c;
13681
13682- asm volatile(_ASM_ADD "%2,%0; sets %1"
13683+ asm volatile(_ASM_ADD "%2,%0\n"
13684+
13685+#ifdef CONFIG_PAX_REFCOUNT
13686+ "jno 0f\n"
13687+ _ASM_SUB "%2,%0\n"
13688+ "int $4\n0:\n"
13689+ _ASM_EXTABLE(0b, 0b)
13690+#endif
13691+
13692+ "sets %1\n"
13693 : "+m" (l->a.counter), "=qm" (c)
13694 : "ir" (i) : "memory");
13695 return c;
13696@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13697 static inline long local_add_return(long i, local_t *l)
13698 {
13699 long __i = i;
13700+ asm volatile(_ASM_XADD "%0, %1\n"
13701+
13702+#ifdef CONFIG_PAX_REFCOUNT
13703+ "jno 0f\n"
13704+ _ASM_MOV "%0,%1\n"
13705+ "int $4\n0:\n"
13706+ _ASM_EXTABLE(0b, 0b)
13707+#endif
13708+
13709+ : "+r" (i), "+m" (l->a.counter)
13710+ : : "memory");
13711+ return i + __i;
13712+}
13713+
13714+/**
13715+ * local_add_return_unchecked - add and return
13716+ * @i: integer value to add
13717+ * @l: pointer to type local_unchecked_t
13718+ *
13719+ * Atomically adds @i to @l and returns @i + @l
13720+ */
13721+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13722+{
13723+ long __i = i;
13724 asm volatile(_ASM_XADD "%0, %1;"
13725 : "+r" (i), "+m" (l->a.counter)
13726 : : "memory");
13727@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13728
13729 #define local_cmpxchg(l, o, n) \
13730 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13731+#define local_cmpxchg_unchecked(l, o, n) \
13732+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13733 /* Always has a lock prefix */
13734 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13735
13736diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13737new file mode 100644
13738index 0000000..2bfd3ba
13739--- /dev/null
13740+++ b/arch/x86/include/asm/mman.h
13741@@ -0,0 +1,15 @@
13742+#ifndef _X86_MMAN_H
13743+#define _X86_MMAN_H
13744+
13745+#include <uapi/asm/mman.h>
13746+
13747+#ifdef __KERNEL__
13748+#ifndef __ASSEMBLY__
13749+#ifdef CONFIG_X86_32
13750+#define arch_mmap_check i386_mmap_check
13751+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13752+#endif
13753+#endif
13754+#endif
13755+
13756+#endif /* X86_MMAN_H */
13757diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13758index 5f55e69..e20bfb1 100644
13759--- a/arch/x86/include/asm/mmu.h
13760+++ b/arch/x86/include/asm/mmu.h
13761@@ -9,7 +9,7 @@
13762 * we put the segment information here.
13763 */
13764 typedef struct {
13765- void *ldt;
13766+ struct desc_struct *ldt;
13767 int size;
13768
13769 #ifdef CONFIG_X86_64
13770@@ -18,7 +18,19 @@ typedef struct {
13771 #endif
13772
13773 struct mutex lock;
13774- void *vdso;
13775+ unsigned long vdso;
13776+
13777+#ifdef CONFIG_X86_32
13778+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13779+ unsigned long user_cs_base;
13780+ unsigned long user_cs_limit;
13781+
13782+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13783+ cpumask_t cpu_user_cs_mask;
13784+#endif
13785+
13786+#endif
13787+#endif
13788 } mm_context_t;
13789
13790 #ifdef CONFIG_SMP
13791diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13792index cdbf367..adb37ac 100644
13793--- a/arch/x86/include/asm/mmu_context.h
13794+++ b/arch/x86/include/asm/mmu_context.h
13795@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13796
13797 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13798 {
13799+
13800+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13801+ unsigned int i;
13802+ pgd_t *pgd;
13803+
13804+ pax_open_kernel();
13805+ pgd = get_cpu_pgd(smp_processor_id());
13806+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13807+ set_pgd_batched(pgd+i, native_make_pgd(0));
13808+ pax_close_kernel();
13809+#endif
13810+
13811 #ifdef CONFIG_SMP
13812 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13813 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13814@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13815 struct task_struct *tsk)
13816 {
13817 unsigned cpu = smp_processor_id();
13818+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13819+ int tlbstate = TLBSTATE_OK;
13820+#endif
13821
13822 if (likely(prev != next)) {
13823 #ifdef CONFIG_SMP
13824+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13825+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13826+#endif
13827 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13828 this_cpu_write(cpu_tlbstate.active_mm, next);
13829 #endif
13830 cpumask_set_cpu(cpu, mm_cpumask(next));
13831
13832 /* Re-load page tables */
13833+#ifdef CONFIG_PAX_PER_CPU_PGD
13834+ pax_open_kernel();
13835+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13836+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13837+ pax_close_kernel();
13838+ load_cr3(get_cpu_pgd(cpu));
13839+#else
13840 load_cr3(next->pgd);
13841+#endif
13842
13843 /* stop flush ipis for the previous mm */
13844 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13845@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13846 */
13847 if (unlikely(prev->context.ldt != next->context.ldt))
13848 load_LDT_nolock(&next->context);
13849- }
13850+
13851+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13852+ if (!(__supported_pte_mask & _PAGE_NX)) {
13853+ smp_mb__before_clear_bit();
13854+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13855+ smp_mb__after_clear_bit();
13856+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13857+ }
13858+#endif
13859+
13860+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13861+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13862+ prev->context.user_cs_limit != next->context.user_cs_limit))
13863+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13864 #ifdef CONFIG_SMP
13865+ else if (unlikely(tlbstate != TLBSTATE_OK))
13866+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13867+#endif
13868+#endif
13869+
13870+ }
13871 else {
13872+
13873+#ifdef CONFIG_PAX_PER_CPU_PGD
13874+ pax_open_kernel();
13875+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13876+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13877+ pax_close_kernel();
13878+ load_cr3(get_cpu_pgd(cpu));
13879+#endif
13880+
13881+#ifdef CONFIG_SMP
13882 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13883 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13884
13885@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13886 * tlb flush IPI delivery. We must reload CR3
13887 * to make sure to use no freed page tables.
13888 */
13889+
13890+#ifndef CONFIG_PAX_PER_CPU_PGD
13891 load_cr3(next->pgd);
13892+#endif
13893+
13894 load_LDT_nolock(&next->context);
13895+
13896+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13897+ if (!(__supported_pte_mask & _PAGE_NX))
13898+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13899+#endif
13900+
13901+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13902+#ifdef CONFIG_PAX_PAGEEXEC
13903+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13904+#endif
13905+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13906+#endif
13907+
13908 }
13909+#endif
13910 }
13911-#endif
13912 }
13913
13914 #define activate_mm(prev, next) \
13915diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13916index e3b7819..b257c64 100644
13917--- a/arch/x86/include/asm/module.h
13918+++ b/arch/x86/include/asm/module.h
13919@@ -5,6 +5,7 @@
13920
13921 #ifdef CONFIG_X86_64
13922 /* X86_64 does not define MODULE_PROC_FAMILY */
13923+#define MODULE_PROC_FAMILY ""
13924 #elif defined CONFIG_M486
13925 #define MODULE_PROC_FAMILY "486 "
13926 #elif defined CONFIG_M586
13927@@ -57,8 +58,20 @@
13928 #error unknown processor family
13929 #endif
13930
13931-#ifdef CONFIG_X86_32
13932-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13933+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13934+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13935+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13936+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13937+#else
13938+#define MODULE_PAX_KERNEXEC ""
13939 #endif
13940
13941+#ifdef CONFIG_PAX_MEMORY_UDEREF
13942+#define MODULE_PAX_UDEREF "UDEREF "
13943+#else
13944+#define MODULE_PAX_UDEREF ""
13945+#endif
13946+
13947+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13948+
13949 #endif /* _ASM_X86_MODULE_H */
13950diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
13951index c0fa356..07a498a 100644
13952--- a/arch/x86/include/asm/nmi.h
13953+++ b/arch/x86/include/asm/nmi.h
13954@@ -42,11 +42,11 @@ struct nmiaction {
13955 nmi_handler_t handler;
13956 unsigned long flags;
13957 const char *name;
13958-};
13959+} __do_const;
13960
13961 #define register_nmi_handler(t, fn, fg, n, init...) \
13962 ({ \
13963- static struct nmiaction init fn##_na = { \
13964+ static const struct nmiaction init fn##_na = { \
13965 .handler = (fn), \
13966 .name = (n), \
13967 .flags = (fg), \
13968@@ -54,7 +54,7 @@ struct nmiaction {
13969 __register_nmi_handler((t), &fn##_na); \
13970 })
13971
13972-int __register_nmi_handler(unsigned int, struct nmiaction *);
13973+int __register_nmi_handler(unsigned int, const struct nmiaction *);
13974
13975 void unregister_nmi_handler(unsigned int, const char *);
13976
13977diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13978index 320f7bb..e89f8f8 100644
13979--- a/arch/x86/include/asm/page_64_types.h
13980+++ b/arch/x86/include/asm/page_64_types.h
13981@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13982
13983 /* duplicated to the one in bootmem.h */
13984 extern unsigned long max_pfn;
13985-extern unsigned long phys_base;
13986+extern const unsigned long phys_base;
13987
13988 extern unsigned long __phys_addr(unsigned long);
13989 #define __phys_reloc_hide(x) (x)
13990diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13991index 5edd174..c395822 100644
13992--- a/arch/x86/include/asm/paravirt.h
13993+++ b/arch/x86/include/asm/paravirt.h
13994@@ -564,7 +564,7 @@ static inline pmd_t __pmd(pmdval_t val)
13995 return (pmd_t) { ret };
13996 }
13997
13998-static inline pmdval_t pmd_val(pmd_t pmd)
13999+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14000 {
14001 pmdval_t ret;
14002
14003@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14004 val);
14005 }
14006
14007+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14008+{
14009+ pgdval_t val = native_pgd_val(pgd);
14010+
14011+ if (sizeof(pgdval_t) > sizeof(long))
14012+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14013+ val, (u64)val >> 32);
14014+ else
14015+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14016+ val);
14017+}
14018+
14019 static inline void pgd_clear(pgd_t *pgdp)
14020 {
14021 set_pgd(pgdp, __pgd(0));
14022@@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14023 pv_mmu_ops.set_fixmap(idx, phys, flags);
14024 }
14025
14026+#ifdef CONFIG_PAX_KERNEXEC
14027+static inline unsigned long pax_open_kernel(void)
14028+{
14029+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14030+}
14031+
14032+static inline unsigned long pax_close_kernel(void)
14033+{
14034+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14035+}
14036+#else
14037+static inline unsigned long pax_open_kernel(void) { return 0; }
14038+static inline unsigned long pax_close_kernel(void) { return 0; }
14039+#endif
14040+
14041 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14042
14043 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14044@@ -927,7 +954,7 @@ extern void default_banner(void);
14045
14046 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14047 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14048-#define PARA_INDIRECT(addr) *%cs:addr
14049+#define PARA_INDIRECT(addr) *%ss:addr
14050 #endif
14051
14052 #define INTERRUPT_RETURN \
14053@@ -1002,6 +1029,21 @@ extern void default_banner(void);
14054 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14055 CLBR_NONE, \
14056 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14057+
14058+#define GET_CR0_INTO_RDI \
14059+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14060+ mov %rax,%rdi
14061+
14062+#define SET_RDI_INTO_CR0 \
14063+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14064+
14065+#define GET_CR3_INTO_RDI \
14066+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14067+ mov %rax,%rdi
14068+
14069+#define SET_RDI_INTO_CR3 \
14070+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14071+
14072 #endif /* CONFIG_X86_32 */
14073
14074 #endif /* __ASSEMBLY__ */
14075diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14076index 142236e..5446ffbc 100644
14077--- a/arch/x86/include/asm/paravirt_types.h
14078+++ b/arch/x86/include/asm/paravirt_types.h
14079@@ -84,7 +84,7 @@ struct pv_init_ops {
14080 */
14081 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14082 unsigned long addr, unsigned len);
14083-};
14084+} __no_const;
14085
14086
14087 struct pv_lazy_ops {
14088@@ -97,7 +97,7 @@ struct pv_time_ops {
14089 unsigned long long (*sched_clock)(void);
14090 unsigned long long (*steal_clock)(int cpu);
14091 unsigned long (*get_tsc_khz)(void);
14092-};
14093+} __no_const;
14094
14095 struct pv_cpu_ops {
14096 /* hooks for various privileged instructions */
14097@@ -191,7 +191,7 @@ struct pv_cpu_ops {
14098
14099 void (*start_context_switch)(struct task_struct *prev);
14100 void (*end_context_switch)(struct task_struct *next);
14101-};
14102+} __no_const;
14103
14104 struct pv_irq_ops {
14105 /*
14106@@ -222,7 +222,7 @@ struct pv_apic_ops {
14107 unsigned long start_eip,
14108 unsigned long start_esp);
14109 #endif
14110-};
14111+} __no_const;
14112
14113 struct pv_mmu_ops {
14114 unsigned long (*read_cr2)(void);
14115@@ -312,6 +312,7 @@ struct pv_mmu_ops {
14116 struct paravirt_callee_save make_pud;
14117
14118 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14119+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14120 #endif /* PAGETABLE_LEVELS == 4 */
14121 #endif /* PAGETABLE_LEVELS >= 3 */
14122
14123@@ -323,6 +324,12 @@ struct pv_mmu_ops {
14124 an mfn. We can tell which is which from the index. */
14125 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14126 phys_addr_t phys, pgprot_t flags);
14127+
14128+#ifdef CONFIG_PAX_KERNEXEC
14129+ unsigned long (*pax_open_kernel)(void);
14130+ unsigned long (*pax_close_kernel)(void);
14131+#endif
14132+
14133 };
14134
14135 struct arch_spinlock;
14136@@ -333,7 +340,7 @@ struct pv_lock_ops {
14137 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14138 int (*spin_trylock)(struct arch_spinlock *lock);
14139 void (*spin_unlock)(struct arch_spinlock *lock);
14140-};
14141+} __no_const;
14142
14143 /* This contains all the paravirt structures: we get a convenient
14144 * number for each function using the offset which we use to indicate
14145diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14146index b4389a4..7024269 100644
14147--- a/arch/x86/include/asm/pgalloc.h
14148+++ b/arch/x86/include/asm/pgalloc.h
14149@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14150 pmd_t *pmd, pte_t *pte)
14151 {
14152 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14153+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14154+}
14155+
14156+static inline void pmd_populate_user(struct mm_struct *mm,
14157+ pmd_t *pmd, pte_t *pte)
14158+{
14159+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14160 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14161 }
14162
14163@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14164
14165 #ifdef CONFIG_X86_PAE
14166 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14167+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14168+{
14169+ pud_populate(mm, pudp, pmd);
14170+}
14171 #else /* !CONFIG_X86_PAE */
14172 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14173 {
14174 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14175 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14176 }
14177+
14178+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14179+{
14180+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14181+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14182+}
14183 #endif /* CONFIG_X86_PAE */
14184
14185 #if PAGETABLE_LEVELS > 3
14186@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14187 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14188 }
14189
14190+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14191+{
14192+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14193+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14194+}
14195+
14196 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14197 {
14198 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14199diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14200index f2b489c..4f7e2e5 100644
14201--- a/arch/x86/include/asm/pgtable-2level.h
14202+++ b/arch/x86/include/asm/pgtable-2level.h
14203@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14204
14205 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14206 {
14207+ pax_open_kernel();
14208 *pmdp = pmd;
14209+ pax_close_kernel();
14210 }
14211
14212 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14213diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14214index 4cc9f2b..5fd9226 100644
14215--- a/arch/x86/include/asm/pgtable-3level.h
14216+++ b/arch/x86/include/asm/pgtable-3level.h
14217@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14218
14219 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14220 {
14221+ pax_open_kernel();
14222 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14223+ pax_close_kernel();
14224 }
14225
14226 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14227 {
14228+ pax_open_kernel();
14229 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14230+ pax_close_kernel();
14231 }
14232
14233 /*
14234diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14235index 1c1a955..50f828c 100644
14236--- a/arch/x86/include/asm/pgtable.h
14237+++ b/arch/x86/include/asm/pgtable.h
14238@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14239
14240 #ifndef __PAGETABLE_PUD_FOLDED
14241 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14242+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14243 #define pgd_clear(pgd) native_pgd_clear(pgd)
14244 #endif
14245
14246@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14247
14248 #define arch_end_context_switch(prev) do {} while(0)
14249
14250+#define pax_open_kernel() native_pax_open_kernel()
14251+#define pax_close_kernel() native_pax_close_kernel()
14252 #endif /* CONFIG_PARAVIRT */
14253
14254+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14255+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14256+
14257+#ifdef CONFIG_PAX_KERNEXEC
14258+static inline unsigned long native_pax_open_kernel(void)
14259+{
14260+ unsigned long cr0;
14261+
14262+ preempt_disable();
14263+ barrier();
14264+ cr0 = read_cr0() ^ X86_CR0_WP;
14265+ BUG_ON(cr0 & X86_CR0_WP);
14266+ write_cr0(cr0);
14267+ return cr0 ^ X86_CR0_WP;
14268+}
14269+
14270+static inline unsigned long native_pax_close_kernel(void)
14271+{
14272+ unsigned long cr0;
14273+
14274+ cr0 = read_cr0() ^ X86_CR0_WP;
14275+ BUG_ON(!(cr0 & X86_CR0_WP));
14276+ write_cr0(cr0);
14277+ barrier();
14278+ preempt_enable_no_resched();
14279+ return cr0 ^ X86_CR0_WP;
14280+}
14281+#else
14282+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14283+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14284+#endif
14285+
14286 /*
14287 * The following only work if pte_present() is true.
14288 * Undefined behaviour if not..
14289 */
14290+static inline int pte_user(pte_t pte)
14291+{
14292+ return pte_val(pte) & _PAGE_USER;
14293+}
14294+
14295 static inline int pte_dirty(pte_t pte)
14296 {
14297 return pte_flags(pte) & _PAGE_DIRTY;
14298@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14299 return pte_clear_flags(pte, _PAGE_RW);
14300 }
14301
14302+static inline pte_t pte_mkread(pte_t pte)
14303+{
14304+ return __pte(pte_val(pte) | _PAGE_USER);
14305+}
14306+
14307 static inline pte_t pte_mkexec(pte_t pte)
14308 {
14309- return pte_clear_flags(pte, _PAGE_NX);
14310+#ifdef CONFIG_X86_PAE
14311+ if (__supported_pte_mask & _PAGE_NX)
14312+ return pte_clear_flags(pte, _PAGE_NX);
14313+ else
14314+#endif
14315+ return pte_set_flags(pte, _PAGE_USER);
14316+}
14317+
14318+static inline pte_t pte_exprotect(pte_t pte)
14319+{
14320+#ifdef CONFIG_X86_PAE
14321+ if (__supported_pte_mask & _PAGE_NX)
14322+ return pte_set_flags(pte, _PAGE_NX);
14323+ else
14324+#endif
14325+ return pte_clear_flags(pte, _PAGE_USER);
14326 }
14327
14328 static inline pte_t pte_mkdirty(pte_t pte)
14329@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14330 #endif
14331
14332 #ifndef __ASSEMBLY__
14333+
14334+#ifdef CONFIG_PAX_PER_CPU_PGD
14335+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14336+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14337+{
14338+ return cpu_pgd[cpu];
14339+}
14340+#endif
14341+
14342 #include <linux/mm_types.h>
14343
14344 static inline int pte_none(pte_t pte)
14345@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14346
14347 static inline int pgd_bad(pgd_t pgd)
14348 {
14349- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14350+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14351 }
14352
14353 static inline int pgd_none(pgd_t pgd)
14354@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
14355 * pgd_offset() returns a (pgd_t *)
14356 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14357 */
14358-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14359+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14360+
14361+#ifdef CONFIG_PAX_PER_CPU_PGD
14362+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14363+#endif
14364+
14365 /*
14366 * a shortcut which implies the use of the kernel's pgd, instead
14367 * of a process's
14368@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
14369 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14370 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14371
14372+#ifdef CONFIG_X86_32
14373+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14374+#else
14375+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14376+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14377+
14378+#ifdef CONFIG_PAX_MEMORY_UDEREF
14379+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
14380+#else
14381+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
14382+#endif
14383+
14384+#endif
14385+
14386 #ifndef __ASSEMBLY__
14387
14388 extern int direct_gbpages;
14389@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14390 * dst and src can be on the same page, but the range must not overlap,
14391 * and must not cross a page boundary.
14392 */
14393-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14394+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14395 {
14396- memcpy(dst, src, count * sizeof(pgd_t));
14397+ pax_open_kernel();
14398+ while (count--)
14399+ *dst++ = *src++;
14400+ pax_close_kernel();
14401 }
14402
14403+#ifdef CONFIG_PAX_PER_CPU_PGD
14404+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14405+#endif
14406+
14407+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14408+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14409+#else
14410+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14411+#endif
14412
14413 #include <asm-generic/pgtable.h>
14414 #endif /* __ASSEMBLY__ */
14415diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14416index 8faa215..a8a17ea 100644
14417--- a/arch/x86/include/asm/pgtable_32.h
14418+++ b/arch/x86/include/asm/pgtable_32.h
14419@@ -25,9 +25,6 @@
14420 struct mm_struct;
14421 struct vm_area_struct;
14422
14423-extern pgd_t swapper_pg_dir[1024];
14424-extern pgd_t initial_page_table[1024];
14425-
14426 static inline void pgtable_cache_init(void) { }
14427 static inline void check_pgt_cache(void) { }
14428 void paging_init(void);
14429@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14430 # include <asm/pgtable-2level.h>
14431 #endif
14432
14433+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14434+extern pgd_t initial_page_table[PTRS_PER_PGD];
14435+#ifdef CONFIG_X86_PAE
14436+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14437+#endif
14438+
14439 #if defined(CONFIG_HIGHPTE)
14440 #define pte_offset_map(dir, address) \
14441 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14442@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14443 /* Clear a kernel PTE and flush it from the TLB */
14444 #define kpte_clear_flush(ptep, vaddr) \
14445 do { \
14446+ pax_open_kernel(); \
14447 pte_clear(&init_mm, (vaddr), (ptep)); \
14448+ pax_close_kernel(); \
14449 __flush_tlb_one((vaddr)); \
14450 } while (0)
14451
14452@@ -75,6 +80,9 @@ do { \
14453
14454 #endif /* !__ASSEMBLY__ */
14455
14456+#define HAVE_ARCH_UNMAPPED_AREA
14457+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14458+
14459 /*
14460 * kern_addr_valid() is (1) for FLATMEM and (0) for
14461 * SPARSEMEM and DISCONTIGMEM
14462diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14463index ed5903b..c7fe163 100644
14464--- a/arch/x86/include/asm/pgtable_32_types.h
14465+++ b/arch/x86/include/asm/pgtable_32_types.h
14466@@ -8,7 +8,7 @@
14467 */
14468 #ifdef CONFIG_X86_PAE
14469 # include <asm/pgtable-3level_types.h>
14470-# define PMD_SIZE (1UL << PMD_SHIFT)
14471+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14472 # define PMD_MASK (~(PMD_SIZE - 1))
14473 #else
14474 # include <asm/pgtable-2level_types.h>
14475@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14476 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14477 #endif
14478
14479+#ifdef CONFIG_PAX_KERNEXEC
14480+#ifndef __ASSEMBLY__
14481+extern unsigned char MODULES_EXEC_VADDR[];
14482+extern unsigned char MODULES_EXEC_END[];
14483+#endif
14484+#include <asm/boot.h>
14485+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14486+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14487+#else
14488+#define ktla_ktva(addr) (addr)
14489+#define ktva_ktla(addr) (addr)
14490+#endif
14491+
14492 #define MODULES_VADDR VMALLOC_START
14493 #define MODULES_END VMALLOC_END
14494 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14495diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14496index 47356f9..deb94a2 100644
14497--- a/arch/x86/include/asm/pgtable_64.h
14498+++ b/arch/x86/include/asm/pgtable_64.h
14499@@ -16,10 +16,14 @@
14500
14501 extern pud_t level3_kernel_pgt[512];
14502 extern pud_t level3_ident_pgt[512];
14503+extern pud_t level3_vmalloc_start_pgt[512];
14504+extern pud_t level3_vmalloc_end_pgt[512];
14505+extern pud_t level3_vmemmap_pgt[512];
14506+extern pud_t level2_vmemmap_pgt[512];
14507 extern pmd_t level2_kernel_pgt[512];
14508 extern pmd_t level2_fixmap_pgt[512];
14509-extern pmd_t level2_ident_pgt[512];
14510-extern pgd_t init_level4_pgt[];
14511+extern pmd_t level2_ident_pgt[512*2];
14512+extern pgd_t init_level4_pgt[512];
14513
14514 #define swapper_pg_dir init_level4_pgt
14515
14516@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14517
14518 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14519 {
14520+ pax_open_kernel();
14521 *pmdp = pmd;
14522+ pax_close_kernel();
14523 }
14524
14525 static inline void native_pmd_clear(pmd_t *pmd)
14526@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14527
14528 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14529 {
14530+ pax_open_kernel();
14531 *pudp = pud;
14532+ pax_close_kernel();
14533 }
14534
14535 static inline void native_pud_clear(pud_t *pud)
14536@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14537
14538 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14539 {
14540+ pax_open_kernel();
14541+ *pgdp = pgd;
14542+ pax_close_kernel();
14543+}
14544+
14545+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14546+{
14547 *pgdp = pgd;
14548 }
14549
14550diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14551index 766ea16..5b96cb3 100644
14552--- a/arch/x86/include/asm/pgtable_64_types.h
14553+++ b/arch/x86/include/asm/pgtable_64_types.h
14554@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14555 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14556 #define MODULES_END _AC(0xffffffffff000000, UL)
14557 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14558+#define MODULES_EXEC_VADDR MODULES_VADDR
14559+#define MODULES_EXEC_END MODULES_END
14560+
14561+#define ktla_ktva(addr) (addr)
14562+#define ktva_ktla(addr) (addr)
14563
14564 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14565diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14566index 3c32db8..1ddccf5 100644
14567--- a/arch/x86/include/asm/pgtable_types.h
14568+++ b/arch/x86/include/asm/pgtable_types.h
14569@@ -16,13 +16,12 @@
14570 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14571 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14572 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14573-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14574+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14575 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14576 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14577 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14578-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14579-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14580-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14581+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14582+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14583 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14584
14585 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14586@@ -40,7 +39,6 @@
14587 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14588 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14589 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14590-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14591 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14592 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14593 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14594@@ -57,8 +55,10 @@
14595
14596 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14597 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14598-#else
14599+#elif defined(CONFIG_KMEMCHECK)
14600 #define _PAGE_NX (_AT(pteval_t, 0))
14601+#else
14602+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14603 #endif
14604
14605 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14606@@ -116,6 +116,9 @@
14607 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14608 _PAGE_ACCESSED)
14609
14610+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14611+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14612+
14613 #define __PAGE_KERNEL_EXEC \
14614 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14615 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14616@@ -126,7 +129,7 @@
14617 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14618 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14619 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14620-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14621+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14622 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14623 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14624 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14625@@ -188,8 +191,8 @@
14626 * bits are combined, this will alow user to access the high address mapped
14627 * VDSO in the presence of CONFIG_COMPAT_VDSO
14628 */
14629-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14630-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14631+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14632+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14633 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14634 #endif
14635
14636@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14637 {
14638 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14639 }
14640+#endif
14641
14642+#if PAGETABLE_LEVELS == 3
14643+#include <asm-generic/pgtable-nopud.h>
14644+#endif
14645+
14646+#if PAGETABLE_LEVELS == 2
14647+#include <asm-generic/pgtable-nopmd.h>
14648+#endif
14649+
14650+#ifndef __ASSEMBLY__
14651 #if PAGETABLE_LEVELS > 3
14652 typedef struct { pudval_t pud; } pud_t;
14653
14654@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14655 return pud.pud;
14656 }
14657 #else
14658-#include <asm-generic/pgtable-nopud.h>
14659-
14660 static inline pudval_t native_pud_val(pud_t pud)
14661 {
14662 return native_pgd_val(pud.pgd);
14663@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14664 return pmd.pmd;
14665 }
14666 #else
14667-#include <asm-generic/pgtable-nopmd.h>
14668-
14669 static inline pmdval_t native_pmd_val(pmd_t pmd)
14670 {
14671 return native_pgd_val(pmd.pud.pgd);
14672@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14673
14674 extern pteval_t __supported_pte_mask;
14675 extern void set_nx(void);
14676-extern int nx_enabled;
14677
14678 #define pgprot_writecombine pgprot_writecombine
14679 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14680diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14681index 888184b..a07ac89 100644
14682--- a/arch/x86/include/asm/processor.h
14683+++ b/arch/x86/include/asm/processor.h
14684@@ -287,7 +287,7 @@ struct tss_struct {
14685
14686 } ____cacheline_aligned;
14687
14688-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14689+extern struct tss_struct init_tss[NR_CPUS];
14690
14691 /*
14692 * Save the original ist values for checking stack pointers during debugging
14693@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14694 */
14695 #define TASK_SIZE PAGE_OFFSET
14696 #define TASK_SIZE_MAX TASK_SIZE
14697+
14698+#ifdef CONFIG_PAX_SEGMEXEC
14699+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14700+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14701+#else
14702 #define STACK_TOP TASK_SIZE
14703-#define STACK_TOP_MAX STACK_TOP
14704+#endif
14705+
14706+#define STACK_TOP_MAX TASK_SIZE
14707
14708 #define INIT_THREAD { \
14709- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14710+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14711 .vm86_info = NULL, \
14712 .sysenter_cs = __KERNEL_CS, \
14713 .io_bitmap_ptr = NULL, \
14714@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14715 */
14716 #define INIT_TSS { \
14717 .x86_tss = { \
14718- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14719+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14720 .ss0 = __KERNEL_DS, \
14721 .ss1 = __KERNEL_CS, \
14722 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14723@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14724 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14725
14726 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14727-#define KSTK_TOP(info) \
14728-({ \
14729- unsigned long *__ptr = (unsigned long *)(info); \
14730- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14731-})
14732+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14733
14734 /*
14735 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14736@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14737 #define task_pt_regs(task) \
14738 ({ \
14739 struct pt_regs *__regs__; \
14740- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14741+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14742 __regs__ - 1; \
14743 })
14744
14745@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14746 /*
14747 * User space process size. 47bits minus one guard page.
14748 */
14749-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14750+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14751
14752 /* This decides where the kernel will search for a free chunk of vm
14753 * space during mmap's.
14754 */
14755 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14756- 0xc0000000 : 0xFFFFe000)
14757+ 0xc0000000 : 0xFFFFf000)
14758
14759 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14760 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14761@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14762 #define STACK_TOP_MAX TASK_SIZE_MAX
14763
14764 #define INIT_THREAD { \
14765- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14766+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14767 }
14768
14769 #define INIT_TSS { \
14770- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14771+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14772 }
14773
14774 /*
14775@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14776 */
14777 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14778
14779+#ifdef CONFIG_PAX_SEGMEXEC
14780+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14781+#endif
14782+
14783 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14784
14785 /* Get/set a process' ability to use the timestamp counter instruction */
14786@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14787 #define cpu_has_amd_erratum(x) (false)
14788 #endif /* CONFIG_CPU_SUP_AMD */
14789
14790-extern unsigned long arch_align_stack(unsigned long sp);
14791+#define arch_align_stack(x) ((x) & ~0xfUL)
14792 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14793
14794 void default_idle(void);
14795 bool set_pm_idle_to_default(void);
14796
14797-void stop_this_cpu(void *dummy);
14798+void stop_this_cpu(void *dummy) __noreturn;
14799
14800 #endif /* _ASM_X86_PROCESSOR_H */
14801diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14802index 942a086..6c26446 100644
14803--- a/arch/x86/include/asm/ptrace.h
14804+++ b/arch/x86/include/asm/ptrace.h
14805@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14806 }
14807
14808 /*
14809- * user_mode_vm(regs) determines whether a register set came from user mode.
14810+ * user_mode(regs) determines whether a register set came from user mode.
14811 * This is true if V8086 mode was enabled OR if the register set was from
14812 * protected mode with RPL-3 CS value. This tricky test checks that with
14813 * one comparison. Many places in the kernel can bypass this full check
14814- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14815+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14816+ * be used.
14817 */
14818-static inline int user_mode(struct pt_regs *regs)
14819+static inline int user_mode_novm(struct pt_regs *regs)
14820 {
14821 #ifdef CONFIG_X86_32
14822 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14823 #else
14824- return !!(regs->cs & 3);
14825+ return !!(regs->cs & SEGMENT_RPL_MASK);
14826 #endif
14827 }
14828
14829-static inline int user_mode_vm(struct pt_regs *regs)
14830+static inline int user_mode(struct pt_regs *regs)
14831 {
14832 #ifdef CONFIG_X86_32
14833 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14834 USER_RPL;
14835 #else
14836- return user_mode(regs);
14837+ return user_mode_novm(regs);
14838 #endif
14839 }
14840
14841@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14842 #ifdef CONFIG_X86_64
14843 static inline bool user_64bit_mode(struct pt_regs *regs)
14844 {
14845+ unsigned long cs = regs->cs & 0xffff;
14846 #ifndef CONFIG_PARAVIRT
14847 /*
14848 * On non-paravirt systems, this is the only long mode CPL 3
14849 * selector. We do not allow long mode selectors in the LDT.
14850 */
14851- return regs->cs == __USER_CS;
14852+ return cs == __USER_CS;
14853 #else
14854 /* Headers are too twisted for this to go in paravirt.h. */
14855- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14856+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14857 #endif
14858 }
14859
14860@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14861 * Traps from the kernel do not save sp and ss.
14862 * Use the helper function to retrieve sp.
14863 */
14864- if (offset == offsetof(struct pt_regs, sp) &&
14865- regs->cs == __KERNEL_CS)
14866- return kernel_stack_pointer(regs);
14867+ if (offset == offsetof(struct pt_regs, sp)) {
14868+ unsigned long cs = regs->cs & 0xffff;
14869+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14870+ return kernel_stack_pointer(regs);
14871+ }
14872 #endif
14873 return *(unsigned long *)((unsigned long)regs + offset);
14874 }
14875diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14876index fe1ec5b..dc5c3fe 100644
14877--- a/arch/x86/include/asm/realmode.h
14878+++ b/arch/x86/include/asm/realmode.h
14879@@ -22,16 +22,14 @@ struct real_mode_header {
14880 #endif
14881 /* APM/BIOS reboot */
14882 u32 machine_real_restart_asm;
14883-#ifdef CONFIG_X86_64
14884 u32 machine_real_restart_seg;
14885-#endif
14886 };
14887
14888 /* This must match data at trampoline_32/64.S */
14889 struct trampoline_header {
14890 #ifdef CONFIG_X86_32
14891 u32 start;
14892- u16 gdt_pad;
14893+ u16 boot_cs;
14894 u16 gdt_limit;
14895 u32 gdt_base;
14896 #else
14897diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14898index a82c4f1..ac45053 100644
14899--- a/arch/x86/include/asm/reboot.h
14900+++ b/arch/x86/include/asm/reboot.h
14901@@ -6,13 +6,13 @@
14902 struct pt_regs;
14903
14904 struct machine_ops {
14905- void (*restart)(char *cmd);
14906- void (*halt)(void);
14907- void (*power_off)(void);
14908+ void (* __noreturn restart)(char *cmd);
14909+ void (* __noreturn halt)(void);
14910+ void (* __noreturn power_off)(void);
14911 void (*shutdown)(void);
14912 void (*crash_shutdown)(struct pt_regs *);
14913- void (*emergency_restart)(void);
14914-};
14915+ void (* __noreturn emergency_restart)(void);
14916+} __no_const;
14917
14918 extern struct machine_ops machine_ops;
14919
14920diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14921index 2dbe4a7..ce1db00 100644
14922--- a/arch/x86/include/asm/rwsem.h
14923+++ b/arch/x86/include/asm/rwsem.h
14924@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14925 {
14926 asm volatile("# beginning down_read\n\t"
14927 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14928+
14929+#ifdef CONFIG_PAX_REFCOUNT
14930+ "jno 0f\n"
14931+ LOCK_PREFIX _ASM_DEC "(%1)\n"
14932+ "int $4\n0:\n"
14933+ _ASM_EXTABLE(0b, 0b)
14934+#endif
14935+
14936 /* adds 0x00000001 */
14937 " jns 1f\n"
14938 " call call_rwsem_down_read_failed\n"
14939@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14940 "1:\n\t"
14941 " mov %1,%2\n\t"
14942 " add %3,%2\n\t"
14943+
14944+#ifdef CONFIG_PAX_REFCOUNT
14945+ "jno 0f\n"
14946+ "sub %3,%2\n"
14947+ "int $4\n0:\n"
14948+ _ASM_EXTABLE(0b, 0b)
14949+#endif
14950+
14951 " jle 2f\n\t"
14952 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14953 " jnz 1b\n\t"
14954@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14955 long tmp;
14956 asm volatile("# beginning down_write\n\t"
14957 LOCK_PREFIX " xadd %1,(%2)\n\t"
14958+
14959+#ifdef CONFIG_PAX_REFCOUNT
14960+ "jno 0f\n"
14961+ "mov %1,(%2)\n"
14962+ "int $4\n0:\n"
14963+ _ASM_EXTABLE(0b, 0b)
14964+#endif
14965+
14966 /* adds 0xffff0001, returns the old value */
14967 " test %1,%1\n\t"
14968 /* was the count 0 before? */
14969@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14970 long tmp;
14971 asm volatile("# beginning __up_read\n\t"
14972 LOCK_PREFIX " xadd %1,(%2)\n\t"
14973+
14974+#ifdef CONFIG_PAX_REFCOUNT
14975+ "jno 0f\n"
14976+ "mov %1,(%2)\n"
14977+ "int $4\n0:\n"
14978+ _ASM_EXTABLE(0b, 0b)
14979+#endif
14980+
14981 /* subtracts 1, returns the old value */
14982 " jns 1f\n\t"
14983 " call call_rwsem_wake\n" /* expects old value in %edx */
14984@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14985 long tmp;
14986 asm volatile("# beginning __up_write\n\t"
14987 LOCK_PREFIX " xadd %1,(%2)\n\t"
14988+
14989+#ifdef CONFIG_PAX_REFCOUNT
14990+ "jno 0f\n"
14991+ "mov %1,(%2)\n"
14992+ "int $4\n0:\n"
14993+ _ASM_EXTABLE(0b, 0b)
14994+#endif
14995+
14996 /* subtracts 0xffff0001, returns the old value */
14997 " jns 1f\n\t"
14998 " call call_rwsem_wake\n" /* expects old value in %edx */
14999@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15000 {
15001 asm volatile("# beginning __downgrade_write\n\t"
15002 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15003+
15004+#ifdef CONFIG_PAX_REFCOUNT
15005+ "jno 0f\n"
15006+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15007+ "int $4\n0:\n"
15008+ _ASM_EXTABLE(0b, 0b)
15009+#endif
15010+
15011 /*
15012 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15013 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15014@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15015 */
15016 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15017 {
15018- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15019+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15020+
15021+#ifdef CONFIG_PAX_REFCOUNT
15022+ "jno 0f\n"
15023+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15024+ "int $4\n0:\n"
15025+ _ASM_EXTABLE(0b, 0b)
15026+#endif
15027+
15028 : "+m" (sem->count)
15029 : "er" (delta));
15030 }
15031@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15032 */
15033 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15034 {
15035- return delta + xadd(&sem->count, delta);
15036+ return delta + xadd_check_overflow(&sem->count, delta);
15037 }
15038
15039 #endif /* __KERNEL__ */
15040diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15041index c48a950..c6d7468 100644
15042--- a/arch/x86/include/asm/segment.h
15043+++ b/arch/x86/include/asm/segment.h
15044@@ -64,10 +64,15 @@
15045 * 26 - ESPFIX small SS
15046 * 27 - per-cpu [ offset to per-cpu data area ]
15047 * 28 - stack_canary-20 [ for stack protector ]
15048- * 29 - unused
15049- * 30 - unused
15050+ * 29 - PCI BIOS CS
15051+ * 30 - PCI BIOS DS
15052 * 31 - TSS for double fault handler
15053 */
15054+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15055+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15056+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15057+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15058+
15059 #define GDT_ENTRY_TLS_MIN 6
15060 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15061
15062@@ -79,6 +84,8 @@
15063
15064 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15065
15066+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15067+
15068 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15069
15070 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15071@@ -104,6 +111,12 @@
15072 #define __KERNEL_STACK_CANARY 0
15073 #endif
15074
15075+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15076+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15077+
15078+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15079+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15080+
15081 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15082
15083 /*
15084@@ -141,7 +154,7 @@
15085 */
15086
15087 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15088-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15089+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15090
15091
15092 #else
15093@@ -165,6 +178,8 @@
15094 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15095 #define __USER32_DS __USER_DS
15096
15097+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15098+
15099 #define GDT_ENTRY_TSS 8 /* needs two entries */
15100 #define GDT_ENTRY_LDT 10 /* needs two entries */
15101 #define GDT_ENTRY_TLS_MIN 12
15102@@ -185,6 +200,7 @@
15103 #endif
15104
15105 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15106+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15107 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15108 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15109 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15110@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15111 {
15112 unsigned long __limit;
15113 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15114- return __limit + 1;
15115+ return __limit;
15116 }
15117
15118 #endif /* !__ASSEMBLY__ */
15119diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15120index b073aae..39f9bdd 100644
15121--- a/arch/x86/include/asm/smp.h
15122+++ b/arch/x86/include/asm/smp.h
15123@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15124 /* cpus sharing the last level cache: */
15125 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15126 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15127-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15128+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15129
15130 static inline struct cpumask *cpu_sibling_mask(int cpu)
15131 {
15132@@ -79,7 +79,7 @@ struct smp_ops {
15133
15134 void (*send_call_func_ipi)(const struct cpumask *mask);
15135 void (*send_call_func_single_ipi)(int cpu);
15136-};
15137+} __no_const;
15138
15139 /* Globals due to paravirt */
15140 extern void set_cpu_sibling_map(int cpu);
15141@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15142 extern int safe_smp_processor_id(void);
15143
15144 #elif defined(CONFIG_X86_64_SMP)
15145-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15146-
15147-#define stack_smp_processor_id() \
15148-({ \
15149- struct thread_info *ti; \
15150- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15151- ti->cpu; \
15152-})
15153+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15154+#define stack_smp_processor_id() raw_smp_processor_id()
15155 #define safe_smp_processor_id() smp_processor_id()
15156
15157 #endif
15158diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15159index 33692ea..350a534 100644
15160--- a/arch/x86/include/asm/spinlock.h
15161+++ b/arch/x86/include/asm/spinlock.h
15162@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15163 static inline void arch_read_lock(arch_rwlock_t *rw)
15164 {
15165 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15166+
15167+#ifdef CONFIG_PAX_REFCOUNT
15168+ "jno 0f\n"
15169+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15170+ "int $4\n0:\n"
15171+ _ASM_EXTABLE(0b, 0b)
15172+#endif
15173+
15174 "jns 1f\n"
15175 "call __read_lock_failed\n\t"
15176 "1:\n"
15177@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15178 static inline void arch_write_lock(arch_rwlock_t *rw)
15179 {
15180 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15181+
15182+#ifdef CONFIG_PAX_REFCOUNT
15183+ "jno 0f\n"
15184+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15185+ "int $4\n0:\n"
15186+ _ASM_EXTABLE(0b, 0b)
15187+#endif
15188+
15189 "jz 1f\n"
15190 "call __write_lock_failed\n\t"
15191 "1:\n"
15192@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15193
15194 static inline void arch_read_unlock(arch_rwlock_t *rw)
15195 {
15196- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15197+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15198+
15199+#ifdef CONFIG_PAX_REFCOUNT
15200+ "jno 0f\n"
15201+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15202+ "int $4\n0:\n"
15203+ _ASM_EXTABLE(0b, 0b)
15204+#endif
15205+
15206 :"+m" (rw->lock) : : "memory");
15207 }
15208
15209 static inline void arch_write_unlock(arch_rwlock_t *rw)
15210 {
15211- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15212+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15213+
15214+#ifdef CONFIG_PAX_REFCOUNT
15215+ "jno 0f\n"
15216+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15217+ "int $4\n0:\n"
15218+ _ASM_EXTABLE(0b, 0b)
15219+#endif
15220+
15221 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15222 }
15223
15224diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15225index 6a99859..03cb807 100644
15226--- a/arch/x86/include/asm/stackprotector.h
15227+++ b/arch/x86/include/asm/stackprotector.h
15228@@ -47,7 +47,7 @@
15229 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15230 */
15231 #define GDT_STACK_CANARY_INIT \
15232- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15233+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15234
15235 /*
15236 * Initialize the stackprotector canary value.
15237@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15238
15239 static inline void load_stack_canary_segment(void)
15240 {
15241-#ifdef CONFIG_X86_32
15242+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15243 asm volatile ("mov %0, %%gs" : : "r" (0));
15244 #endif
15245 }
15246diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15247index 70bbe39..4ae2bd4 100644
15248--- a/arch/x86/include/asm/stacktrace.h
15249+++ b/arch/x86/include/asm/stacktrace.h
15250@@ -11,28 +11,20 @@
15251
15252 extern int kstack_depth_to_print;
15253
15254-struct thread_info;
15255+struct task_struct;
15256 struct stacktrace_ops;
15257
15258-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15259- unsigned long *stack,
15260- unsigned long bp,
15261- const struct stacktrace_ops *ops,
15262- void *data,
15263- unsigned long *end,
15264- int *graph);
15265+typedef unsigned long walk_stack_t(struct task_struct *task,
15266+ void *stack_start,
15267+ unsigned long *stack,
15268+ unsigned long bp,
15269+ const struct stacktrace_ops *ops,
15270+ void *data,
15271+ unsigned long *end,
15272+ int *graph);
15273
15274-extern unsigned long
15275-print_context_stack(struct thread_info *tinfo,
15276- unsigned long *stack, unsigned long bp,
15277- const struct stacktrace_ops *ops, void *data,
15278- unsigned long *end, int *graph);
15279-
15280-extern unsigned long
15281-print_context_stack_bp(struct thread_info *tinfo,
15282- unsigned long *stack, unsigned long bp,
15283- const struct stacktrace_ops *ops, void *data,
15284- unsigned long *end, int *graph);
15285+extern walk_stack_t print_context_stack;
15286+extern walk_stack_t print_context_stack_bp;
15287
15288 /* Generic stack tracer with callbacks */
15289
15290@@ -40,7 +32,7 @@ struct stacktrace_ops {
15291 void (*address)(void *data, unsigned long address, int reliable);
15292 /* On negative return stop dumping */
15293 int (*stack)(void *data, char *name);
15294- walk_stack_t walk_stack;
15295+ walk_stack_t *walk_stack;
15296 };
15297
15298 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15299diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15300index 4ec45b3..a4f0a8a 100644
15301--- a/arch/x86/include/asm/switch_to.h
15302+++ b/arch/x86/include/asm/switch_to.h
15303@@ -108,7 +108,7 @@ do { \
15304 "call __switch_to\n\t" \
15305 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15306 __switch_canary \
15307- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15308+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15309 "movq %%rax,%%rdi\n\t" \
15310 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15311 "jnz ret_from_fork\n\t" \
15312@@ -119,7 +119,7 @@ do { \
15313 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15314 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15315 [_tif_fork] "i" (_TIF_FORK), \
15316- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15317+ [thread_info] "m" (current_tinfo), \
15318 [current_task] "m" (current_task) \
15319 __switch_canary_iparam \
15320 : "memory", "cc" __EXTRA_CLOBBER)
15321diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15322index 2d946e6..e453ec4 100644
15323--- a/arch/x86/include/asm/thread_info.h
15324+++ b/arch/x86/include/asm/thread_info.h
15325@@ -10,6 +10,7 @@
15326 #include <linux/compiler.h>
15327 #include <asm/page.h>
15328 #include <asm/types.h>
15329+#include <asm/percpu.h>
15330
15331 /*
15332 * low level task data that entry.S needs immediate access to
15333@@ -24,7 +25,6 @@ struct exec_domain;
15334 #include <linux/atomic.h>
15335
15336 struct thread_info {
15337- struct task_struct *task; /* main task structure */
15338 struct exec_domain *exec_domain; /* execution domain */
15339 __u32 flags; /* low level flags */
15340 __u32 status; /* thread synchronous flags */
15341@@ -34,19 +34,13 @@ struct thread_info {
15342 mm_segment_t addr_limit;
15343 struct restart_block restart_block;
15344 void __user *sysenter_return;
15345-#ifdef CONFIG_X86_32
15346- unsigned long previous_esp; /* ESP of the previous stack in
15347- case of nested (IRQ) stacks
15348- */
15349- __u8 supervisor_stack[0];
15350-#endif
15351+ unsigned long lowest_stack;
15352 unsigned int sig_on_uaccess_error:1;
15353 unsigned int uaccess_err:1; /* uaccess failed */
15354 };
15355
15356-#define INIT_THREAD_INFO(tsk) \
15357+#define INIT_THREAD_INFO \
15358 { \
15359- .task = &tsk, \
15360 .exec_domain = &default_exec_domain, \
15361 .flags = 0, \
15362 .cpu = 0, \
15363@@ -57,7 +51,7 @@ struct thread_info {
15364 }, \
15365 }
15366
15367-#define init_thread_info (init_thread_union.thread_info)
15368+#define init_thread_info (init_thread_union.stack)
15369 #define init_stack (init_thread_union.stack)
15370
15371 #else /* !__ASSEMBLY__ */
15372@@ -98,6 +92,7 @@ struct thread_info {
15373 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15374 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15375 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15376+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15377
15378 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15379 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15380@@ -122,17 +117,18 @@ struct thread_info {
15381 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15382 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15383 #define _TIF_X32 (1 << TIF_X32)
15384+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15385
15386 /* work to do in syscall_trace_enter() */
15387 #define _TIF_WORK_SYSCALL_ENTRY \
15388 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15389 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15390- _TIF_NOHZ)
15391+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15392
15393 /* work to do in syscall_trace_leave() */
15394 #define _TIF_WORK_SYSCALL_EXIT \
15395 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15396- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15397+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15398
15399 /* work to do on interrupt/exception return */
15400 #define _TIF_WORK_MASK \
15401@@ -143,7 +139,7 @@ struct thread_info {
15402 /* work to do on any return to user space */
15403 #define _TIF_ALLWORK_MASK \
15404 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15405- _TIF_NOHZ)
15406+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15407
15408 /* Only used for 64 bit */
15409 #define _TIF_DO_NOTIFY_MASK \
15410@@ -159,45 +155,40 @@ struct thread_info {
15411
15412 #define PREEMPT_ACTIVE 0x10000000
15413
15414-#ifdef CONFIG_X86_32
15415-
15416-#define STACK_WARN (THREAD_SIZE/8)
15417-/*
15418- * macros/functions for gaining access to the thread information structure
15419- *
15420- * preempt_count needs to be 1 initially, until the scheduler is functional.
15421- */
15422-#ifndef __ASSEMBLY__
15423-
15424-
15425-/* how to get the current stack pointer from C */
15426-register unsigned long current_stack_pointer asm("esp") __used;
15427-
15428-/* how to get the thread information struct from C */
15429-static inline struct thread_info *current_thread_info(void)
15430-{
15431- return (struct thread_info *)
15432- (current_stack_pointer & ~(THREAD_SIZE - 1));
15433-}
15434-
15435-#else /* !__ASSEMBLY__ */
15436-
15437+#ifdef __ASSEMBLY__
15438 /* how to get the thread information struct from ASM */
15439 #define GET_THREAD_INFO(reg) \
15440- movl $-THREAD_SIZE, reg; \
15441- andl %esp, reg
15442+ mov PER_CPU_VAR(current_tinfo), reg
15443
15444 /* use this one if reg already contains %esp */
15445-#define GET_THREAD_INFO_WITH_ESP(reg) \
15446- andl $-THREAD_SIZE, reg
15447+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15448+#else
15449+/* how to get the thread information struct from C */
15450+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15451+
15452+static __always_inline struct thread_info *current_thread_info(void)
15453+{
15454+ return this_cpu_read_stable(current_tinfo);
15455+}
15456+#endif
15457+
15458+#ifdef CONFIG_X86_32
15459+
15460+#define STACK_WARN (THREAD_SIZE/8)
15461+/*
15462+ * macros/functions for gaining access to the thread information structure
15463+ *
15464+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15465+ */
15466+#ifndef __ASSEMBLY__
15467+
15468+/* how to get the current stack pointer from C */
15469+register unsigned long current_stack_pointer asm("esp") __used;
15470
15471 #endif
15472
15473 #else /* X86_32 */
15474
15475-#include <asm/percpu.h>
15476-#define KERNEL_STACK_OFFSET (5*8)
15477-
15478 /*
15479 * macros/functions for gaining access to the thread information structure
15480 * preempt_count needs to be 1 initially, until the scheduler is functional.
15481@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15482 #ifndef __ASSEMBLY__
15483 DECLARE_PER_CPU(unsigned long, kernel_stack);
15484
15485-static inline struct thread_info *current_thread_info(void)
15486-{
15487- struct thread_info *ti;
15488- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15489- KERNEL_STACK_OFFSET - THREAD_SIZE);
15490- return ti;
15491-}
15492-
15493-#else /* !__ASSEMBLY__ */
15494-
15495-/* how to get the thread information struct from ASM */
15496-#define GET_THREAD_INFO(reg) \
15497- movq PER_CPU_VAR(kernel_stack),reg ; \
15498- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15499-
15500-/*
15501- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15502- * a certain register (to be used in assembler memory operands).
15503- */
15504-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15505-
15506+/* how to get the current stack pointer from C */
15507+register unsigned long current_stack_pointer asm("rsp") __used;
15508 #endif
15509
15510 #endif /* !X86_32 */
15511@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15512 extern void arch_task_cache_init(void);
15513 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15514 extern void arch_release_task_struct(struct task_struct *tsk);
15515+
15516+#define __HAVE_THREAD_FUNCTIONS
15517+#define task_thread_info(task) (&(task)->tinfo)
15518+#define task_stack_page(task) ((task)->stack)
15519+#define setup_thread_stack(p, org) do {} while (0)
15520+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15521+
15522 #endif
15523 #endif /* _ASM_X86_THREAD_INFO_H */
15524diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15525index 1709801..0a60f2f 100644
15526--- a/arch/x86/include/asm/uaccess.h
15527+++ b/arch/x86/include/asm/uaccess.h
15528@@ -7,6 +7,7 @@
15529 #include <linux/compiler.h>
15530 #include <linux/thread_info.h>
15531 #include <linux/string.h>
15532+#include <linux/sched.h>
15533 #include <asm/asm.h>
15534 #include <asm/page.h>
15535 #include <asm/smap.h>
15536@@ -29,7 +30,12 @@
15537
15538 #define get_ds() (KERNEL_DS)
15539 #define get_fs() (current_thread_info()->addr_limit)
15540+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15541+void __set_fs(mm_segment_t x);
15542+void set_fs(mm_segment_t x);
15543+#else
15544 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15545+#endif
15546
15547 #define segment_eq(a, b) ((a).seg == (b).seg)
15548
15549@@ -77,8 +83,33 @@
15550 * checks that the pointer is in the user space range - after calling
15551 * this function, memory access functions may still return -EFAULT.
15552 */
15553-#define access_ok(type, addr, size) \
15554- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15555+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15556+#define access_ok(type, addr, size) \
15557+({ \
15558+ long __size = size; \
15559+ unsigned long __addr = (unsigned long)addr; \
15560+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15561+ unsigned long __end_ao = __addr + __size - 1; \
15562+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15563+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15564+ while(__addr_ao <= __end_ao) { \
15565+ char __c_ao; \
15566+ __addr_ao += PAGE_SIZE; \
15567+ if (__size > PAGE_SIZE) \
15568+ cond_resched(); \
15569+ if (__get_user(__c_ao, (char __user *)__addr)) \
15570+ break; \
15571+ if (type != VERIFY_WRITE) { \
15572+ __addr = __addr_ao; \
15573+ continue; \
15574+ } \
15575+ if (__put_user(__c_ao, (char __user *)__addr)) \
15576+ break; \
15577+ __addr = __addr_ao; \
15578+ } \
15579+ } \
15580+ __ret_ao; \
15581+})
15582
15583 /*
15584 * The exception table consists of pairs of addresses relative to the
15585@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15586 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15587 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15588
15589-
15590+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15591+#define __copyuser_seg "gs;"
15592+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15593+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15594+#else
15595+#define __copyuser_seg
15596+#define __COPYUSER_SET_ES
15597+#define __COPYUSER_RESTORE_ES
15598+#endif
15599
15600 #ifdef CONFIG_X86_32
15601 #define __put_user_asm_u64(x, addr, err, errret) \
15602 asm volatile(ASM_STAC "\n" \
15603- "1: movl %%eax,0(%2)\n" \
15604- "2: movl %%edx,4(%2)\n" \
15605+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15606+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15607 "3: " ASM_CLAC "\n" \
15608 ".section .fixup,\"ax\"\n" \
15609 "4: movl %3,%0\n" \
15610@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15611
15612 #define __put_user_asm_ex_u64(x, addr) \
15613 asm volatile(ASM_STAC "\n" \
15614- "1: movl %%eax,0(%1)\n" \
15615- "2: movl %%edx,4(%1)\n" \
15616+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15617+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15618 "3: " ASM_CLAC "\n" \
15619 _ASM_EXTABLE_EX(1b, 2b) \
15620 _ASM_EXTABLE_EX(2b, 3b) \
15621@@ -259,7 +298,7 @@ extern void __put_user_8(void);
15622 __typeof__(*(ptr)) __pu_val; \
15623 __chk_user_ptr(ptr); \
15624 might_fault(); \
15625- __pu_val = x; \
15626+ __pu_val = (x); \
15627 switch (sizeof(*(ptr))) { \
15628 case 1: \
15629 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15630@@ -358,7 +397,7 @@ do { \
15631
15632 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15633 asm volatile(ASM_STAC "\n" \
15634- "1: mov"itype" %2,%"rtype"1\n" \
15635+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15636 "2: " ASM_CLAC "\n" \
15637 ".section .fixup,\"ax\"\n" \
15638 "3: mov %3,%0\n" \
15639@@ -366,7 +405,7 @@ do { \
15640 " jmp 2b\n" \
15641 ".previous\n" \
15642 _ASM_EXTABLE(1b, 3b) \
15643- : "=r" (err), ltype(x) \
15644+ : "=r" (err), ltype (x) \
15645 : "m" (__m(addr)), "i" (errret), "0" (err))
15646
15647 #define __get_user_size_ex(x, ptr, size) \
15648@@ -391,7 +430,7 @@ do { \
15649 } while (0)
15650
15651 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15652- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15653+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15654 "2:\n" \
15655 _ASM_EXTABLE_EX(1b, 2b) \
15656 : ltype(x) : "m" (__m(addr)))
15657@@ -408,13 +447,24 @@ do { \
15658 int __gu_err; \
15659 unsigned long __gu_val; \
15660 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15661- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15662+ (x) = (__typeof__(*(ptr)))__gu_val; \
15663 __gu_err; \
15664 })
15665
15666 /* FIXME: this hack is definitely wrong -AK */
15667 struct __large_struct { unsigned long buf[100]; };
15668-#define __m(x) (*(struct __large_struct __user *)(x))
15669+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15670+#define ____m(x) \
15671+({ \
15672+ unsigned long ____x = (unsigned long)(x); \
15673+ if (____x < PAX_USER_SHADOW_BASE) \
15674+ ____x += PAX_USER_SHADOW_BASE; \
15675+ (void __user *)____x; \
15676+})
15677+#else
15678+#define ____m(x) (x)
15679+#endif
15680+#define __m(x) (*(struct __large_struct __user *)____m(x))
15681
15682 /*
15683 * Tell gcc we read from memory instead of writing: this is because
15684@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15685 */
15686 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15687 asm volatile(ASM_STAC "\n" \
15688- "1: mov"itype" %"rtype"1,%2\n" \
15689+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15690 "2: " ASM_CLAC "\n" \
15691 ".section .fixup,\"ax\"\n" \
15692 "3: mov %3,%0\n" \
15693@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15694 ".previous\n" \
15695 _ASM_EXTABLE(1b, 3b) \
15696 : "=r"(err) \
15697- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15698+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15699
15700 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15701- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15702+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15703 "2:\n" \
15704 _ASM_EXTABLE_EX(1b, 2b) \
15705 : : ltype(x), "m" (__m(addr)))
15706@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15707 * On error, the variable @x is set to zero.
15708 */
15709
15710+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15711+#define __get_user(x, ptr) get_user((x), (ptr))
15712+#else
15713 #define __get_user(x, ptr) \
15714 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15715+#endif
15716
15717 /**
15718 * __put_user: - Write a simple value into user space, with less checking.
15719@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15720 * Returns zero on success, or -EFAULT on error.
15721 */
15722
15723+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15724+#define __put_user(x, ptr) put_user((x), (ptr))
15725+#else
15726 #define __put_user(x, ptr) \
15727 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15728+#endif
15729
15730 #define __get_user_unaligned __get_user
15731 #define __put_user_unaligned __put_user
15732@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15733 #define get_user_ex(x, ptr) do { \
15734 unsigned long __gue_val; \
15735 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15736- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15737+ (x) = (__typeof__(*(ptr)))__gue_val; \
15738 } while (0)
15739
15740 #define put_user_try uaccess_try
15741@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15742 extern __must_check long strlen_user(const char __user *str);
15743 extern __must_check long strnlen_user(const char __user *str, long n);
15744
15745-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
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) __size_overflow(2);
15748+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15749
15750 /*
15751 * movsl can be slow when source and dest are not both 8-byte aligned
15752diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15753index 7f760a9..04b1c65 100644
15754--- a/arch/x86/include/asm/uaccess_32.h
15755+++ b/arch/x86/include/asm/uaccess_32.h
15756@@ -11,15 +11,15 @@
15757 #include <asm/page.h>
15758
15759 unsigned long __must_check __copy_to_user_ll
15760- (void __user *to, const void *from, unsigned long n);
15761+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15762 unsigned long __must_check __copy_from_user_ll
15763- (void *to, const void __user *from, unsigned long n);
15764+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15765 unsigned long __must_check __copy_from_user_ll_nozero
15766- (void *to, const void __user *from, unsigned long n);
15767+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15768 unsigned long __must_check __copy_from_user_ll_nocache
15769- (void *to, const void __user *from, unsigned long n);
15770+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15771 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15772- (void *to, const void __user *from, unsigned long n);
15773+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15774
15775 /**
15776 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15777@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15778 static __always_inline unsigned long __must_check
15779 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15780 {
15781+ if ((long)n < 0)
15782+ return n;
15783+
15784+ check_object_size(from, n, true);
15785+
15786 if (__builtin_constant_p(n)) {
15787 unsigned long ret;
15788
15789@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15790 __copy_to_user(void __user *to, const void *from, unsigned long n)
15791 {
15792 might_fault();
15793+
15794 return __copy_to_user_inatomic(to, from, n);
15795 }
15796
15797 static __always_inline unsigned long
15798 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15799 {
15800+ if ((long)n < 0)
15801+ return n;
15802+
15803 /* Avoid zeroing the tail if the copy fails..
15804 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15805 * but as the zeroing behaviour is only significant when n is not
15806@@ -137,6 +146,12 @@ static __always_inline unsigned long
15807 __copy_from_user(void *to, const void __user *from, unsigned long n)
15808 {
15809 might_fault();
15810+
15811+ if ((long)n < 0)
15812+ return n;
15813+
15814+ check_object_size(to, n, false);
15815+
15816 if (__builtin_constant_p(n)) {
15817 unsigned long ret;
15818
15819@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15820 const void __user *from, unsigned long n)
15821 {
15822 might_fault();
15823+
15824+ if ((long)n < 0)
15825+ return n;
15826+
15827 if (__builtin_constant_p(n)) {
15828 unsigned long ret;
15829
15830@@ -181,15 +200,19 @@ static __always_inline unsigned long
15831 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15832 unsigned long n)
15833 {
15834- return __copy_from_user_ll_nocache_nozero(to, from, n);
15835+ if ((long)n < 0)
15836+ return n;
15837+
15838+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15839 }
15840
15841-unsigned long __must_check copy_to_user(void __user *to,
15842- const void *from, unsigned long n);
15843-unsigned long __must_check _copy_from_user(void *to,
15844- const void __user *from,
15845- unsigned long n);
15846-
15847+extern void copy_to_user_overflow(void)
15848+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15849+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15850+#else
15851+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15852+#endif
15853+;
15854
15855 extern void copy_from_user_overflow(void)
15856 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15857@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15858 #endif
15859 ;
15860
15861-static inline unsigned long __must_check copy_from_user(void *to,
15862- const void __user *from,
15863- unsigned long n)
15864+/**
15865+ * copy_to_user: - Copy a block of data into user space.
15866+ * @to: Destination address, in user space.
15867+ * @from: Source address, in kernel space.
15868+ * @n: Number of bytes to copy.
15869+ *
15870+ * Context: User context only. This function may sleep.
15871+ *
15872+ * Copy data from kernel space to user space.
15873+ *
15874+ * Returns number of bytes that could not be copied.
15875+ * On success, this will be zero.
15876+ */
15877+static inline unsigned long __must_check
15878+copy_to_user(void __user *to, const void *from, unsigned long n)
15879 {
15880- int sz = __compiletime_object_size(to);
15881+ size_t sz = __compiletime_object_size(from);
15882
15883- if (likely(sz == -1 || sz >= n))
15884- n = _copy_from_user(to, from, n);
15885- else
15886+ if (unlikely(sz != (size_t)-1 && sz < n))
15887+ copy_to_user_overflow();
15888+ else if (access_ok(VERIFY_WRITE, to, n))
15889+ n = __copy_to_user(to, from, n);
15890+ return n;
15891+}
15892+
15893+/**
15894+ * copy_from_user: - Copy a block of data from user space.
15895+ * @to: Destination address, in kernel space.
15896+ * @from: Source address, in user space.
15897+ * @n: Number of bytes to copy.
15898+ *
15899+ * Context: User context only. This function may sleep.
15900+ *
15901+ * Copy data from user space to kernel space.
15902+ *
15903+ * Returns number of bytes that could not be copied.
15904+ * On success, this will be zero.
15905+ *
15906+ * If some data could not be copied, this function will pad the copied
15907+ * data to the requested size using zero bytes.
15908+ */
15909+static inline unsigned long __must_check
15910+copy_from_user(void *to, const void __user *from, unsigned long n)
15911+{
15912+ size_t sz = __compiletime_object_size(to);
15913+
15914+ check_object_size(to, n, false);
15915+
15916+ if (unlikely(sz != (size_t)-1 && sz < n))
15917 copy_from_user_overflow();
15918-
15919+ else if (access_ok(VERIFY_READ, from, n))
15920+ n = __copy_from_user(to, from, n);
15921+ else if ((long)n > 0)
15922+ memset(to, 0, n);
15923 return n;
15924 }
15925
15926diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15927index 142810c..747941a 100644
15928--- a/arch/x86/include/asm/uaccess_64.h
15929+++ b/arch/x86/include/asm/uaccess_64.h
15930@@ -10,6 +10,9 @@
15931 #include <asm/alternative.h>
15932 #include <asm/cpufeature.h>
15933 #include <asm/page.h>
15934+#include <asm/pgtable.h>
15935+
15936+#define set_fs(x) (current_thread_info()->addr_limit = (x))
15937
15938 /*
15939 * Copy To/From Userspace
15940@@ -17,13 +20,13 @@
15941
15942 /* Handles exceptions in both to and from, but doesn't do access_ok */
15943 __must_check unsigned long
15944-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15945+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15946 __must_check unsigned long
15947-copy_user_generic_string(void *to, const void *from, unsigned len);
15948+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15949 __must_check unsigned long
15950-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15951+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15952
15953-static __always_inline __must_check unsigned long
15954+static __always_inline __must_check __size_overflow(3) unsigned long
15955 copy_user_generic(void *to, const void *from, unsigned len)
15956 {
15957 unsigned ret;
15958@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15959 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15960 "=d" (len)),
15961 "1" (to), "2" (from), "3" (len)
15962- : "memory", "rcx", "r8", "r9", "r10", "r11");
15963+ : "memory", "rcx", "r8", "r9", "r11");
15964 return ret;
15965 }
15966
15967+static __always_inline __must_check unsigned long
15968+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15969+static __always_inline __must_check unsigned long
15970+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15971 __must_check unsigned long
15972-_copy_to_user(void __user *to, const void *from, unsigned len);
15973-__must_check unsigned long
15974-_copy_from_user(void *to, const void __user *from, unsigned len);
15975-__must_check unsigned long
15976-copy_in_user(void __user *to, const void __user *from, unsigned len);
15977+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15978+
15979+extern void copy_to_user_overflow(void)
15980+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15981+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15982+#else
15983+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15984+#endif
15985+;
15986+
15987+extern void copy_from_user_overflow(void)
15988+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15989+ __compiletime_error("copy_from_user() buffer size is not provably correct")
15990+#else
15991+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
15992+#endif
15993+;
15994
15995 static inline unsigned long __must_check copy_from_user(void *to,
15996 const void __user *from,
15997 unsigned long n)
15998 {
15999- int sz = __compiletime_object_size(to);
16000-
16001 might_fault();
16002- if (likely(sz == -1 || sz >= n))
16003- n = _copy_from_user(to, from, n);
16004-#ifdef CONFIG_DEBUG_VM
16005- else
16006- WARN(1, "Buffer overflow detected!\n");
16007-#endif
16008+
16009+ check_object_size(to, n, false);
16010+
16011+ if (access_ok(VERIFY_READ, from, n))
16012+ n = __copy_from_user(to, from, n);
16013+ else if (n < INT_MAX)
16014+ memset(to, 0, n);
16015 return n;
16016 }
16017
16018 static __always_inline __must_check
16019-int copy_to_user(void __user *dst, const void *src, unsigned size)
16020+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16021 {
16022 might_fault();
16023
16024- return _copy_to_user(dst, src, size);
16025+ if (access_ok(VERIFY_WRITE, dst, size))
16026+ size = __copy_to_user(dst, src, size);
16027+ return size;
16028 }
16029
16030 static __always_inline __must_check
16031-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16032+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16033 {
16034- int ret = 0;
16035+ size_t sz = __compiletime_object_size(dst);
16036+ unsigned ret = 0;
16037
16038 might_fault();
16039+
16040+ if (size > INT_MAX)
16041+ return size;
16042+
16043+ check_object_size(dst, size, false);
16044+
16045+#ifdef CONFIG_PAX_MEMORY_UDEREF
16046+ if (!__access_ok(VERIFY_READ, src, size))
16047+ return size;
16048+#endif
16049+
16050+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16051+ copy_from_user_overflow();
16052+ return size;
16053+ }
16054+
16055 if (!__builtin_constant_p(size))
16056- return copy_user_generic(dst, (__force void *)src, size);
16057+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16058 switch (size) {
16059- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16060+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16061 ret, "b", "b", "=q", 1);
16062 return ret;
16063- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16064+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16065 ret, "w", "w", "=r", 2);
16066 return ret;
16067- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16068+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16069 ret, "l", "k", "=r", 4);
16070 return ret;
16071- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16072+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16073 ret, "q", "", "=r", 8);
16074 return ret;
16075 case 10:
16076- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16077+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16078 ret, "q", "", "=r", 10);
16079 if (unlikely(ret))
16080 return ret;
16081 __get_user_asm(*(u16 *)(8 + (char *)dst),
16082- (u16 __user *)(8 + (char __user *)src),
16083+ (const u16 __user *)(8 + (const char __user *)src),
16084 ret, "w", "w", "=r", 2);
16085 return ret;
16086 case 16:
16087- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16088+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16089 ret, "q", "", "=r", 16);
16090 if (unlikely(ret))
16091 return ret;
16092 __get_user_asm(*(u64 *)(8 + (char *)dst),
16093- (u64 __user *)(8 + (char __user *)src),
16094+ (const u64 __user *)(8 + (const char __user *)src),
16095 ret, "q", "", "=r", 8);
16096 return ret;
16097 default:
16098- return copy_user_generic(dst, (__force void *)src, size);
16099+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16100 }
16101 }
16102
16103 static __always_inline __must_check
16104-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16105+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16106 {
16107- int ret = 0;
16108+ size_t sz = __compiletime_object_size(src);
16109+ unsigned ret = 0;
16110
16111 might_fault();
16112+
16113+ if (size > INT_MAX)
16114+ return size;
16115+
16116+ check_object_size(src, size, true);
16117+
16118+#ifdef CONFIG_PAX_MEMORY_UDEREF
16119+ if (!__access_ok(VERIFY_WRITE, dst, size))
16120+ return size;
16121+#endif
16122+
16123+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16124+ copy_to_user_overflow();
16125+ return size;
16126+ }
16127+
16128 if (!__builtin_constant_p(size))
16129- return copy_user_generic((__force void *)dst, src, size);
16130+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16131 switch (size) {
16132- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16133+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16134 ret, "b", "b", "iq", 1);
16135 return ret;
16136- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16137+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16138 ret, "w", "w", "ir", 2);
16139 return ret;
16140- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16141+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16142 ret, "l", "k", "ir", 4);
16143 return ret;
16144- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16145+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16146 ret, "q", "", "er", 8);
16147 return ret;
16148 case 10:
16149- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16150+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16151 ret, "q", "", "er", 10);
16152 if (unlikely(ret))
16153 return ret;
16154 asm("":::"memory");
16155- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16156+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16157 ret, "w", "w", "ir", 2);
16158 return ret;
16159 case 16:
16160- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16161+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16162 ret, "q", "", "er", 16);
16163 if (unlikely(ret))
16164 return ret;
16165 asm("":::"memory");
16166- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16167+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16168 ret, "q", "", "er", 8);
16169 return ret;
16170 default:
16171- return copy_user_generic((__force void *)dst, src, size);
16172+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16173 }
16174 }
16175
16176 static __always_inline __must_check
16177-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16178+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16179 {
16180- int ret = 0;
16181+ unsigned ret = 0;
16182
16183 might_fault();
16184+
16185+ if (size > INT_MAX)
16186+ return size;
16187+
16188+#ifdef CONFIG_PAX_MEMORY_UDEREF
16189+ if (!__access_ok(VERIFY_READ, src, size))
16190+ return size;
16191+ if (!__access_ok(VERIFY_WRITE, dst, size))
16192+ return size;
16193+#endif
16194+
16195 if (!__builtin_constant_p(size))
16196- return copy_user_generic((__force void *)dst,
16197- (__force void *)src, size);
16198+ return copy_user_generic((__force_kernel void *)____m(dst),
16199+ (__force_kernel const void *)____m(src), size);
16200 switch (size) {
16201 case 1: {
16202 u8 tmp;
16203- __get_user_asm(tmp, (u8 __user *)src,
16204+ __get_user_asm(tmp, (const u8 __user *)src,
16205 ret, "b", "b", "=q", 1);
16206 if (likely(!ret))
16207 __put_user_asm(tmp, (u8 __user *)dst,
16208@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16209 }
16210 case 2: {
16211 u16 tmp;
16212- __get_user_asm(tmp, (u16 __user *)src,
16213+ __get_user_asm(tmp, (const u16 __user *)src,
16214 ret, "w", "w", "=r", 2);
16215 if (likely(!ret))
16216 __put_user_asm(tmp, (u16 __user *)dst,
16217@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16218
16219 case 4: {
16220 u32 tmp;
16221- __get_user_asm(tmp, (u32 __user *)src,
16222+ __get_user_asm(tmp, (const u32 __user *)src,
16223 ret, "l", "k", "=r", 4);
16224 if (likely(!ret))
16225 __put_user_asm(tmp, (u32 __user *)dst,
16226@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16227 }
16228 case 8: {
16229 u64 tmp;
16230- __get_user_asm(tmp, (u64 __user *)src,
16231+ __get_user_asm(tmp, (const u64 __user *)src,
16232 ret, "q", "", "=r", 8);
16233 if (likely(!ret))
16234 __put_user_asm(tmp, (u64 __user *)dst,
16235@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16236 return ret;
16237 }
16238 default:
16239- return copy_user_generic((__force void *)dst,
16240- (__force void *)src, size);
16241+ return copy_user_generic((__force_kernel void *)____m(dst),
16242+ (__force_kernel const void *)____m(src), size);
16243 }
16244 }
16245
16246 static __must_check __always_inline int
16247-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16248+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16249 {
16250- return copy_user_generic(dst, (__force const void *)src, size);
16251+ if (size > INT_MAX)
16252+ return size;
16253+
16254+#ifdef CONFIG_PAX_MEMORY_UDEREF
16255+ if (!__access_ok(VERIFY_READ, src, size))
16256+ return size;
16257+#endif
16258+
16259+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16260 }
16261
16262-static __must_check __always_inline int
16263-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16264+static __must_check __always_inline unsigned long
16265+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16266 {
16267- return copy_user_generic((__force void *)dst, src, size);
16268+ if (size > INT_MAX)
16269+ return size;
16270+
16271+#ifdef CONFIG_PAX_MEMORY_UDEREF
16272+ if (!__access_ok(VERIFY_WRITE, dst, size))
16273+ return size;
16274+#endif
16275+
16276+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16277 }
16278
16279-extern long __copy_user_nocache(void *dst, const void __user *src,
16280- unsigned size, int zerorest);
16281+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16282+ unsigned long size, int zerorest) __size_overflow(3);
16283
16284-static inline int
16285-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16286+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16287 {
16288 might_sleep();
16289+
16290+ if (size > INT_MAX)
16291+ return size;
16292+
16293+#ifdef CONFIG_PAX_MEMORY_UDEREF
16294+ if (!__access_ok(VERIFY_READ, src, size))
16295+ return size;
16296+#endif
16297+
16298 return __copy_user_nocache(dst, src, size, 1);
16299 }
16300
16301-static inline int
16302-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16303- unsigned size)
16304+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16305+ unsigned long size)
16306 {
16307+ if (size > INT_MAX)
16308+ return size;
16309+
16310+#ifdef CONFIG_PAX_MEMORY_UDEREF
16311+ if (!__access_ok(VERIFY_READ, src, size))
16312+ return size;
16313+#endif
16314+
16315 return __copy_user_nocache(dst, src, size, 0);
16316 }
16317
16318-unsigned long
16319-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16320+extern unsigned long
16321+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16322
16323 #endif /* _ASM_X86_UACCESS_64_H */
16324diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16325index 5b238981..77fdd78 100644
16326--- a/arch/x86/include/asm/word-at-a-time.h
16327+++ b/arch/x86/include/asm/word-at-a-time.h
16328@@ -11,7 +11,7 @@
16329 * and shift, for example.
16330 */
16331 struct word_at_a_time {
16332- const unsigned long one_bits, high_bits;
16333+ unsigned long one_bits, high_bits;
16334 };
16335
16336 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16337diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16338index 5769349..a3d3e2a 100644
16339--- a/arch/x86/include/asm/x86_init.h
16340+++ b/arch/x86/include/asm/x86_init.h
16341@@ -141,7 +141,7 @@ struct x86_init_ops {
16342 struct x86_init_timers timers;
16343 struct x86_init_iommu iommu;
16344 struct x86_init_pci pci;
16345-};
16346+} __no_const;
16347
16348 /**
16349 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16350@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
16351 void (*setup_percpu_clockev)(void);
16352 void (*early_percpu_clock_init)(void);
16353 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16354-};
16355+} __no_const;
16356
16357 /**
16358 * struct x86_platform_ops - platform specific runtime functions
16359@@ -178,7 +178,7 @@ struct x86_platform_ops {
16360 void (*save_sched_clock_state)(void);
16361 void (*restore_sched_clock_state)(void);
16362 void (*apic_post_init)(void);
16363-};
16364+} __no_const;
16365
16366 struct pci_dev;
16367
16368@@ -187,14 +187,14 @@ struct x86_msi_ops {
16369 void (*teardown_msi_irq)(unsigned int irq);
16370 void (*teardown_msi_irqs)(struct pci_dev *dev);
16371 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16372-};
16373+} __no_const;
16374
16375 struct x86_io_apic_ops {
16376 void (*init) (void);
16377 unsigned int (*read) (unsigned int apic, unsigned int reg);
16378 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16379 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16380-};
16381+} __no_const;
16382
16383 extern struct x86_init_ops x86_init;
16384 extern struct x86_cpuinit_ops x86_cpuinit;
16385diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16386index 0415cda..b43d877 100644
16387--- a/arch/x86/include/asm/xsave.h
16388+++ b/arch/x86/include/asm/xsave.h
16389@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16390 return -EFAULT;
16391
16392 __asm__ __volatile__(ASM_STAC "\n"
16393- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16394+ "1:"
16395+ __copyuser_seg
16396+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16397 "2: " ASM_CLAC "\n"
16398 ".section .fixup,\"ax\"\n"
16399 "3: movl $-1,%[err]\n"
16400@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16401 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16402 {
16403 int err;
16404- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16405+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16406 u32 lmask = mask;
16407 u32 hmask = mask >> 32;
16408
16409 __asm__ __volatile__(ASM_STAC "\n"
16410- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16411+ "1:"
16412+ __copyuser_seg
16413+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16414 "2: " ASM_CLAC "\n"
16415 ".section .fixup,\"ax\"\n"
16416 "3: movl $-1,%[err]\n"
16417diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16418index bbae024..e1528f9 100644
16419--- a/arch/x86/include/uapi/asm/e820.h
16420+++ b/arch/x86/include/uapi/asm/e820.h
16421@@ -63,7 +63,7 @@ struct e820map {
16422 #define ISA_START_ADDRESS 0xa0000
16423 #define ISA_END_ADDRESS 0x100000
16424
16425-#define BIOS_BEGIN 0x000a0000
16426+#define BIOS_BEGIN 0x000c0000
16427 #define BIOS_END 0x00100000
16428
16429 #define BIOS_ROM_BASE 0xffe00000
16430diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16431index 34e923a..0c6bb6e 100644
16432--- a/arch/x86/kernel/Makefile
16433+++ b/arch/x86/kernel/Makefile
16434@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16435 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16436 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16437 obj-y += probe_roms.o
16438-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16439+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16440 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16441 obj-y += syscall_$(BITS).o
16442 obj-$(CONFIG_X86_64) += vsyscall_64.o
16443diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16444index bacf4b0..4ede72e 100644
16445--- a/arch/x86/kernel/acpi/boot.c
16446+++ b/arch/x86/kernel/acpi/boot.c
16447@@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16448 * If your system is blacklisted here, but you find that acpi=force
16449 * works for you, please contact linux-acpi@vger.kernel.org
16450 */
16451-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16452+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16453 /*
16454 * Boxes that need ACPI disabled
16455 */
16456@@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16457 };
16458
16459 /* second table for DMI checks that should run after early-quirks */
16460-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16461+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16462 /*
16463 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16464 * which includes some code which overrides all temperature
16465diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16466index d5e0d71..6533e08 100644
16467--- a/arch/x86/kernel/acpi/sleep.c
16468+++ b/arch/x86/kernel/acpi/sleep.c
16469@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16470 #else /* CONFIG_64BIT */
16471 #ifdef CONFIG_SMP
16472 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16473+
16474+ pax_open_kernel();
16475 early_gdt_descr.address =
16476 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16477+ pax_close_kernel();
16478+
16479 initial_gs = per_cpu_offset(smp_processor_id());
16480 #endif
16481 initial_code = (unsigned long)wakeup_long64;
16482diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16483index 13ab720..95d5442 100644
16484--- a/arch/x86/kernel/acpi/wakeup_32.S
16485+++ b/arch/x86/kernel/acpi/wakeup_32.S
16486@@ -30,13 +30,11 @@ wakeup_pmode_return:
16487 # and restore the stack ... but you need gdt for this to work
16488 movl saved_context_esp, %esp
16489
16490- movl %cs:saved_magic, %eax
16491- cmpl $0x12345678, %eax
16492+ cmpl $0x12345678, saved_magic
16493 jne bogus_magic
16494
16495 # jump to place where we left off
16496- movl saved_eip, %eax
16497- jmp *%eax
16498+ jmp *(saved_eip)
16499
16500 bogus_magic:
16501 jmp bogus_magic
16502diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16503index ef5ccca..bd83949 100644
16504--- a/arch/x86/kernel/alternative.c
16505+++ b/arch/x86/kernel/alternative.c
16506@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16507 */
16508 for (a = start; a < end; a++) {
16509 instr = (u8 *)&a->instr_offset + a->instr_offset;
16510+
16511+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16512+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16513+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16514+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16515+#endif
16516+
16517 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16518 BUG_ON(a->replacementlen > a->instrlen);
16519 BUG_ON(a->instrlen > sizeof(insnbuf));
16520@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16521 for (poff = start; poff < end; poff++) {
16522 u8 *ptr = (u8 *)poff + *poff;
16523
16524+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16525+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16526+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16527+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16528+#endif
16529+
16530 if (!*poff || ptr < text || ptr >= text_end)
16531 continue;
16532 /* turn DS segment override prefix into lock prefix */
16533- if (*ptr == 0x3e)
16534+ if (*ktla_ktva(ptr) == 0x3e)
16535 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16536 }
16537 mutex_unlock(&text_mutex);
16538@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16539 for (poff = start; poff < end; poff++) {
16540 u8 *ptr = (u8 *)poff + *poff;
16541
16542+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16543+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16544+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16545+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16546+#endif
16547+
16548 if (!*poff || ptr < text || ptr >= text_end)
16549 continue;
16550 /* turn lock prefix into DS segment override prefix */
16551- if (*ptr == 0xf0)
16552+ if (*ktla_ktva(ptr) == 0xf0)
16553 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16554 }
16555 mutex_unlock(&text_mutex);
16556@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16557
16558 BUG_ON(p->len > MAX_PATCH_LEN);
16559 /* prep the buffer with the original instructions */
16560- memcpy(insnbuf, p->instr, p->len);
16561+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16562 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16563 (unsigned long)p->instr, p->len);
16564
16565@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16566 if (!uniproc_patched || num_possible_cpus() == 1)
16567 free_init_pages("SMP alternatives",
16568 (unsigned long)__smp_locks,
16569- (unsigned long)__smp_locks_end);
16570+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16571 #endif
16572
16573 apply_paravirt(__parainstructions, __parainstructions_end);
16574@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16575 * instructions. And on the local CPU you need to be protected again NMI or MCE
16576 * handlers seeing an inconsistent instruction while you patch.
16577 */
16578-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16579+void *__kprobes text_poke_early(void *addr, const void *opcode,
16580 size_t len)
16581 {
16582 unsigned long flags;
16583 local_irq_save(flags);
16584- memcpy(addr, opcode, len);
16585+
16586+ pax_open_kernel();
16587+ memcpy(ktla_ktva(addr), opcode, len);
16588 sync_core();
16589+ pax_close_kernel();
16590+
16591 local_irq_restore(flags);
16592 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16593 that causes hangs on some VIA CPUs. */
16594@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16595 */
16596 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16597 {
16598- unsigned long flags;
16599- char *vaddr;
16600+ unsigned char *vaddr = ktla_ktva(addr);
16601 struct page *pages[2];
16602- int i;
16603+ size_t i;
16604
16605 if (!core_kernel_text((unsigned long)addr)) {
16606- pages[0] = vmalloc_to_page(addr);
16607- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16608+ pages[0] = vmalloc_to_page(vaddr);
16609+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16610 } else {
16611- pages[0] = virt_to_page(addr);
16612+ pages[0] = virt_to_page(vaddr);
16613 WARN_ON(!PageReserved(pages[0]));
16614- pages[1] = virt_to_page(addr + PAGE_SIZE);
16615+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16616 }
16617 BUG_ON(!pages[0]);
16618- local_irq_save(flags);
16619- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16620- if (pages[1])
16621- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16622- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16623- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16624- clear_fixmap(FIX_TEXT_POKE0);
16625- if (pages[1])
16626- clear_fixmap(FIX_TEXT_POKE1);
16627- local_flush_tlb();
16628- sync_core();
16629- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16630- that causes hangs on some VIA CPUs. */
16631+ text_poke_early(addr, opcode, len);
16632 for (i = 0; i < len; i++)
16633- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16634- local_irq_restore(flags);
16635+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16636 return addr;
16637 }
16638
16639diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16640index cbf5121..812b537 100644
16641--- a/arch/x86/kernel/apic/apic.c
16642+++ b/arch/x86/kernel/apic/apic.c
16643@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16644 /*
16645 * Debug level, exported for io_apic.c
16646 */
16647-unsigned int apic_verbosity;
16648+int apic_verbosity;
16649
16650 int pic_mode;
16651
16652@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16653 apic_write(APIC_ESR, 0);
16654 v1 = apic_read(APIC_ESR);
16655 ack_APIC_irq();
16656- atomic_inc(&irq_err_count);
16657+ atomic_inc_unchecked(&irq_err_count);
16658
16659 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16660 smp_processor_id(), v0 , v1);
16661diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16662index 00c77cf..2dc6a2d 100644
16663--- a/arch/x86/kernel/apic/apic_flat_64.c
16664+++ b/arch/x86/kernel/apic/apic_flat_64.c
16665@@ -157,7 +157,7 @@ static int flat_probe(void)
16666 return 1;
16667 }
16668
16669-static struct apic apic_flat = {
16670+static struct apic apic_flat __read_only = {
16671 .name = "flat",
16672 .probe = flat_probe,
16673 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16674@@ -271,7 +271,7 @@ static int physflat_probe(void)
16675 return 0;
16676 }
16677
16678-static struct apic apic_physflat = {
16679+static struct apic apic_physflat __read_only = {
16680
16681 .name = "physical flat",
16682 .probe = physflat_probe,
16683diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16684index e145f28..2752888 100644
16685--- a/arch/x86/kernel/apic/apic_noop.c
16686+++ b/arch/x86/kernel/apic/apic_noop.c
16687@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16688 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16689 }
16690
16691-struct apic apic_noop = {
16692+struct apic apic_noop __read_only = {
16693 .name = "noop",
16694 .probe = noop_probe,
16695 .acpi_madt_oem_check = NULL,
16696diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16697index d50e364..543bee3 100644
16698--- a/arch/x86/kernel/apic/bigsmp_32.c
16699+++ b/arch/x86/kernel/apic/bigsmp_32.c
16700@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16701 return dmi_bigsmp;
16702 }
16703
16704-static struct apic apic_bigsmp = {
16705+static struct apic apic_bigsmp __read_only = {
16706
16707 .name = "bigsmp",
16708 .probe = probe_bigsmp,
16709diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16710index 0874799..a7a7892 100644
16711--- a/arch/x86/kernel/apic/es7000_32.c
16712+++ b/arch/x86/kernel/apic/es7000_32.c
16713@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16714 return ret && es7000_apic_is_cluster();
16715 }
16716
16717-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16718-static struct apic __refdata apic_es7000_cluster = {
16719+static struct apic apic_es7000_cluster __read_only = {
16720
16721 .name = "es7000",
16722 .probe = probe_es7000,
16723@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16724 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16725 };
16726
16727-static struct apic __refdata apic_es7000 = {
16728+static struct apic apic_es7000 __read_only = {
16729
16730 .name = "es7000",
16731 .probe = probe_es7000,
16732diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16733index b739d39..aebc14c 100644
16734--- a/arch/x86/kernel/apic/io_apic.c
16735+++ b/arch/x86/kernel/apic/io_apic.c
16736@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16737 }
16738 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16739
16740-void lock_vector_lock(void)
16741+void lock_vector_lock(void) __acquires(vector_lock)
16742 {
16743 /* Used to the online set of cpus does not change
16744 * during assign_irq_vector.
16745@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16746 raw_spin_lock(&vector_lock);
16747 }
16748
16749-void unlock_vector_lock(void)
16750+void unlock_vector_lock(void) __releases(vector_lock)
16751 {
16752 raw_spin_unlock(&vector_lock);
16753 }
16754@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16755 ack_APIC_irq();
16756 }
16757
16758-atomic_t irq_mis_count;
16759+atomic_unchecked_t irq_mis_count;
16760
16761 #ifdef CONFIG_GENERIC_PENDING_IRQ
16762 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16763@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16764 * at the cpu.
16765 */
16766 if (!(v & (1 << (i & 0x1f)))) {
16767- atomic_inc(&irq_mis_count);
16768+ atomic_inc_unchecked(&irq_mis_count);
16769
16770 eoi_ioapic_irq(irq, cfg);
16771 }
16772@@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
16773
16774 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
16775 {
16776- chip->irq_print_chip = ir_print_prefix;
16777- chip->irq_ack = ir_ack_apic_edge;
16778- chip->irq_eoi = ir_ack_apic_level;
16779+ pax_open_kernel();
16780+ *(void **)&chip->irq_print_chip = ir_print_prefix;
16781+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
16782+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
16783
16784- chip->irq_set_affinity = set_remapped_irq_affinity;
16785+ *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
16786+ pax_close_kernel();
16787 }
16788 #endif /* CONFIG_IRQ_REMAP */
16789
16790diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16791index d661ee9..791fd33 100644
16792--- a/arch/x86/kernel/apic/numaq_32.c
16793+++ b/arch/x86/kernel/apic/numaq_32.c
16794@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16795 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16796 }
16797
16798-/* Use __refdata to keep false positive warning calm. */
16799-static struct apic __refdata apic_numaq = {
16800+static struct apic apic_numaq __read_only = {
16801
16802 .name = "NUMAQ",
16803 .probe = probe_numaq,
16804diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16805index eb35ef9..f184a21 100644
16806--- a/arch/x86/kernel/apic/probe_32.c
16807+++ b/arch/x86/kernel/apic/probe_32.c
16808@@ -72,7 +72,7 @@ static int probe_default(void)
16809 return 1;
16810 }
16811
16812-static struct apic apic_default = {
16813+static struct apic apic_default __read_only = {
16814
16815 .name = "default",
16816 .probe = probe_default,
16817diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16818index 77c95c0..434f8a4 100644
16819--- a/arch/x86/kernel/apic/summit_32.c
16820+++ b/arch/x86/kernel/apic/summit_32.c
16821@@ -486,7 +486,7 @@ void setup_summit(void)
16822 }
16823 #endif
16824
16825-static struct apic apic_summit = {
16826+static struct apic apic_summit __read_only = {
16827
16828 .name = "summit",
16829 .probe = probe_summit,
16830diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16831index c88baa4..757aee1 100644
16832--- a/arch/x86/kernel/apic/x2apic_cluster.c
16833+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16834@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16835 return notifier_from_errno(err);
16836 }
16837
16838-static struct notifier_block __refdata x2apic_cpu_notifier = {
16839+static struct notifier_block x2apic_cpu_notifier = {
16840 .notifier_call = update_clusterinfo,
16841 };
16842
16843@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16844 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16845 }
16846
16847-static struct apic apic_x2apic_cluster = {
16848+static struct apic apic_x2apic_cluster __read_only = {
16849
16850 .name = "cluster x2apic",
16851 .probe = x2apic_cluster_probe,
16852diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16853index 562a76d..a003c0f 100644
16854--- a/arch/x86/kernel/apic/x2apic_phys.c
16855+++ b/arch/x86/kernel/apic/x2apic_phys.c
16856@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16857 return apic == &apic_x2apic_phys;
16858 }
16859
16860-static struct apic apic_x2apic_phys = {
16861+static struct apic apic_x2apic_phys __read_only = {
16862
16863 .name = "physical x2apic",
16864 .probe = x2apic_phys_probe,
16865diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16866index 8cfade9..b9d04fc 100644
16867--- a/arch/x86/kernel/apic/x2apic_uv_x.c
16868+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16869@@ -333,7 +333,7 @@ static int uv_probe(void)
16870 return apic == &apic_x2apic_uv_x;
16871 }
16872
16873-static struct apic __refdata apic_x2apic_uv_x = {
16874+static struct apic apic_x2apic_uv_x __read_only = {
16875
16876 .name = "UV large system",
16877 .probe = uv_probe,
16878diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16879index d65464e..1035d31 100644
16880--- a/arch/x86/kernel/apm_32.c
16881+++ b/arch/x86/kernel/apm_32.c
16882@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16883 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16884 * even though they are called in protected mode.
16885 */
16886-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16887+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16888 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16889
16890 static const char driver_version[] = "1.16ac"; /* no spaces */
16891@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16892 BUG_ON(cpu != 0);
16893 gdt = get_cpu_gdt_table(cpu);
16894 save_desc_40 = gdt[0x40 / 8];
16895+
16896+ pax_open_kernel();
16897 gdt[0x40 / 8] = bad_bios_desc;
16898+ pax_close_kernel();
16899
16900 apm_irq_save(flags);
16901 APM_DO_SAVE_SEGS;
16902@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16903 &call->esi);
16904 APM_DO_RESTORE_SEGS;
16905 apm_irq_restore(flags);
16906+
16907+ pax_open_kernel();
16908 gdt[0x40 / 8] = save_desc_40;
16909+ pax_close_kernel();
16910+
16911 put_cpu();
16912
16913 return call->eax & 0xff;
16914@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16915 BUG_ON(cpu != 0);
16916 gdt = get_cpu_gdt_table(cpu);
16917 save_desc_40 = gdt[0x40 / 8];
16918+
16919+ pax_open_kernel();
16920 gdt[0x40 / 8] = bad_bios_desc;
16921+ pax_close_kernel();
16922
16923 apm_irq_save(flags);
16924 APM_DO_SAVE_SEGS;
16925@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16926 &call->eax);
16927 APM_DO_RESTORE_SEGS;
16928 apm_irq_restore(flags);
16929+
16930+ pax_open_kernel();
16931 gdt[0x40 / 8] = save_desc_40;
16932+ pax_close_kernel();
16933+
16934 put_cpu();
16935 return error;
16936 }
16937@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16938 * code to that CPU.
16939 */
16940 gdt = get_cpu_gdt_table(0);
16941+
16942+ pax_open_kernel();
16943 set_desc_base(&gdt[APM_CS >> 3],
16944 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16945 set_desc_base(&gdt[APM_CS_16 >> 3],
16946 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16947 set_desc_base(&gdt[APM_DS >> 3],
16948 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16949+ pax_close_kernel();
16950
16951 proc_create("apm", 0, NULL, &apm_file_ops);
16952
16953diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16954index 2861082..6d4718e 100644
16955--- a/arch/x86/kernel/asm-offsets.c
16956+++ b/arch/x86/kernel/asm-offsets.c
16957@@ -33,6 +33,8 @@ void common(void) {
16958 OFFSET(TI_status, thread_info, status);
16959 OFFSET(TI_addr_limit, thread_info, addr_limit);
16960 OFFSET(TI_preempt_count, thread_info, preempt_count);
16961+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16962+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16963
16964 BLANK();
16965 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16966@@ -53,8 +55,26 @@ void common(void) {
16967 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16968 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16969 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16970+
16971+#ifdef CONFIG_PAX_KERNEXEC
16972+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16973 #endif
16974
16975+#ifdef CONFIG_PAX_MEMORY_UDEREF
16976+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16977+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16978+#ifdef CONFIG_X86_64
16979+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16980+#endif
16981+#endif
16982+
16983+#endif
16984+
16985+ BLANK();
16986+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16987+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16988+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16989+
16990 #ifdef CONFIG_XEN
16991 BLANK();
16992 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16993diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16994index 1b4754f..fbb4227 100644
16995--- a/arch/x86/kernel/asm-offsets_64.c
16996+++ b/arch/x86/kernel/asm-offsets_64.c
16997@@ -76,6 +76,7 @@ int main(void)
16998 BLANK();
16999 #undef ENTRY
17000
17001+ DEFINE(TSS_size, sizeof(struct tss_struct));
17002 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17003 BLANK();
17004
17005diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17006index a0e067d..9c7db16 100644
17007--- a/arch/x86/kernel/cpu/Makefile
17008+++ b/arch/x86/kernel/cpu/Makefile
17009@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17010 CFLAGS_REMOVE_perf_event.o = -pg
17011 endif
17012
17013-# Make sure load_percpu_segment has no stackprotector
17014-nostackp := $(call cc-option, -fno-stack-protector)
17015-CFLAGS_common.o := $(nostackp)
17016-
17017 obj-y := intel_cacheinfo.o scattered.o topology.o
17018 obj-y += proc.o capflags.o powerflags.o common.o
17019 obj-y += vmware.o hypervisor.o mshyperv.o
17020diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17021index 15239ff..e23e04e 100644
17022--- a/arch/x86/kernel/cpu/amd.c
17023+++ b/arch/x86/kernel/cpu/amd.c
17024@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17025 unsigned int size)
17026 {
17027 /* AMD errata T13 (order #21922) */
17028- if ((c->x86 == 6)) {
17029+ if (c->x86 == 6) {
17030 /* Duron Rev A0 */
17031 if (c->x86_model == 3 && c->x86_mask == 0)
17032 size = 64;
17033diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17034index 9c3ab43..51e6366 100644
17035--- a/arch/x86/kernel/cpu/common.c
17036+++ b/arch/x86/kernel/cpu/common.c
17037@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17038
17039 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17040
17041-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17042-#ifdef CONFIG_X86_64
17043- /*
17044- * We need valid kernel segments for data and code in long mode too
17045- * IRET will check the segment types kkeil 2000/10/28
17046- * Also sysret mandates a special GDT layout
17047- *
17048- * TLS descriptors are currently at a different place compared to i386.
17049- * Hopefully nobody expects them at a fixed place (Wine?)
17050- */
17051- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17052- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17053- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17054- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17055- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17056- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17057-#else
17058- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17059- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17060- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17061- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17062- /*
17063- * Segments used for calling PnP BIOS have byte granularity.
17064- * They code segments and data segments have fixed 64k limits,
17065- * the transfer segment sizes are set at run time.
17066- */
17067- /* 32-bit code */
17068- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17069- /* 16-bit code */
17070- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17071- /* 16-bit data */
17072- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17073- /* 16-bit data */
17074- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17075- /* 16-bit data */
17076- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17077- /*
17078- * The APM segments have byte granularity and their bases
17079- * are set at run time. All have 64k limits.
17080- */
17081- /* 32-bit code */
17082- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17083- /* 16-bit code */
17084- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17085- /* data */
17086- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17087-
17088- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17089- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17090- GDT_STACK_CANARY_INIT
17091-#endif
17092-} };
17093-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17094-
17095 static int __init x86_xsave_setup(char *s)
17096 {
17097 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17098@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
17099 {
17100 struct desc_ptr gdt_descr;
17101
17102- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17103+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17104 gdt_descr.size = GDT_SIZE - 1;
17105 load_gdt(&gdt_descr);
17106 /* Reload the per-cpu base */
17107@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17108 /* Filter out anything that depends on CPUID levels we don't have */
17109 filter_cpuid_features(c, true);
17110
17111+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17112+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17113+#endif
17114+
17115 /* If the model name is still unset, do table lookup. */
17116 if (!c->x86_model_id[0]) {
17117 const char *p;
17118@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
17119 }
17120 __setup("clearcpuid=", setup_disablecpuid);
17121
17122+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17123+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17124+
17125 #ifdef CONFIG_X86_64
17126 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17127-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17128- (unsigned long) nmi_idt_table };
17129+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17130
17131 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17132 irq_stack_union) __aligned(PAGE_SIZE);
17133@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17134 EXPORT_PER_CPU_SYMBOL(current_task);
17135
17136 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17137- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17138+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17139 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17140
17141 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17142@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
17143 int i;
17144
17145 cpu = stack_smp_processor_id();
17146- t = &per_cpu(init_tss, cpu);
17147+ t = init_tss + cpu;
17148 oist = &per_cpu(orig_ist, cpu);
17149
17150 #ifdef CONFIG_NUMA
17151@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
17152 switch_to_new_gdt(cpu);
17153 loadsegment(fs, 0);
17154
17155- load_idt((const struct desc_ptr *)&idt_descr);
17156+ load_idt(&idt_descr);
17157
17158 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17159 syscall_init();
17160@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
17161 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17162 barrier();
17163
17164- x86_configure_nx();
17165 enable_x2apic();
17166
17167 /*
17168@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
17169 {
17170 int cpu = smp_processor_id();
17171 struct task_struct *curr = current;
17172- struct tss_struct *t = &per_cpu(init_tss, cpu);
17173+ struct tss_struct *t = init_tss + cpu;
17174 struct thread_struct *thread = &curr->thread;
17175
17176 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
17177diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
17178index fcaabd0..7b55a26 100644
17179--- a/arch/x86/kernel/cpu/intel.c
17180+++ b/arch/x86/kernel/cpu/intel.c
17181@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
17182 * Update the IDT descriptor and reload the IDT so that
17183 * it uses the read-only mapped virtual address.
17184 */
17185- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
17186+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
17187 load_idt(&idt_descr);
17188 }
17189 #endif
17190diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17191index 84c1309..39b7224 100644
17192--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17193+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17194@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17195 };
17196
17197 #ifdef CONFIG_AMD_NB
17198+static struct attribute *default_attrs_amd_nb[] = {
17199+ &type.attr,
17200+ &level.attr,
17201+ &coherency_line_size.attr,
17202+ &physical_line_partition.attr,
17203+ &ways_of_associativity.attr,
17204+ &number_of_sets.attr,
17205+ &size.attr,
17206+ &shared_cpu_map.attr,
17207+ &shared_cpu_list.attr,
17208+ NULL,
17209+ NULL,
17210+ NULL,
17211+ NULL
17212+};
17213+
17214 static struct attribute ** __cpuinit amd_l3_attrs(void)
17215 {
17216 static struct attribute **attrs;
17217@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17218
17219 n = ARRAY_SIZE(default_attrs);
17220
17221- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17222- n += 2;
17223-
17224- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17225- n += 1;
17226-
17227- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17228- if (attrs == NULL)
17229- return attrs = default_attrs;
17230-
17231- for (n = 0; default_attrs[n]; n++)
17232- attrs[n] = default_attrs[n];
17233+ attrs = default_attrs_amd_nb;
17234
17235 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17236 attrs[n++] = &cache_disable_0.attr;
17237@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17238 .default_attrs = default_attrs,
17239 };
17240
17241+#ifdef CONFIG_AMD_NB
17242+static struct kobj_type ktype_cache_amd_nb = {
17243+ .sysfs_ops = &sysfs_ops,
17244+ .default_attrs = default_attrs_amd_nb,
17245+};
17246+#endif
17247+
17248 static struct kobj_type ktype_percpu_entry = {
17249 .sysfs_ops = &sysfs_ops,
17250 };
17251@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17252 return retval;
17253 }
17254
17255+#ifdef CONFIG_AMD_NB
17256+ amd_l3_attrs();
17257+#endif
17258+
17259 for (i = 0; i < num_cache_leaves; i++) {
17260+ struct kobj_type *ktype;
17261+
17262 this_object = INDEX_KOBJECT_PTR(cpu, i);
17263 this_object->cpu = cpu;
17264 this_object->index = i;
17265
17266 this_leaf = CPUID4_INFO_IDX(cpu, i);
17267
17268- ktype_cache.default_attrs = default_attrs;
17269+ ktype = &ktype_cache;
17270 #ifdef CONFIG_AMD_NB
17271 if (this_leaf->base.nb)
17272- ktype_cache.default_attrs = amd_l3_attrs();
17273+ ktype = &ktype_cache_amd_nb;
17274 #endif
17275 retval = kobject_init_and_add(&(this_object->kobj),
17276- &ktype_cache,
17277+ ktype,
17278 per_cpu(ici_cache_kobject, cpu),
17279 "index%1lu", i);
17280 if (unlikely(retval)) {
17281@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17282 return NOTIFY_OK;
17283 }
17284
17285-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17286+static struct notifier_block cacheinfo_cpu_notifier = {
17287 .notifier_call = cacheinfo_cpu_callback,
17288 };
17289
17290diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17291index 80dbda8..be16652 100644
17292--- a/arch/x86/kernel/cpu/mcheck/mce.c
17293+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17294@@ -45,6 +45,7 @@
17295 #include <asm/processor.h>
17296 #include <asm/mce.h>
17297 #include <asm/msr.h>
17298+#include <asm/local.h>
17299
17300 #include "mce-internal.h"
17301
17302@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17303 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17304 m->cs, m->ip);
17305
17306- if (m->cs == __KERNEL_CS)
17307+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17308 print_symbol("{%s}", m->ip);
17309 pr_cont("\n");
17310 }
17311@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17312
17313 #define PANIC_TIMEOUT 5 /* 5 seconds */
17314
17315-static atomic_t mce_paniced;
17316+static atomic_unchecked_t mce_paniced;
17317
17318 static int fake_panic;
17319-static atomic_t mce_fake_paniced;
17320+static atomic_unchecked_t mce_fake_paniced;
17321
17322 /* Panic in progress. Enable interrupts and wait for final IPI */
17323 static void wait_for_panic(void)
17324@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17325 /*
17326 * Make sure only one CPU runs in machine check panic
17327 */
17328- if (atomic_inc_return(&mce_paniced) > 1)
17329+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17330 wait_for_panic();
17331 barrier();
17332
17333@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17334 console_verbose();
17335 } else {
17336 /* Don't log too much for fake panic */
17337- if (atomic_inc_return(&mce_fake_paniced) > 1)
17338+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17339 return;
17340 }
17341 /* First print corrected ones that are still unlogged */
17342@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
17343 * might have been modified by someone else.
17344 */
17345 rmb();
17346- if (atomic_read(&mce_paniced))
17347+ if (atomic_read_unchecked(&mce_paniced))
17348 wait_for_panic();
17349 if (!mca_cfg.monarch_timeout)
17350 goto out;
17351@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17352 }
17353
17354 /* Call the installed machine check handler for this CPU setup. */
17355-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17356+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17357 unexpected_machine_check;
17358
17359 /*
17360@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17361 return;
17362 }
17363
17364+ pax_open_kernel();
17365 machine_check_vector = do_machine_check;
17366+ pax_close_kernel();
17367
17368 __mcheck_cpu_init_generic();
17369 __mcheck_cpu_init_vendor(c);
17370@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17371 */
17372
17373 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17374-static int mce_chrdev_open_count; /* #times opened */
17375+static local_t mce_chrdev_open_count; /* #times opened */
17376 static int mce_chrdev_open_exclu; /* already open exclusive? */
17377
17378 static int mce_chrdev_open(struct inode *inode, struct file *file)
17379@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17380 spin_lock(&mce_chrdev_state_lock);
17381
17382 if (mce_chrdev_open_exclu ||
17383- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17384+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17385 spin_unlock(&mce_chrdev_state_lock);
17386
17387 return -EBUSY;
17388@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17389
17390 if (file->f_flags & O_EXCL)
17391 mce_chrdev_open_exclu = 1;
17392- mce_chrdev_open_count++;
17393+ local_inc(&mce_chrdev_open_count);
17394
17395 spin_unlock(&mce_chrdev_state_lock);
17396
17397@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17398 {
17399 spin_lock(&mce_chrdev_state_lock);
17400
17401- mce_chrdev_open_count--;
17402+ local_dec(&mce_chrdev_open_count);
17403 mce_chrdev_open_exclu = 0;
17404
17405 spin_unlock(&mce_chrdev_state_lock);
17406@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17407 return NOTIFY_OK;
17408 }
17409
17410-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17411+static struct notifier_block mce_cpu_notifier = {
17412 .notifier_call = mce_cpu_callback,
17413 };
17414
17415@@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17416
17417 for (i = 0; i < mca_cfg.banks; i++) {
17418 struct mce_bank *b = &mce_banks[i];
17419- struct device_attribute *a = &b->attr;
17420+ device_attribute_no_const *a = &b->attr;
17421
17422 sysfs_attr_init(&a->attr);
17423 a->attr.name = b->attrname;
17424@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17425 static void mce_reset(void)
17426 {
17427 cpu_missing = 0;
17428- atomic_set(&mce_fake_paniced, 0);
17429+ atomic_set_unchecked(&mce_fake_paniced, 0);
17430 atomic_set(&mce_executing, 0);
17431 atomic_set(&mce_callin, 0);
17432 atomic_set(&global_nwo, 0);
17433diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17434index 2d5454c..51987eb 100644
17435--- a/arch/x86/kernel/cpu/mcheck/p5.c
17436+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17437@@ -11,6 +11,7 @@
17438 #include <asm/processor.h>
17439 #include <asm/mce.h>
17440 #include <asm/msr.h>
17441+#include <asm/pgtable.h>
17442
17443 /* By default disabled */
17444 int mce_p5_enabled __read_mostly;
17445@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17446 if (!cpu_has(c, X86_FEATURE_MCE))
17447 return;
17448
17449+ pax_open_kernel();
17450 machine_check_vector = pentium_machine_check;
17451+ pax_close_kernel();
17452 /* Make sure the vector pointer is visible before we enable MCEs: */
17453 wmb();
17454
17455diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17456index 47a1870..8c019a7 100644
17457--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17458+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17459@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17460 return notifier_from_errno(err);
17461 }
17462
17463-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17464+static struct notifier_block thermal_throttle_cpu_notifier =
17465 {
17466 .notifier_call = thermal_throttle_cpu_callback,
17467 };
17468diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17469index 2d7998f..17c9de1 100644
17470--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17471+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17472@@ -10,6 +10,7 @@
17473 #include <asm/processor.h>
17474 #include <asm/mce.h>
17475 #include <asm/msr.h>
17476+#include <asm/pgtable.h>
17477
17478 /* Machine check handler for WinChip C6: */
17479 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17480@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17481 {
17482 u32 lo, hi;
17483
17484+ pax_open_kernel();
17485 machine_check_vector = winchip_machine_check;
17486+ pax_close_kernel();
17487 /* Make sure the vector pointer is visible before we enable MCEs: */
17488 wmb();
17489
17490diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17491index 726bf96..81f0526 100644
17492--- a/arch/x86/kernel/cpu/mtrr/main.c
17493+++ b/arch/x86/kernel/cpu/mtrr/main.c
17494@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17495 u64 size_or_mask, size_and_mask;
17496 static bool mtrr_aps_delayed_init;
17497
17498-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17499+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17500
17501 const struct mtrr_ops *mtrr_if;
17502
17503diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17504index df5e41f..816c719 100644
17505--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17506+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17507@@ -25,7 +25,7 @@ struct mtrr_ops {
17508 int (*validate_add_page)(unsigned long base, unsigned long size,
17509 unsigned int type);
17510 int (*have_wrcomb)(void);
17511-};
17512+} __do_const;
17513
17514 extern int generic_get_free_region(unsigned long base, unsigned long size,
17515 int replace_reg);
17516diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17517index 6774c17..72c1b22 100644
17518--- a/arch/x86/kernel/cpu/perf_event.c
17519+++ b/arch/x86/kernel/cpu/perf_event.c
17520@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17521 pr_info("no hardware sampling interrupt available.\n");
17522 }
17523
17524-static struct attribute_group x86_pmu_format_group = {
17525+static attribute_group_no_const x86_pmu_format_group = {
17526 .name = "format",
17527 .attrs = NULL,
17528 };
17529@@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17530 struct perf_pmu_events_attr {
17531 struct device_attribute attr;
17532 u64 id;
17533-};
17534+} __do_const;
17535
17536 /*
17537 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17538@@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17539 NULL,
17540 };
17541
17542-static struct attribute_group x86_pmu_events_group = {
17543+static attribute_group_no_const x86_pmu_events_group = {
17544 .name = "events",
17545 .attrs = events_attr,
17546 };
17547@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17548 if (idx > GDT_ENTRIES)
17549 return 0;
17550
17551- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17552+ desc = get_cpu_gdt_table(smp_processor_id());
17553 }
17554
17555 return get_desc_base(desc + idx);
17556@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17557 break;
17558
17559 perf_callchain_store(entry, frame.return_address);
17560- fp = frame.next_frame;
17561+ fp = (const void __force_user *)frame.next_frame;
17562 }
17563 }
17564
17565diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17566index 4914e94..60b06e3 100644
17567--- a/arch/x86/kernel/cpu/perf_event_intel.c
17568+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17569@@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17570 * v2 and above have a perf capabilities MSR
17571 */
17572 if (version > 1) {
17573- u64 capabilities;
17574+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17575
17576- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17577- x86_pmu.intel_cap.capabilities = capabilities;
17578+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17579+ x86_pmu.intel_cap.capabilities = capabilities;
17580 }
17581
17582 intel_ds_init();
17583diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17584index b43200d..d235b3e 100644
17585--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17586+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17587@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17588 static int __init uncore_type_init(struct intel_uncore_type *type)
17589 {
17590 struct intel_uncore_pmu *pmus;
17591- struct attribute_group *events_group;
17592+ attribute_group_no_const *attr_group;
17593 struct attribute **attrs;
17594 int i, j;
17595
17596@@ -2455,19 +2455,19 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
17597 while (type->event_descs[i].attr.attr.name)
17598 i++;
17599
17600- events_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
17601- sizeof(*events_group), GFP_KERNEL);
17602- if (!events_group)
17603+ attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
17604+ sizeof(*attr_group), GFP_KERNEL);
17605+ if (!attr_group)
17606 goto fail;
17607
17608- attrs = (struct attribute **)(events_group + 1);
17609- events_group->name = "events";
17610- events_group->attrs = attrs;
17611+ attrs = (struct attribute **)(attr_group + 1);
17612+ attr_group->name = "events";
17613+ attr_group->attrs = attrs;
17614
17615 for (j = 0; j < i; j++)
17616 attrs[j] = &type->event_descs[j].attr.attr;
17617
17618- type->events_group = events_group;
17619+ type->events_group = attr_group;
17620 }
17621
17622 type->pmu_group = &uncore_pmu_attr_group;
17623@@ -2826,7 +2826,7 @@ static int
17624 return NOTIFY_OK;
17625 }
17626
17627-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17628+static struct notifier_block uncore_cpu_nb = {
17629 .notifier_call = uncore_cpu_notifier,
17630 /*
17631 * to migrate uncore events, our notifier should be executed
17632diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17633index e68a455..975a932 100644
17634--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17635+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17636@@ -428,7 +428,7 @@ struct intel_uncore_box {
17637 struct uncore_event_desc {
17638 struct kobj_attribute attr;
17639 const char *config;
17640-};
17641+} __do_const;
17642
17643 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17644 { \
17645diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17646index 60c7891..9e911d3 100644
17647--- a/arch/x86/kernel/cpuid.c
17648+++ b/arch/x86/kernel/cpuid.c
17649@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17650 return notifier_from_errno(err);
17651 }
17652
17653-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17654+static struct notifier_block cpuid_class_cpu_notifier =
17655 {
17656 .notifier_call = cpuid_class_cpu_callback,
17657 };
17658diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17659index 74467fe..18793d5 100644
17660--- a/arch/x86/kernel/crash.c
17661+++ b/arch/x86/kernel/crash.c
17662@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17663 {
17664 #ifdef CONFIG_X86_32
17665 struct pt_regs fixed_regs;
17666-#endif
17667
17668-#ifdef CONFIG_X86_32
17669- if (!user_mode_vm(regs)) {
17670+ if (!user_mode(regs)) {
17671 crash_fixup_ss_esp(&fixed_regs, regs);
17672 regs = &fixed_regs;
17673 }
17674diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17675index 37250fe..bf2ec74 100644
17676--- a/arch/x86/kernel/doublefault_32.c
17677+++ b/arch/x86/kernel/doublefault_32.c
17678@@ -11,7 +11,7 @@
17679
17680 #define DOUBLEFAULT_STACKSIZE (1024)
17681 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17682-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17683+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17684
17685 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17686
17687@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17688 unsigned long gdt, tss;
17689
17690 store_gdt(&gdt_desc);
17691- gdt = gdt_desc.address;
17692+ gdt = (unsigned long)gdt_desc.address;
17693
17694 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17695
17696@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17697 /* 0x2 bit is always set */
17698 .flags = X86_EFLAGS_SF | 0x2,
17699 .sp = STACK_START,
17700- .es = __USER_DS,
17701+ .es = __KERNEL_DS,
17702 .cs = __KERNEL_CS,
17703 .ss = __KERNEL_DS,
17704- .ds = __USER_DS,
17705+ .ds = __KERNEL_DS,
17706 .fs = __KERNEL_PERCPU,
17707
17708 .__cr3 = __pa_nodebug(swapper_pg_dir),
17709diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17710index ae42418b..787c16b 100644
17711--- a/arch/x86/kernel/dumpstack.c
17712+++ b/arch/x86/kernel/dumpstack.c
17713@@ -2,6 +2,9 @@
17714 * Copyright (C) 1991, 1992 Linus Torvalds
17715 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17716 */
17717+#ifdef CONFIG_GRKERNSEC_HIDESYM
17718+#define __INCLUDED_BY_HIDESYM 1
17719+#endif
17720 #include <linux/kallsyms.h>
17721 #include <linux/kprobes.h>
17722 #include <linux/uaccess.h>
17723@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17724 static void
17725 print_ftrace_graph_addr(unsigned long addr, void *data,
17726 const struct stacktrace_ops *ops,
17727- struct thread_info *tinfo, int *graph)
17728+ struct task_struct *task, int *graph)
17729 {
17730- struct task_struct *task;
17731 unsigned long ret_addr;
17732 int index;
17733
17734 if (addr != (unsigned long)return_to_handler)
17735 return;
17736
17737- task = tinfo->task;
17738 index = task->curr_ret_stack;
17739
17740 if (!task->ret_stack || index < *graph)
17741@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17742 static inline void
17743 print_ftrace_graph_addr(unsigned long addr, void *data,
17744 const struct stacktrace_ops *ops,
17745- struct thread_info *tinfo, int *graph)
17746+ struct task_struct *task, int *graph)
17747 { }
17748 #endif
17749
17750@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17751 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17752 */
17753
17754-static inline int valid_stack_ptr(struct thread_info *tinfo,
17755- void *p, unsigned int size, void *end)
17756+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17757 {
17758- void *t = tinfo;
17759 if (end) {
17760 if (p < end && p >= (end-THREAD_SIZE))
17761 return 1;
17762@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17763 }
17764
17765 unsigned long
17766-print_context_stack(struct thread_info *tinfo,
17767+print_context_stack(struct task_struct *task, void *stack_start,
17768 unsigned long *stack, unsigned long bp,
17769 const struct stacktrace_ops *ops, void *data,
17770 unsigned long *end, int *graph)
17771 {
17772 struct stack_frame *frame = (struct stack_frame *)bp;
17773
17774- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17775+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17776 unsigned long addr;
17777
17778 addr = *stack;
17779@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17780 } else {
17781 ops->address(data, addr, 0);
17782 }
17783- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17784+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17785 }
17786 stack++;
17787 }
17788@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17789 EXPORT_SYMBOL_GPL(print_context_stack);
17790
17791 unsigned long
17792-print_context_stack_bp(struct thread_info *tinfo,
17793+print_context_stack_bp(struct task_struct *task, void *stack_start,
17794 unsigned long *stack, unsigned long bp,
17795 const struct stacktrace_ops *ops, void *data,
17796 unsigned long *end, int *graph)
17797@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17798 struct stack_frame *frame = (struct stack_frame *)bp;
17799 unsigned long *ret_addr = &frame->return_address;
17800
17801- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17802+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17803 unsigned long addr = *ret_addr;
17804
17805 if (!__kernel_text_address(addr))
17806@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17807 ops->address(data, addr, 1);
17808 frame = frame->next_frame;
17809 ret_addr = &frame->return_address;
17810- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17811+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17812 }
17813
17814 return (unsigned long)frame;
17815@@ -189,7 +188,7 @@ void dump_stack(void)
17816
17817 bp = stack_frame(current, NULL);
17818 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17819- current->pid, current->comm, print_tainted(),
17820+ task_pid_nr(current), current->comm, print_tainted(),
17821 init_utsname()->release,
17822 (int)strcspn(init_utsname()->version, " "),
17823 init_utsname()->version);
17824@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17825 }
17826 EXPORT_SYMBOL_GPL(oops_begin);
17827
17828+extern void gr_handle_kernel_exploit(void);
17829+
17830 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17831 {
17832 if (regs && kexec_should_crash(current))
17833@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17834 panic("Fatal exception in interrupt");
17835 if (panic_on_oops)
17836 panic("Fatal exception");
17837- do_exit(signr);
17838+
17839+ gr_handle_kernel_exploit();
17840+
17841+ do_group_exit(signr);
17842 }
17843
17844 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17845@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17846 print_modules();
17847 show_regs(regs);
17848 #ifdef CONFIG_X86_32
17849- if (user_mode_vm(regs)) {
17850+ if (user_mode(regs)) {
17851 sp = regs->sp;
17852 ss = regs->ss & 0xffff;
17853 } else {
17854@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17855 unsigned long flags = oops_begin();
17856 int sig = SIGSEGV;
17857
17858- if (!user_mode_vm(regs))
17859+ if (!user_mode(regs))
17860 report_bug(regs->ip, regs);
17861
17862 if (__die(str, regs, err))
17863diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17864index 1038a41..db2c12b 100644
17865--- a/arch/x86/kernel/dumpstack_32.c
17866+++ b/arch/x86/kernel/dumpstack_32.c
17867@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17868 bp = stack_frame(task, regs);
17869
17870 for (;;) {
17871- struct thread_info *context;
17872+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17873
17874- context = (struct thread_info *)
17875- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17876- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17877+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17878
17879- stack = (unsigned long *)context->previous_esp;
17880- if (!stack)
17881+ if (stack_start == task_stack_page(task))
17882 break;
17883+ stack = *(unsigned long **)stack_start;
17884 if (ops->stack(data, "IRQ") < 0)
17885 break;
17886 touch_nmi_watchdog();
17887@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17888 {
17889 int i;
17890
17891- __show_regs(regs, !user_mode_vm(regs));
17892+ __show_regs(regs, !user_mode(regs));
17893
17894 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17895 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17896@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17897 * When in-kernel, we also print out the stack and code at the
17898 * time of the fault..
17899 */
17900- if (!user_mode_vm(regs)) {
17901+ if (!user_mode(regs)) {
17902 unsigned int code_prologue = code_bytes * 43 / 64;
17903 unsigned int code_len = code_bytes;
17904 unsigned char c;
17905 u8 *ip;
17906+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17907
17908 pr_emerg("Stack:\n");
17909 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17910
17911 pr_emerg("Code:");
17912
17913- ip = (u8 *)regs->ip - code_prologue;
17914+ ip = (u8 *)regs->ip - code_prologue + cs_base;
17915 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17916 /* try starting at IP */
17917- ip = (u8 *)regs->ip;
17918+ ip = (u8 *)regs->ip + cs_base;
17919 code_len = code_len - code_prologue + 1;
17920 }
17921 for (i = 0; i < code_len; i++, ip++) {
17922@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17923 pr_cont(" Bad EIP value.");
17924 break;
17925 }
17926- if (ip == (u8 *)regs->ip)
17927+ if (ip == (u8 *)regs->ip + cs_base)
17928 pr_cont(" <%02x>", c);
17929 else
17930 pr_cont(" %02x", c);
17931@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17932 {
17933 unsigned short ud2;
17934
17935+ ip = ktla_ktva(ip);
17936 if (ip < PAGE_OFFSET)
17937 return 0;
17938 if (probe_kernel_address((unsigned short *)ip, ud2))
17939@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17940
17941 return ud2 == 0x0b0f;
17942 }
17943+
17944+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17945+void pax_check_alloca(unsigned long size)
17946+{
17947+ unsigned long sp = (unsigned long)&sp, stack_left;
17948+
17949+ /* all kernel stacks are of the same size */
17950+ stack_left = sp & (THREAD_SIZE - 1);
17951+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17952+}
17953+EXPORT_SYMBOL(pax_check_alloca);
17954+#endif
17955diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17956index b653675..51cc8c0 100644
17957--- a/arch/x86/kernel/dumpstack_64.c
17958+++ b/arch/x86/kernel/dumpstack_64.c
17959@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17960 unsigned long *irq_stack_end =
17961 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17962 unsigned used = 0;
17963- struct thread_info *tinfo;
17964 int graph = 0;
17965 unsigned long dummy;
17966+ void *stack_start;
17967
17968 if (!task)
17969 task = current;
17970@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17971 * current stack address. If the stacks consist of nested
17972 * exceptions
17973 */
17974- tinfo = task_thread_info(task);
17975 for (;;) {
17976 char *id;
17977 unsigned long *estack_end;
17978+
17979 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17980 &used, &id);
17981
17982@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17983 if (ops->stack(data, id) < 0)
17984 break;
17985
17986- bp = ops->walk_stack(tinfo, stack, bp, ops,
17987+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17988 data, estack_end, &graph);
17989 ops->stack(data, "<EOE>");
17990 /*
17991@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17992 * second-to-last pointer (index -2 to end) in the
17993 * exception stack:
17994 */
17995+ if ((u16)estack_end[-1] != __KERNEL_DS)
17996+ goto out;
17997 stack = (unsigned long *) estack_end[-2];
17998 continue;
17999 }
18000@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18001 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18002 if (ops->stack(data, "IRQ") < 0)
18003 break;
18004- bp = ops->walk_stack(tinfo, stack, bp,
18005+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18006 ops, data, irq_stack_end, &graph);
18007 /*
18008 * We link to the next stack (which would be
18009@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18010 /*
18011 * This handles the process stack:
18012 */
18013- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18014+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18015+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18016+out:
18017 put_cpu();
18018 }
18019 EXPORT_SYMBOL(dump_trace);
18020@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18021 {
18022 int i;
18023 unsigned long sp;
18024- const int cpu = smp_processor_id();
18025+ const int cpu = raw_smp_processor_id();
18026 struct task_struct *cur = current;
18027
18028 sp = regs->sp;
18029@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18030
18031 return ud2 == 0x0b0f;
18032 }
18033+
18034+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18035+void pax_check_alloca(unsigned long size)
18036+{
18037+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18038+ unsigned cpu, used;
18039+ char *id;
18040+
18041+ /* check the process stack first */
18042+ stack_start = (unsigned long)task_stack_page(current);
18043+ stack_end = stack_start + THREAD_SIZE;
18044+ if (likely(stack_start <= sp && sp < stack_end)) {
18045+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18046+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18047+ return;
18048+ }
18049+
18050+ cpu = get_cpu();
18051+
18052+ /* check the irq stacks */
18053+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18054+ stack_start = stack_end - IRQ_STACK_SIZE;
18055+ if (stack_start <= sp && sp < stack_end) {
18056+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18057+ put_cpu();
18058+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18059+ return;
18060+ }
18061+
18062+ /* check the exception stacks */
18063+ used = 0;
18064+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18065+ stack_start = stack_end - EXCEPTION_STKSZ;
18066+ if (stack_end && stack_start <= sp && sp < stack_end) {
18067+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18068+ put_cpu();
18069+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18070+ return;
18071+ }
18072+
18073+ put_cpu();
18074+
18075+ /* unknown stack */
18076+ BUG();
18077+}
18078+EXPORT_SYMBOL(pax_check_alloca);
18079+#endif
18080diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18081index 9b9f18b..9fcaa04 100644
18082--- a/arch/x86/kernel/early_printk.c
18083+++ b/arch/x86/kernel/early_printk.c
18084@@ -7,6 +7,7 @@
18085 #include <linux/pci_regs.h>
18086 #include <linux/pci_ids.h>
18087 #include <linux/errno.h>
18088+#include <linux/sched.h>
18089 #include <asm/io.h>
18090 #include <asm/processor.h>
18091 #include <asm/fcntl.h>
18092diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18093index 6ed91d9..6cc365b 100644
18094--- a/arch/x86/kernel/entry_32.S
18095+++ b/arch/x86/kernel/entry_32.S
18096@@ -177,13 +177,153 @@
18097 /*CFI_REL_OFFSET gs, PT_GS*/
18098 .endm
18099 .macro SET_KERNEL_GS reg
18100+
18101+#ifdef CONFIG_CC_STACKPROTECTOR
18102 movl $(__KERNEL_STACK_CANARY), \reg
18103+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18104+ movl $(__USER_DS), \reg
18105+#else
18106+ xorl \reg, \reg
18107+#endif
18108+
18109 movl \reg, %gs
18110 .endm
18111
18112 #endif /* CONFIG_X86_32_LAZY_GS */
18113
18114-.macro SAVE_ALL
18115+.macro pax_enter_kernel
18116+#ifdef CONFIG_PAX_KERNEXEC
18117+ call pax_enter_kernel
18118+#endif
18119+.endm
18120+
18121+.macro pax_exit_kernel
18122+#ifdef CONFIG_PAX_KERNEXEC
18123+ call pax_exit_kernel
18124+#endif
18125+.endm
18126+
18127+#ifdef CONFIG_PAX_KERNEXEC
18128+ENTRY(pax_enter_kernel)
18129+#ifdef CONFIG_PARAVIRT
18130+ pushl %eax
18131+ pushl %ecx
18132+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18133+ mov %eax, %esi
18134+#else
18135+ mov %cr0, %esi
18136+#endif
18137+ bts $16, %esi
18138+ jnc 1f
18139+ mov %cs, %esi
18140+ cmp $__KERNEL_CS, %esi
18141+ jz 3f
18142+ ljmp $__KERNEL_CS, $3f
18143+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18144+2:
18145+#ifdef CONFIG_PARAVIRT
18146+ mov %esi, %eax
18147+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18148+#else
18149+ mov %esi, %cr0
18150+#endif
18151+3:
18152+#ifdef CONFIG_PARAVIRT
18153+ popl %ecx
18154+ popl %eax
18155+#endif
18156+ ret
18157+ENDPROC(pax_enter_kernel)
18158+
18159+ENTRY(pax_exit_kernel)
18160+#ifdef CONFIG_PARAVIRT
18161+ pushl %eax
18162+ pushl %ecx
18163+#endif
18164+ mov %cs, %esi
18165+ cmp $__KERNEXEC_KERNEL_CS, %esi
18166+ jnz 2f
18167+#ifdef CONFIG_PARAVIRT
18168+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18169+ mov %eax, %esi
18170+#else
18171+ mov %cr0, %esi
18172+#endif
18173+ btr $16, %esi
18174+ ljmp $__KERNEL_CS, $1f
18175+1:
18176+#ifdef CONFIG_PARAVIRT
18177+ mov %esi, %eax
18178+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18179+#else
18180+ mov %esi, %cr0
18181+#endif
18182+2:
18183+#ifdef CONFIG_PARAVIRT
18184+ popl %ecx
18185+ popl %eax
18186+#endif
18187+ ret
18188+ENDPROC(pax_exit_kernel)
18189+#endif
18190+
18191+.macro pax_erase_kstack
18192+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18193+ call pax_erase_kstack
18194+#endif
18195+.endm
18196+
18197+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18198+/*
18199+ * ebp: thread_info
18200+ */
18201+ENTRY(pax_erase_kstack)
18202+ pushl %edi
18203+ pushl %ecx
18204+ pushl %eax
18205+
18206+ mov TI_lowest_stack(%ebp), %edi
18207+ mov $-0xBEEF, %eax
18208+ std
18209+
18210+1: mov %edi, %ecx
18211+ and $THREAD_SIZE_asm - 1, %ecx
18212+ shr $2, %ecx
18213+ repne scasl
18214+ jecxz 2f
18215+
18216+ cmp $2*16, %ecx
18217+ jc 2f
18218+
18219+ mov $2*16, %ecx
18220+ repe scasl
18221+ jecxz 2f
18222+ jne 1b
18223+
18224+2: cld
18225+ mov %esp, %ecx
18226+ sub %edi, %ecx
18227+
18228+ cmp $THREAD_SIZE_asm, %ecx
18229+ jb 3f
18230+ ud2
18231+3:
18232+
18233+ shr $2, %ecx
18234+ rep stosl
18235+
18236+ mov TI_task_thread_sp0(%ebp), %edi
18237+ sub $128, %edi
18238+ mov %edi, TI_lowest_stack(%ebp)
18239+
18240+ popl %eax
18241+ popl %ecx
18242+ popl %edi
18243+ ret
18244+ENDPROC(pax_erase_kstack)
18245+#endif
18246+
18247+.macro __SAVE_ALL _DS
18248 cld
18249 PUSH_GS
18250 pushl_cfi %fs
18251@@ -206,7 +346,7 @@
18252 CFI_REL_OFFSET ecx, 0
18253 pushl_cfi %ebx
18254 CFI_REL_OFFSET ebx, 0
18255- movl $(__USER_DS), %edx
18256+ movl $\_DS, %edx
18257 movl %edx, %ds
18258 movl %edx, %es
18259 movl $(__KERNEL_PERCPU), %edx
18260@@ -214,6 +354,15 @@
18261 SET_KERNEL_GS %edx
18262 .endm
18263
18264+.macro SAVE_ALL
18265+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18266+ __SAVE_ALL __KERNEL_DS
18267+ pax_enter_kernel
18268+#else
18269+ __SAVE_ALL __USER_DS
18270+#endif
18271+.endm
18272+
18273 .macro RESTORE_INT_REGS
18274 popl_cfi %ebx
18275 CFI_RESTORE ebx
18276@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18277 popfl_cfi
18278 jmp syscall_exit
18279 CFI_ENDPROC
18280-END(ret_from_fork)
18281+ENDPROC(ret_from_fork)
18282
18283 ENTRY(ret_from_kernel_thread)
18284 CFI_STARTPROC
18285@@ -344,7 +493,15 @@ ret_from_intr:
18286 andl $SEGMENT_RPL_MASK, %eax
18287 #endif
18288 cmpl $USER_RPL, %eax
18289+
18290+#ifdef CONFIG_PAX_KERNEXEC
18291+ jae resume_userspace
18292+
18293+ pax_exit_kernel
18294+ jmp resume_kernel
18295+#else
18296 jb resume_kernel # not returning to v8086 or userspace
18297+#endif
18298
18299 ENTRY(resume_userspace)
18300 LOCKDEP_SYS_EXIT
18301@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18302 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18303 # int/exception return?
18304 jne work_pending
18305- jmp restore_all
18306-END(ret_from_exception)
18307+ jmp restore_all_pax
18308+ENDPROC(ret_from_exception)
18309
18310 #ifdef CONFIG_PREEMPT
18311 ENTRY(resume_kernel)
18312@@ -372,7 +529,7 @@ need_resched:
18313 jz restore_all
18314 call preempt_schedule_irq
18315 jmp need_resched
18316-END(resume_kernel)
18317+ENDPROC(resume_kernel)
18318 #endif
18319 CFI_ENDPROC
18320 /*
18321@@ -406,30 +563,45 @@ sysenter_past_esp:
18322 /*CFI_REL_OFFSET cs, 0*/
18323 /*
18324 * Push current_thread_info()->sysenter_return to the stack.
18325- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18326- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18327 */
18328- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18329+ pushl_cfi $0
18330 CFI_REL_OFFSET eip, 0
18331
18332 pushl_cfi %eax
18333 SAVE_ALL
18334+ GET_THREAD_INFO(%ebp)
18335+ movl TI_sysenter_return(%ebp),%ebp
18336+ movl %ebp,PT_EIP(%esp)
18337 ENABLE_INTERRUPTS(CLBR_NONE)
18338
18339 /*
18340 * Load the potential sixth argument from user stack.
18341 * Careful about security.
18342 */
18343+ movl PT_OLDESP(%esp),%ebp
18344+
18345+#ifdef CONFIG_PAX_MEMORY_UDEREF
18346+ mov PT_OLDSS(%esp),%ds
18347+1: movl %ds:(%ebp),%ebp
18348+ push %ss
18349+ pop %ds
18350+#else
18351 cmpl $__PAGE_OFFSET-3,%ebp
18352 jae syscall_fault
18353 ASM_STAC
18354 1: movl (%ebp),%ebp
18355 ASM_CLAC
18356+#endif
18357+
18358 movl %ebp,PT_EBP(%esp)
18359 _ASM_EXTABLE(1b,syscall_fault)
18360
18361 GET_THREAD_INFO(%ebp)
18362
18363+#ifdef CONFIG_PAX_RANDKSTACK
18364+ pax_erase_kstack
18365+#endif
18366+
18367 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18368 jnz sysenter_audit
18369 sysenter_do_call:
18370@@ -444,12 +616,24 @@ sysenter_do_call:
18371 testl $_TIF_ALLWORK_MASK, %ecx
18372 jne sysexit_audit
18373 sysenter_exit:
18374+
18375+#ifdef CONFIG_PAX_RANDKSTACK
18376+ pushl_cfi %eax
18377+ movl %esp, %eax
18378+ call pax_randomize_kstack
18379+ popl_cfi %eax
18380+#endif
18381+
18382+ pax_erase_kstack
18383+
18384 /* if something modifies registers it must also disable sysexit */
18385 movl PT_EIP(%esp), %edx
18386 movl PT_OLDESP(%esp), %ecx
18387 xorl %ebp,%ebp
18388 TRACE_IRQS_ON
18389 1: mov PT_FS(%esp), %fs
18390+2: mov PT_DS(%esp), %ds
18391+3: mov PT_ES(%esp), %es
18392 PTGS_TO_GS
18393 ENABLE_INTERRUPTS_SYSEXIT
18394
18395@@ -466,6 +650,9 @@ sysenter_audit:
18396 movl %eax,%edx /* 2nd arg: syscall number */
18397 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18398 call __audit_syscall_entry
18399+
18400+ pax_erase_kstack
18401+
18402 pushl_cfi %ebx
18403 movl PT_EAX(%esp),%eax /* reload syscall number */
18404 jmp sysenter_do_call
18405@@ -491,10 +678,16 @@ sysexit_audit:
18406
18407 CFI_ENDPROC
18408 .pushsection .fixup,"ax"
18409-2: movl $0,PT_FS(%esp)
18410+4: movl $0,PT_FS(%esp)
18411+ jmp 1b
18412+5: movl $0,PT_DS(%esp)
18413+ jmp 1b
18414+6: movl $0,PT_ES(%esp)
18415 jmp 1b
18416 .popsection
18417- _ASM_EXTABLE(1b,2b)
18418+ _ASM_EXTABLE(1b,4b)
18419+ _ASM_EXTABLE(2b,5b)
18420+ _ASM_EXTABLE(3b,6b)
18421 PTGS_TO_GS_EX
18422 ENDPROC(ia32_sysenter_target)
18423
18424@@ -509,6 +702,11 @@ ENTRY(system_call)
18425 pushl_cfi %eax # save orig_eax
18426 SAVE_ALL
18427 GET_THREAD_INFO(%ebp)
18428+
18429+#ifdef CONFIG_PAX_RANDKSTACK
18430+ pax_erase_kstack
18431+#endif
18432+
18433 # system call tracing in operation / emulation
18434 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18435 jnz syscall_trace_entry
18436@@ -527,6 +725,15 @@ syscall_exit:
18437 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18438 jne syscall_exit_work
18439
18440+restore_all_pax:
18441+
18442+#ifdef CONFIG_PAX_RANDKSTACK
18443+ movl %esp, %eax
18444+ call pax_randomize_kstack
18445+#endif
18446+
18447+ pax_erase_kstack
18448+
18449 restore_all:
18450 TRACE_IRQS_IRET
18451 restore_all_notrace:
18452@@ -583,14 +790,34 @@ ldt_ss:
18453 * compensating for the offset by changing to the ESPFIX segment with
18454 * a base address that matches for the difference.
18455 */
18456-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18457+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18458 mov %esp, %edx /* load kernel esp */
18459 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18460 mov %dx, %ax /* eax: new kernel esp */
18461 sub %eax, %edx /* offset (low word is 0) */
18462+#ifdef CONFIG_SMP
18463+ movl PER_CPU_VAR(cpu_number), %ebx
18464+ shll $PAGE_SHIFT_asm, %ebx
18465+ addl $cpu_gdt_table, %ebx
18466+#else
18467+ movl $cpu_gdt_table, %ebx
18468+#endif
18469 shr $16, %edx
18470- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18471- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18472+
18473+#ifdef CONFIG_PAX_KERNEXEC
18474+ mov %cr0, %esi
18475+ btr $16, %esi
18476+ mov %esi, %cr0
18477+#endif
18478+
18479+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18480+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18481+
18482+#ifdef CONFIG_PAX_KERNEXEC
18483+ bts $16, %esi
18484+ mov %esi, %cr0
18485+#endif
18486+
18487 pushl_cfi $__ESPFIX_SS
18488 pushl_cfi %eax /* new kernel esp */
18489 /* Disable interrupts, but do not irqtrace this section: we
18490@@ -619,20 +846,18 @@ work_resched:
18491 movl TI_flags(%ebp), %ecx
18492 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18493 # than syscall tracing?
18494- jz restore_all
18495+ jz restore_all_pax
18496 testb $_TIF_NEED_RESCHED, %cl
18497 jnz work_resched
18498
18499 work_notifysig: # deal with pending signals and
18500 # notify-resume requests
18501+ movl %esp, %eax
18502 #ifdef CONFIG_VM86
18503 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18504- movl %esp, %eax
18505 jne work_notifysig_v86 # returning to kernel-space or
18506 # vm86-space
18507 1:
18508-#else
18509- movl %esp, %eax
18510 #endif
18511 TRACE_IRQS_ON
18512 ENABLE_INTERRUPTS(CLBR_NONE)
18513@@ -653,7 +878,7 @@ work_notifysig_v86:
18514 movl %eax, %esp
18515 jmp 1b
18516 #endif
18517-END(work_pending)
18518+ENDPROC(work_pending)
18519
18520 # perform syscall exit tracing
18521 ALIGN
18522@@ -661,11 +886,14 @@ syscall_trace_entry:
18523 movl $-ENOSYS,PT_EAX(%esp)
18524 movl %esp, %eax
18525 call syscall_trace_enter
18526+
18527+ pax_erase_kstack
18528+
18529 /* What it returned is what we'll actually use. */
18530 cmpl $(NR_syscalls), %eax
18531 jnae syscall_call
18532 jmp syscall_exit
18533-END(syscall_trace_entry)
18534+ENDPROC(syscall_trace_entry)
18535
18536 # perform syscall exit tracing
18537 ALIGN
18538@@ -678,21 +906,25 @@ syscall_exit_work:
18539 movl %esp, %eax
18540 call syscall_trace_leave
18541 jmp resume_userspace
18542-END(syscall_exit_work)
18543+ENDPROC(syscall_exit_work)
18544 CFI_ENDPROC
18545
18546 RING0_INT_FRAME # can't unwind into user space anyway
18547 syscall_fault:
18548+#ifdef CONFIG_PAX_MEMORY_UDEREF
18549+ push %ss
18550+ pop %ds
18551+#endif
18552 ASM_CLAC
18553 GET_THREAD_INFO(%ebp)
18554 movl $-EFAULT,PT_EAX(%esp)
18555 jmp resume_userspace
18556-END(syscall_fault)
18557+ENDPROC(syscall_fault)
18558
18559 syscall_badsys:
18560 movl $-ENOSYS,PT_EAX(%esp)
18561 jmp resume_userspace
18562-END(syscall_badsys)
18563+ENDPROC(syscall_badsys)
18564 CFI_ENDPROC
18565 /*
18566 * End of kprobes section
18567@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18568 * normal stack and adjusts ESP with the matching offset.
18569 */
18570 /* fixup the stack */
18571- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18572- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18573+#ifdef CONFIG_SMP
18574+ movl PER_CPU_VAR(cpu_number), %ebx
18575+ shll $PAGE_SHIFT_asm, %ebx
18576+ addl $cpu_gdt_table, %ebx
18577+#else
18578+ movl $cpu_gdt_table, %ebx
18579+#endif
18580+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18581+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18582 shl $16, %eax
18583 addl %esp, %eax /* the adjusted stack pointer */
18584 pushl_cfi $__KERNEL_DS
18585@@ -807,7 +1046,7 @@ vector=vector+1
18586 .endr
18587 2: jmp common_interrupt
18588 .endr
18589-END(irq_entries_start)
18590+ENDPROC(irq_entries_start)
18591
18592 .previous
18593 END(interrupt)
18594@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18595 pushl_cfi $do_coprocessor_error
18596 jmp error_code
18597 CFI_ENDPROC
18598-END(coprocessor_error)
18599+ENDPROC(coprocessor_error)
18600
18601 ENTRY(simd_coprocessor_error)
18602 RING0_INT_FRAME
18603@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18604 #endif
18605 jmp error_code
18606 CFI_ENDPROC
18607-END(simd_coprocessor_error)
18608+ENDPROC(simd_coprocessor_error)
18609
18610 ENTRY(device_not_available)
18611 RING0_INT_FRAME
18612@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18613 pushl_cfi $do_device_not_available
18614 jmp error_code
18615 CFI_ENDPROC
18616-END(device_not_available)
18617+ENDPROC(device_not_available)
18618
18619 #ifdef CONFIG_PARAVIRT
18620 ENTRY(native_iret)
18621 iret
18622 _ASM_EXTABLE(native_iret, iret_exc)
18623-END(native_iret)
18624+ENDPROC(native_iret)
18625
18626 ENTRY(native_irq_enable_sysexit)
18627 sti
18628 sysexit
18629-END(native_irq_enable_sysexit)
18630+ENDPROC(native_irq_enable_sysexit)
18631 #endif
18632
18633 ENTRY(overflow)
18634@@ -910,7 +1149,7 @@ ENTRY(overflow)
18635 pushl_cfi $do_overflow
18636 jmp error_code
18637 CFI_ENDPROC
18638-END(overflow)
18639+ENDPROC(overflow)
18640
18641 ENTRY(bounds)
18642 RING0_INT_FRAME
18643@@ -919,7 +1158,7 @@ ENTRY(bounds)
18644 pushl_cfi $do_bounds
18645 jmp error_code
18646 CFI_ENDPROC
18647-END(bounds)
18648+ENDPROC(bounds)
18649
18650 ENTRY(invalid_op)
18651 RING0_INT_FRAME
18652@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18653 pushl_cfi $do_invalid_op
18654 jmp error_code
18655 CFI_ENDPROC
18656-END(invalid_op)
18657+ENDPROC(invalid_op)
18658
18659 ENTRY(coprocessor_segment_overrun)
18660 RING0_INT_FRAME
18661@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18662 pushl_cfi $do_coprocessor_segment_overrun
18663 jmp error_code
18664 CFI_ENDPROC
18665-END(coprocessor_segment_overrun)
18666+ENDPROC(coprocessor_segment_overrun)
18667
18668 ENTRY(invalid_TSS)
18669 RING0_EC_FRAME
18670@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18671 pushl_cfi $do_invalid_TSS
18672 jmp error_code
18673 CFI_ENDPROC
18674-END(invalid_TSS)
18675+ENDPROC(invalid_TSS)
18676
18677 ENTRY(segment_not_present)
18678 RING0_EC_FRAME
18679@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18680 pushl_cfi $do_segment_not_present
18681 jmp error_code
18682 CFI_ENDPROC
18683-END(segment_not_present)
18684+ENDPROC(segment_not_present)
18685
18686 ENTRY(stack_segment)
18687 RING0_EC_FRAME
18688@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18689 pushl_cfi $do_stack_segment
18690 jmp error_code
18691 CFI_ENDPROC
18692-END(stack_segment)
18693+ENDPROC(stack_segment)
18694
18695 ENTRY(alignment_check)
18696 RING0_EC_FRAME
18697@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18698 pushl_cfi $do_alignment_check
18699 jmp error_code
18700 CFI_ENDPROC
18701-END(alignment_check)
18702+ENDPROC(alignment_check)
18703
18704 ENTRY(divide_error)
18705 RING0_INT_FRAME
18706@@ -978,7 +1217,7 @@ ENTRY(divide_error)
18707 pushl_cfi $do_divide_error
18708 jmp error_code
18709 CFI_ENDPROC
18710-END(divide_error)
18711+ENDPROC(divide_error)
18712
18713 #ifdef CONFIG_X86_MCE
18714 ENTRY(machine_check)
18715@@ -988,7 +1227,7 @@ ENTRY(machine_check)
18716 pushl_cfi machine_check_vector
18717 jmp error_code
18718 CFI_ENDPROC
18719-END(machine_check)
18720+ENDPROC(machine_check)
18721 #endif
18722
18723 ENTRY(spurious_interrupt_bug)
18724@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18725 pushl_cfi $do_spurious_interrupt_bug
18726 jmp error_code
18727 CFI_ENDPROC
18728-END(spurious_interrupt_bug)
18729+ENDPROC(spurious_interrupt_bug)
18730 /*
18731 * End of kprobes section
18732 */
18733@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18734
18735 ENTRY(mcount)
18736 ret
18737-END(mcount)
18738+ENDPROC(mcount)
18739
18740 ENTRY(ftrace_caller)
18741 cmpl $0, function_trace_stop
18742@@ -1134,7 +1373,7 @@ ftrace_graph_call:
18743 .globl ftrace_stub
18744 ftrace_stub:
18745 ret
18746-END(ftrace_caller)
18747+ENDPROC(ftrace_caller)
18748
18749 ENTRY(ftrace_regs_caller)
18750 pushf /* push flags before compare (in cs location) */
18751@@ -1235,7 +1474,7 @@ trace:
18752 popl %ecx
18753 popl %eax
18754 jmp ftrace_stub
18755-END(mcount)
18756+ENDPROC(mcount)
18757 #endif /* CONFIG_DYNAMIC_FTRACE */
18758 #endif /* CONFIG_FUNCTION_TRACER */
18759
18760@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18761 popl %ecx
18762 popl %eax
18763 ret
18764-END(ftrace_graph_caller)
18765+ENDPROC(ftrace_graph_caller)
18766
18767 .globl return_to_handler
18768 return_to_handler:
18769@@ -1309,15 +1548,18 @@ error_code:
18770 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18771 REG_TO_PTGS %ecx
18772 SET_KERNEL_GS %ecx
18773- movl $(__USER_DS), %ecx
18774+ movl $(__KERNEL_DS), %ecx
18775 movl %ecx, %ds
18776 movl %ecx, %es
18777+
18778+ pax_enter_kernel
18779+
18780 TRACE_IRQS_OFF
18781 movl %esp,%eax # pt_regs pointer
18782 call *%edi
18783 jmp ret_from_exception
18784 CFI_ENDPROC
18785-END(page_fault)
18786+ENDPROC(page_fault)
18787
18788 /*
18789 * Debug traps and NMI can happen at the one SYSENTER instruction
18790@@ -1360,7 +1602,7 @@ debug_stack_correct:
18791 call do_debug
18792 jmp ret_from_exception
18793 CFI_ENDPROC
18794-END(debug)
18795+ENDPROC(debug)
18796
18797 /*
18798 * NMI is doubly nasty. It can happen _while_ we're handling
18799@@ -1398,6 +1640,9 @@ nmi_stack_correct:
18800 xorl %edx,%edx # zero error code
18801 movl %esp,%eax # pt_regs pointer
18802 call do_nmi
18803+
18804+ pax_exit_kernel
18805+
18806 jmp restore_all_notrace
18807 CFI_ENDPROC
18808
18809@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18810 FIXUP_ESPFIX_STACK # %eax == %esp
18811 xorl %edx,%edx # zero error code
18812 call do_nmi
18813+
18814+ pax_exit_kernel
18815+
18816 RESTORE_REGS
18817 lss 12+4(%esp), %esp # back to espfix stack
18818 CFI_ADJUST_CFA_OFFSET -24
18819 jmp irq_return
18820 CFI_ENDPROC
18821-END(nmi)
18822+ENDPROC(nmi)
18823
18824 ENTRY(int3)
18825 RING0_INT_FRAME
18826@@ -1452,14 +1700,14 @@ ENTRY(int3)
18827 call do_int3
18828 jmp ret_from_exception
18829 CFI_ENDPROC
18830-END(int3)
18831+ENDPROC(int3)
18832
18833 ENTRY(general_protection)
18834 RING0_EC_FRAME
18835 pushl_cfi $do_general_protection
18836 jmp error_code
18837 CFI_ENDPROC
18838-END(general_protection)
18839+ENDPROC(general_protection)
18840
18841 #ifdef CONFIG_KVM_GUEST
18842 ENTRY(async_page_fault)
18843@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18844 pushl_cfi $do_async_page_fault
18845 jmp error_code
18846 CFI_ENDPROC
18847-END(async_page_fault)
18848+ENDPROC(async_page_fault)
18849 #endif
18850
18851 /*
18852diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18853index cb3c591..bc63707 100644
18854--- a/arch/x86/kernel/entry_64.S
18855+++ b/arch/x86/kernel/entry_64.S
18856@@ -59,6 +59,8 @@
18857 #include <asm/context_tracking.h>
18858 #include <asm/smap.h>
18859 #include <linux/err.h>
18860+#include <asm/pgtable.h>
18861+#include <asm/alternative-asm.h>
18862
18863 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18864 #include <linux/elf-em.h>
18865@@ -80,8 +82,9 @@
18866 #ifdef CONFIG_DYNAMIC_FTRACE
18867
18868 ENTRY(function_hook)
18869+ pax_force_retaddr
18870 retq
18871-END(function_hook)
18872+ENDPROC(function_hook)
18873
18874 /* skip is set if stack has been adjusted */
18875 .macro ftrace_caller_setup skip=0
18876@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18877 #endif
18878
18879 GLOBAL(ftrace_stub)
18880+ pax_force_retaddr
18881 retq
18882-END(ftrace_caller)
18883+ENDPROC(ftrace_caller)
18884
18885 ENTRY(ftrace_regs_caller)
18886 /* Save the current flags before compare (in SS location)*/
18887@@ -191,7 +195,7 @@ ftrace_restore_flags:
18888 popfq
18889 jmp ftrace_stub
18890
18891-END(ftrace_regs_caller)
18892+ENDPROC(ftrace_regs_caller)
18893
18894
18895 #else /* ! CONFIG_DYNAMIC_FTRACE */
18896@@ -212,6 +216,7 @@ ENTRY(function_hook)
18897 #endif
18898
18899 GLOBAL(ftrace_stub)
18900+ pax_force_retaddr
18901 retq
18902
18903 trace:
18904@@ -225,12 +230,13 @@ trace:
18905 #endif
18906 subq $MCOUNT_INSN_SIZE, %rdi
18907
18908+ pax_force_fptr ftrace_trace_function
18909 call *ftrace_trace_function
18910
18911 MCOUNT_RESTORE_FRAME
18912
18913 jmp ftrace_stub
18914-END(function_hook)
18915+ENDPROC(function_hook)
18916 #endif /* CONFIG_DYNAMIC_FTRACE */
18917 #endif /* CONFIG_FUNCTION_TRACER */
18918
18919@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18920
18921 MCOUNT_RESTORE_FRAME
18922
18923+ pax_force_retaddr
18924 retq
18925-END(ftrace_graph_caller)
18926+ENDPROC(ftrace_graph_caller)
18927
18928 GLOBAL(return_to_handler)
18929 subq $24, %rsp
18930@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18931 movq 8(%rsp), %rdx
18932 movq (%rsp), %rax
18933 addq $24, %rsp
18934+ pax_force_fptr %rdi
18935 jmp *%rdi
18936+ENDPROC(return_to_handler)
18937 #endif
18938
18939
18940@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18941 ENDPROC(native_usergs_sysret64)
18942 #endif /* CONFIG_PARAVIRT */
18943
18944+ .macro ljmpq sel, off
18945+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18946+ .byte 0x48; ljmp *1234f(%rip)
18947+ .pushsection .rodata
18948+ .align 16
18949+ 1234: .quad \off; .word \sel
18950+ .popsection
18951+#else
18952+ pushq $\sel
18953+ pushq $\off
18954+ lretq
18955+#endif
18956+ .endm
18957+
18958+ .macro pax_enter_kernel
18959+ pax_set_fptr_mask
18960+#ifdef CONFIG_PAX_KERNEXEC
18961+ call pax_enter_kernel
18962+#endif
18963+ .endm
18964+
18965+ .macro pax_exit_kernel
18966+#ifdef CONFIG_PAX_KERNEXEC
18967+ call pax_exit_kernel
18968+#endif
18969+ .endm
18970+
18971+#ifdef CONFIG_PAX_KERNEXEC
18972+ENTRY(pax_enter_kernel)
18973+ pushq %rdi
18974+
18975+#ifdef CONFIG_PARAVIRT
18976+ PV_SAVE_REGS(CLBR_RDI)
18977+#endif
18978+
18979+ GET_CR0_INTO_RDI
18980+ bts $16,%rdi
18981+ jnc 3f
18982+ mov %cs,%edi
18983+ cmp $__KERNEL_CS,%edi
18984+ jnz 2f
18985+1:
18986+
18987+#ifdef CONFIG_PARAVIRT
18988+ PV_RESTORE_REGS(CLBR_RDI)
18989+#endif
18990+
18991+ popq %rdi
18992+ pax_force_retaddr
18993+ retq
18994+
18995+2: ljmpq __KERNEL_CS,1f
18996+3: ljmpq __KERNEXEC_KERNEL_CS,4f
18997+4: SET_RDI_INTO_CR0
18998+ jmp 1b
18999+ENDPROC(pax_enter_kernel)
19000+
19001+ENTRY(pax_exit_kernel)
19002+ pushq %rdi
19003+
19004+#ifdef CONFIG_PARAVIRT
19005+ PV_SAVE_REGS(CLBR_RDI)
19006+#endif
19007+
19008+ mov %cs,%rdi
19009+ cmp $__KERNEXEC_KERNEL_CS,%edi
19010+ jz 2f
19011+1:
19012+
19013+#ifdef CONFIG_PARAVIRT
19014+ PV_RESTORE_REGS(CLBR_RDI);
19015+#endif
19016+
19017+ popq %rdi
19018+ pax_force_retaddr
19019+ retq
19020+
19021+2: GET_CR0_INTO_RDI
19022+ btr $16,%rdi
19023+ ljmpq __KERNEL_CS,3f
19024+3: SET_RDI_INTO_CR0
19025+ jmp 1b
19026+ENDPROC(pax_exit_kernel)
19027+#endif
19028+
19029+ .macro pax_enter_kernel_user
19030+ pax_set_fptr_mask
19031+#ifdef CONFIG_PAX_MEMORY_UDEREF
19032+ call pax_enter_kernel_user
19033+#endif
19034+ .endm
19035+
19036+ .macro pax_exit_kernel_user
19037+#ifdef CONFIG_PAX_MEMORY_UDEREF
19038+ call pax_exit_kernel_user
19039+#endif
19040+#ifdef CONFIG_PAX_RANDKSTACK
19041+ pushq %rax
19042+ call pax_randomize_kstack
19043+ popq %rax
19044+#endif
19045+ .endm
19046+
19047+#ifdef CONFIG_PAX_MEMORY_UDEREF
19048+ENTRY(pax_enter_kernel_user)
19049+ pushq %rdi
19050+ pushq %rbx
19051+
19052+#ifdef CONFIG_PARAVIRT
19053+ PV_SAVE_REGS(CLBR_RDI)
19054+#endif
19055+
19056+ GET_CR3_INTO_RDI
19057+ mov %rdi,%rbx
19058+ add $__START_KERNEL_map,%rbx
19059+ sub phys_base(%rip),%rbx
19060+
19061+#ifdef CONFIG_PARAVIRT
19062+ pushq %rdi
19063+ cmpl $0, pv_info+PARAVIRT_enabled
19064+ jz 1f
19065+ i = 0
19066+ .rept USER_PGD_PTRS
19067+ mov i*8(%rbx),%rsi
19068+ mov $0,%sil
19069+ lea i*8(%rbx),%rdi
19070+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19071+ i = i + 1
19072+ .endr
19073+ jmp 2f
19074+1:
19075+#endif
19076+
19077+ i = 0
19078+ .rept USER_PGD_PTRS
19079+ movb $0,i*8(%rbx)
19080+ i = i + 1
19081+ .endr
19082+
19083+#ifdef CONFIG_PARAVIRT
19084+2: popq %rdi
19085+#endif
19086+ SET_RDI_INTO_CR3
19087+
19088+#ifdef CONFIG_PAX_KERNEXEC
19089+ GET_CR0_INTO_RDI
19090+ bts $16,%rdi
19091+ SET_RDI_INTO_CR0
19092+#endif
19093+
19094+#ifdef CONFIG_PARAVIRT
19095+ PV_RESTORE_REGS(CLBR_RDI)
19096+#endif
19097+
19098+ popq %rbx
19099+ popq %rdi
19100+ pax_force_retaddr
19101+ retq
19102+ENDPROC(pax_enter_kernel_user)
19103+
19104+ENTRY(pax_exit_kernel_user)
19105+ push %rdi
19106+
19107+#ifdef CONFIG_PARAVIRT
19108+ pushq %rbx
19109+ PV_SAVE_REGS(CLBR_RDI)
19110+#endif
19111+
19112+#ifdef CONFIG_PAX_KERNEXEC
19113+ GET_CR0_INTO_RDI
19114+ btr $16,%rdi
19115+ SET_RDI_INTO_CR0
19116+#endif
19117+
19118+ GET_CR3_INTO_RDI
19119+ add $__START_KERNEL_map,%rdi
19120+ sub phys_base(%rip),%rdi
19121+
19122+#ifdef CONFIG_PARAVIRT
19123+ cmpl $0, pv_info+PARAVIRT_enabled
19124+ jz 1f
19125+ mov %rdi,%rbx
19126+ i = 0
19127+ .rept USER_PGD_PTRS
19128+ mov i*8(%rbx),%rsi
19129+ mov $0x67,%sil
19130+ lea i*8(%rbx),%rdi
19131+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19132+ i = i + 1
19133+ .endr
19134+ jmp 2f
19135+1:
19136+#endif
19137+
19138+ i = 0
19139+ .rept USER_PGD_PTRS
19140+ movb $0x67,i*8(%rdi)
19141+ i = i + 1
19142+ .endr
19143+
19144+#ifdef CONFIG_PARAVIRT
19145+2: PV_RESTORE_REGS(CLBR_RDI)
19146+ popq %rbx
19147+#endif
19148+
19149+ popq %rdi
19150+ pax_force_retaddr
19151+ retq
19152+ENDPROC(pax_exit_kernel_user)
19153+#endif
19154+
19155+.macro pax_erase_kstack
19156+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19157+ call pax_erase_kstack
19158+#endif
19159+.endm
19160+
19161+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19162+ENTRY(pax_erase_kstack)
19163+ pushq %rdi
19164+ pushq %rcx
19165+ pushq %rax
19166+ pushq %r11
19167+
19168+ GET_THREAD_INFO(%r11)
19169+ mov TI_lowest_stack(%r11), %rdi
19170+ mov $-0xBEEF, %rax
19171+ std
19172+
19173+1: mov %edi, %ecx
19174+ and $THREAD_SIZE_asm - 1, %ecx
19175+ shr $3, %ecx
19176+ repne scasq
19177+ jecxz 2f
19178+
19179+ cmp $2*8, %ecx
19180+ jc 2f
19181+
19182+ mov $2*8, %ecx
19183+ repe scasq
19184+ jecxz 2f
19185+ jne 1b
19186+
19187+2: cld
19188+ mov %esp, %ecx
19189+ sub %edi, %ecx
19190+
19191+ cmp $THREAD_SIZE_asm, %rcx
19192+ jb 3f
19193+ ud2
19194+3:
19195+
19196+ shr $3, %ecx
19197+ rep stosq
19198+
19199+ mov TI_task_thread_sp0(%r11), %rdi
19200+ sub $256, %rdi
19201+ mov %rdi, TI_lowest_stack(%r11)
19202+
19203+ popq %r11
19204+ popq %rax
19205+ popq %rcx
19206+ popq %rdi
19207+ pax_force_retaddr
19208+ ret
19209+ENDPROC(pax_erase_kstack)
19210+#endif
19211
19212 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19213 #ifdef CONFIG_TRACE_IRQFLAGS
19214@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
19215 .endm
19216
19217 .macro UNFAKE_STACK_FRAME
19218- addq $8*6, %rsp
19219- CFI_ADJUST_CFA_OFFSET -(6*8)
19220+ addq $8*6 + ARG_SKIP, %rsp
19221+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19222 .endm
19223
19224 /*
19225@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
19226 movq %rsp, %rsi
19227
19228 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19229- testl $3, CS-RBP(%rsi)
19230+ testb $3, CS-RBP(%rsi)
19231 je 1f
19232 SWAPGS
19233 /*
19234@@ -498,9 +774,10 @@ ENTRY(save_rest)
19235 movq_cfi r15, R15+16
19236 movq %r11, 8(%rsp) /* return address */
19237 FIXUP_TOP_OF_STACK %r11, 16
19238+ pax_force_retaddr
19239 ret
19240 CFI_ENDPROC
19241-END(save_rest)
19242+ENDPROC(save_rest)
19243
19244 /* save complete stack frame */
19245 .pushsection .kprobes.text, "ax"
19246@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
19247 js 1f /* negative -> in kernel */
19248 SWAPGS
19249 xorl %ebx,%ebx
19250-1: ret
19251+1: pax_force_retaddr_bts
19252+ ret
19253 CFI_ENDPROC
19254-END(save_paranoid)
19255+ENDPROC(save_paranoid)
19256 .popsection
19257
19258 /*
19259@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
19260
19261 RESTORE_REST
19262
19263- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19264+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19265 jz 1f
19266
19267 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19268@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
19269 RESTORE_REST
19270 jmp int_ret_from_sys_call
19271 CFI_ENDPROC
19272-END(ret_from_fork)
19273+ENDPROC(ret_from_fork)
19274
19275 /*
19276 * System call entry. Up to 6 arguments in registers are supported.
19277@@ -608,7 +886,7 @@ END(ret_from_fork)
19278 ENTRY(system_call)
19279 CFI_STARTPROC simple
19280 CFI_SIGNAL_FRAME
19281- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19282+ CFI_DEF_CFA rsp,0
19283 CFI_REGISTER rip,rcx
19284 /*CFI_REGISTER rflags,r11*/
19285 SWAPGS_UNSAFE_STACK
19286@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
19287
19288 movq %rsp,PER_CPU_VAR(old_rsp)
19289 movq PER_CPU_VAR(kernel_stack),%rsp
19290+ SAVE_ARGS 8*6,0
19291+ pax_enter_kernel_user
19292+
19293+#ifdef CONFIG_PAX_RANDKSTACK
19294+ pax_erase_kstack
19295+#endif
19296+
19297 /*
19298 * No need to follow this irqs off/on section - it's straight
19299 * and short:
19300 */
19301 ENABLE_INTERRUPTS(CLBR_NONE)
19302- SAVE_ARGS 8,0
19303 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19304 movq %rcx,RIP-ARGOFFSET(%rsp)
19305 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19306- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19307+ GET_THREAD_INFO(%rcx)
19308+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19309 jnz tracesys
19310 system_call_fastpath:
19311 #if __SYSCALL_MASK == ~0
19312@@ -640,7 +925,7 @@ system_call_fastpath:
19313 cmpl $__NR_syscall_max,%eax
19314 #endif
19315 ja badsys
19316- movq %r10,%rcx
19317+ movq R10-ARGOFFSET(%rsp),%rcx
19318 call *sys_call_table(,%rax,8) # XXX: rip relative
19319 movq %rax,RAX-ARGOFFSET(%rsp)
19320 /*
19321@@ -654,10 +939,13 @@ sysret_check:
19322 LOCKDEP_SYS_EXIT
19323 DISABLE_INTERRUPTS(CLBR_NONE)
19324 TRACE_IRQS_OFF
19325- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19326+ GET_THREAD_INFO(%rcx)
19327+ movl TI_flags(%rcx),%edx
19328 andl %edi,%edx
19329 jnz sysret_careful
19330 CFI_REMEMBER_STATE
19331+ pax_exit_kernel_user
19332+ pax_erase_kstack
19333 /*
19334 * sysretq will re-enable interrupts:
19335 */
19336@@ -709,14 +997,18 @@ badsys:
19337 * jump back to the normal fast path.
19338 */
19339 auditsys:
19340- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19341+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19342 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19343 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19344 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19345 movq %rax,%rsi /* 2nd arg: syscall number */
19346 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19347 call __audit_syscall_entry
19348+
19349+ pax_erase_kstack
19350+
19351 LOAD_ARGS 0 /* reload call-clobbered registers */
19352+ pax_set_fptr_mask
19353 jmp system_call_fastpath
19354
19355 /*
19356@@ -737,7 +1029,7 @@ sysret_audit:
19357 /* Do syscall tracing */
19358 tracesys:
19359 #ifdef CONFIG_AUDITSYSCALL
19360- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19361+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19362 jz auditsys
19363 #endif
19364 SAVE_REST
19365@@ -745,12 +1037,16 @@ tracesys:
19366 FIXUP_TOP_OF_STACK %rdi
19367 movq %rsp,%rdi
19368 call syscall_trace_enter
19369+
19370+ pax_erase_kstack
19371+
19372 /*
19373 * Reload arg registers from stack in case ptrace changed them.
19374 * We don't reload %rax because syscall_trace_enter() returned
19375 * the value it wants us to use in the table lookup.
19376 */
19377 LOAD_ARGS ARGOFFSET, 1
19378+ pax_set_fptr_mask
19379 RESTORE_REST
19380 #if __SYSCALL_MASK == ~0
19381 cmpq $__NR_syscall_max,%rax
19382@@ -759,7 +1055,7 @@ tracesys:
19383 cmpl $__NR_syscall_max,%eax
19384 #endif
19385 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19386- movq %r10,%rcx /* fixup for C */
19387+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19388 call *sys_call_table(,%rax,8)
19389 movq %rax,RAX-ARGOFFSET(%rsp)
19390 /* Use IRET because user could have changed frame */
19391@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
19392 andl %edi,%edx
19393 jnz int_careful
19394 andl $~TS_COMPAT,TI_status(%rcx)
19395- jmp retint_swapgs
19396+ pax_exit_kernel_user
19397+ pax_erase_kstack
19398+ jmp retint_swapgs_pax
19399
19400 /* Either reschedule or signal or syscall exit tracking needed. */
19401 /* First do a reschedule test. */
19402@@ -826,7 +1124,7 @@ int_restore_rest:
19403 TRACE_IRQS_OFF
19404 jmp int_with_check
19405 CFI_ENDPROC
19406-END(system_call)
19407+ENDPROC(system_call)
19408
19409 /*
19410 * Certain special system calls that need to save a complete full stack frame.
19411@@ -842,7 +1140,7 @@ ENTRY(\label)
19412 call \func
19413 jmp ptregscall_common
19414 CFI_ENDPROC
19415-END(\label)
19416+ENDPROC(\label)
19417 .endm
19418
19419 .macro FORK_LIKE func
19420@@ -856,9 +1154,10 @@ ENTRY(stub_\func)
19421 DEFAULT_FRAME 0 8 /* offset 8: return address */
19422 call sys_\func
19423 RESTORE_TOP_OF_STACK %r11, 8
19424+ pax_force_retaddr
19425 ret $REST_SKIP /* pop extended registers */
19426 CFI_ENDPROC
19427-END(stub_\func)
19428+ENDPROC(stub_\func)
19429 .endm
19430
19431 FORK_LIKE clone
19432@@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
19433 movq_cfi_restore R12+8, r12
19434 movq_cfi_restore RBP+8, rbp
19435 movq_cfi_restore RBX+8, rbx
19436+ pax_force_retaddr
19437 ret $REST_SKIP /* pop extended registers */
19438 CFI_ENDPROC
19439-END(ptregscall_common)
19440+ENDPROC(ptregscall_common)
19441
19442 ENTRY(stub_execve)
19443 CFI_STARTPROC
19444@@ -891,7 +1191,7 @@ ENTRY(stub_execve)
19445 RESTORE_REST
19446 jmp int_ret_from_sys_call
19447 CFI_ENDPROC
19448-END(stub_execve)
19449+ENDPROC(stub_execve)
19450
19451 /*
19452 * sigreturn is special because it needs to restore all registers on return.
19453@@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
19454 RESTORE_REST
19455 jmp int_ret_from_sys_call
19456 CFI_ENDPROC
19457-END(stub_rt_sigreturn)
19458+ENDPROC(stub_rt_sigreturn)
19459
19460 #ifdef CONFIG_X86_X32_ABI
19461 ENTRY(stub_x32_rt_sigreturn)
19462@@ -975,7 +1275,7 @@ vector=vector+1
19463 2: jmp common_interrupt
19464 .endr
19465 CFI_ENDPROC
19466-END(irq_entries_start)
19467+ENDPROC(irq_entries_start)
19468
19469 .previous
19470 END(interrupt)
19471@@ -995,6 +1295,16 @@ END(interrupt)
19472 subq $ORIG_RAX-RBP, %rsp
19473 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19474 SAVE_ARGS_IRQ
19475+#ifdef CONFIG_PAX_MEMORY_UDEREF
19476+ testb $3, CS(%rdi)
19477+ jnz 1f
19478+ pax_enter_kernel
19479+ jmp 2f
19480+1: pax_enter_kernel_user
19481+2:
19482+#else
19483+ pax_enter_kernel
19484+#endif
19485 call \func
19486 .endm
19487
19488@@ -1027,7 +1337,7 @@ ret_from_intr:
19489
19490 exit_intr:
19491 GET_THREAD_INFO(%rcx)
19492- testl $3,CS-ARGOFFSET(%rsp)
19493+ testb $3,CS-ARGOFFSET(%rsp)
19494 je retint_kernel
19495
19496 /* Interrupt came from user space */
19497@@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
19498 * The iretq could re-enable interrupts:
19499 */
19500 DISABLE_INTERRUPTS(CLBR_ANY)
19501+ pax_exit_kernel_user
19502+retint_swapgs_pax:
19503 TRACE_IRQS_IRETQ
19504 SWAPGS
19505 jmp restore_args
19506
19507 retint_restore_args: /* return to kernel space */
19508 DISABLE_INTERRUPTS(CLBR_ANY)
19509+ pax_exit_kernel
19510+ pax_force_retaddr (RIP-ARGOFFSET)
19511 /*
19512 * The iretq could re-enable interrupts:
19513 */
19514@@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
19515 #endif
19516
19517 CFI_ENDPROC
19518-END(common_interrupt)
19519+ENDPROC(common_interrupt)
19520 /*
19521 * End of kprobes section
19522 */
19523@@ -1155,7 +1469,7 @@ ENTRY(\sym)
19524 interrupt \do_sym
19525 jmp ret_from_intr
19526 CFI_ENDPROC
19527-END(\sym)
19528+ENDPROC(\sym)
19529 .endm
19530
19531 #ifdef CONFIG_SMP
19532@@ -1211,12 +1525,22 @@ ENTRY(\sym)
19533 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19534 call error_entry
19535 DEFAULT_FRAME 0
19536+#ifdef CONFIG_PAX_MEMORY_UDEREF
19537+ testb $3, CS(%rsp)
19538+ jnz 1f
19539+ pax_enter_kernel
19540+ jmp 2f
19541+1: pax_enter_kernel_user
19542+2:
19543+#else
19544+ pax_enter_kernel
19545+#endif
19546 movq %rsp,%rdi /* pt_regs pointer */
19547 xorl %esi,%esi /* no error code */
19548 call \do_sym
19549 jmp error_exit /* %ebx: no swapgs flag */
19550 CFI_ENDPROC
19551-END(\sym)
19552+ENDPROC(\sym)
19553 .endm
19554
19555 .macro paranoidzeroentry sym do_sym
19556@@ -1229,15 +1553,25 @@ ENTRY(\sym)
19557 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19558 call save_paranoid
19559 TRACE_IRQS_OFF
19560+#ifdef CONFIG_PAX_MEMORY_UDEREF
19561+ testb $3, CS(%rsp)
19562+ jnz 1f
19563+ pax_enter_kernel
19564+ jmp 2f
19565+1: pax_enter_kernel_user
19566+2:
19567+#else
19568+ pax_enter_kernel
19569+#endif
19570 movq %rsp,%rdi /* pt_regs pointer */
19571 xorl %esi,%esi /* no error code */
19572 call \do_sym
19573 jmp paranoid_exit /* %ebx: no swapgs flag */
19574 CFI_ENDPROC
19575-END(\sym)
19576+ENDPROC(\sym)
19577 .endm
19578
19579-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19580+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19581 .macro paranoidzeroentry_ist sym do_sym ist
19582 ENTRY(\sym)
19583 INTR_FRAME
19584@@ -1248,14 +1582,30 @@ ENTRY(\sym)
19585 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19586 call save_paranoid
19587 TRACE_IRQS_OFF_DEBUG
19588+#ifdef CONFIG_PAX_MEMORY_UDEREF
19589+ testb $3, CS(%rsp)
19590+ jnz 1f
19591+ pax_enter_kernel
19592+ jmp 2f
19593+1: pax_enter_kernel_user
19594+2:
19595+#else
19596+ pax_enter_kernel
19597+#endif
19598 movq %rsp,%rdi /* pt_regs pointer */
19599 xorl %esi,%esi /* no error code */
19600+#ifdef CONFIG_SMP
19601+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19602+ lea init_tss(%r12), %r12
19603+#else
19604+ lea init_tss(%rip), %r12
19605+#endif
19606 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19607 call \do_sym
19608 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19609 jmp paranoid_exit /* %ebx: no swapgs flag */
19610 CFI_ENDPROC
19611-END(\sym)
19612+ENDPROC(\sym)
19613 .endm
19614
19615 .macro errorentry sym do_sym
19616@@ -1267,13 +1617,23 @@ ENTRY(\sym)
19617 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19618 call error_entry
19619 DEFAULT_FRAME 0
19620+#ifdef CONFIG_PAX_MEMORY_UDEREF
19621+ testb $3, CS(%rsp)
19622+ jnz 1f
19623+ pax_enter_kernel
19624+ jmp 2f
19625+1: pax_enter_kernel_user
19626+2:
19627+#else
19628+ pax_enter_kernel
19629+#endif
19630 movq %rsp,%rdi /* pt_regs pointer */
19631 movq ORIG_RAX(%rsp),%rsi /* get error code */
19632 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19633 call \do_sym
19634 jmp error_exit /* %ebx: no swapgs flag */
19635 CFI_ENDPROC
19636-END(\sym)
19637+ENDPROC(\sym)
19638 .endm
19639
19640 /* error code is on the stack already */
19641@@ -1287,13 +1647,23 @@ ENTRY(\sym)
19642 call save_paranoid
19643 DEFAULT_FRAME 0
19644 TRACE_IRQS_OFF
19645+#ifdef CONFIG_PAX_MEMORY_UDEREF
19646+ testb $3, CS(%rsp)
19647+ jnz 1f
19648+ pax_enter_kernel
19649+ jmp 2f
19650+1: pax_enter_kernel_user
19651+2:
19652+#else
19653+ pax_enter_kernel
19654+#endif
19655 movq %rsp,%rdi /* pt_regs pointer */
19656 movq ORIG_RAX(%rsp),%rsi /* get error code */
19657 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19658 call \do_sym
19659 jmp paranoid_exit /* %ebx: no swapgs flag */
19660 CFI_ENDPROC
19661-END(\sym)
19662+ENDPROC(\sym)
19663 .endm
19664
19665 zeroentry divide_error do_divide_error
19666@@ -1323,9 +1693,10 @@ gs_change:
19667 2: mfence /* workaround */
19668 SWAPGS
19669 popfq_cfi
19670+ pax_force_retaddr
19671 ret
19672 CFI_ENDPROC
19673-END(native_load_gs_index)
19674+ENDPROC(native_load_gs_index)
19675
19676 _ASM_EXTABLE(gs_change,bad_gs)
19677 .section .fixup,"ax"
19678@@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19679 CFI_DEF_CFA_REGISTER rsp
19680 CFI_ADJUST_CFA_OFFSET -8
19681 decl PER_CPU_VAR(irq_count)
19682+ pax_force_retaddr
19683 ret
19684 CFI_ENDPROC
19685-END(call_softirq)
19686+ENDPROC(call_softirq)
19687
19688 #ifdef CONFIG_XEN
19689 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19690@@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19691 decl PER_CPU_VAR(irq_count)
19692 jmp error_exit
19693 CFI_ENDPROC
19694-END(xen_do_hypervisor_callback)
19695+ENDPROC(xen_do_hypervisor_callback)
19696
19697 /*
19698 * Hypervisor uses this for application faults while it executes.
19699@@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19700 SAVE_ALL
19701 jmp error_exit
19702 CFI_ENDPROC
19703-END(xen_failsafe_callback)
19704+ENDPROC(xen_failsafe_callback)
19705
19706 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19707 xen_hvm_callback_vector xen_evtchn_do_upcall
19708@@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19709 TRACE_IRQS_OFF_DEBUG
19710 testl %ebx,%ebx /* swapgs needed? */
19711 jnz paranoid_restore
19712- testl $3,CS(%rsp)
19713+ testb $3,CS(%rsp)
19714 jnz paranoid_userspace
19715+#ifdef CONFIG_PAX_MEMORY_UDEREF
19716+ pax_exit_kernel
19717+ TRACE_IRQS_IRETQ 0
19718+ SWAPGS_UNSAFE_STACK
19719+ RESTORE_ALL 8
19720+ pax_force_retaddr_bts
19721+ jmp irq_return
19722+#endif
19723 paranoid_swapgs:
19724+#ifdef CONFIG_PAX_MEMORY_UDEREF
19725+ pax_exit_kernel_user
19726+#else
19727+ pax_exit_kernel
19728+#endif
19729 TRACE_IRQS_IRETQ 0
19730 SWAPGS_UNSAFE_STACK
19731 RESTORE_ALL 8
19732 jmp irq_return
19733 paranoid_restore:
19734+ pax_exit_kernel
19735 TRACE_IRQS_IRETQ_DEBUG 0
19736 RESTORE_ALL 8
19737+ pax_force_retaddr_bts
19738 jmp irq_return
19739 paranoid_userspace:
19740 GET_THREAD_INFO(%rcx)
19741@@ -1539,7 +1926,7 @@ paranoid_schedule:
19742 TRACE_IRQS_OFF
19743 jmp paranoid_userspace
19744 CFI_ENDPROC
19745-END(paranoid_exit)
19746+ENDPROC(paranoid_exit)
19747
19748 /*
19749 * Exception entry point. This expects an error code/orig_rax on the stack.
19750@@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19751 movq_cfi r14, R14+8
19752 movq_cfi r15, R15+8
19753 xorl %ebx,%ebx
19754- testl $3,CS+8(%rsp)
19755+ testb $3,CS+8(%rsp)
19756 je error_kernelspace
19757 error_swapgs:
19758 SWAPGS
19759 error_sti:
19760 TRACE_IRQS_OFF
19761+ pax_force_retaddr_bts
19762 ret
19763
19764 /*
19765@@ -1598,7 +1986,7 @@ bstep_iret:
19766 movq %rcx,RIP+8(%rsp)
19767 jmp error_swapgs
19768 CFI_ENDPROC
19769-END(error_entry)
19770+ENDPROC(error_entry)
19771
19772
19773 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19774@@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19775 jnz retint_careful
19776 jmp retint_swapgs
19777 CFI_ENDPROC
19778-END(error_exit)
19779+ENDPROC(error_exit)
19780
19781 /*
19782 * Test if a given stack is an NMI stack or not.
19783@@ -1676,9 +2064,11 @@ ENTRY(nmi)
19784 * If %cs was not the kernel segment, then the NMI triggered in user
19785 * space, which means it is definitely not nested.
19786 */
19787+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19788+ je 1f
19789 cmpl $__KERNEL_CS, 16(%rsp)
19790 jne first_nmi
19791-
19792+1:
19793 /*
19794 * Check the special variable on the stack to see if NMIs are
19795 * executing.
19796@@ -1847,6 +2237,17 @@ end_repeat_nmi:
19797 */
19798 movq %cr2, %r12
19799
19800+#ifdef CONFIG_PAX_MEMORY_UDEREF
19801+ testb $3, CS(%rsp)
19802+ jnz 1f
19803+ pax_enter_kernel
19804+ jmp 2f
19805+1: pax_enter_kernel_user
19806+2:
19807+#else
19808+ pax_enter_kernel
19809+#endif
19810+
19811 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19812 movq %rsp,%rdi
19813 movq $-1,%rsi
19814@@ -1862,23 +2263,34 @@ end_repeat_nmi:
19815 testl %ebx,%ebx /* swapgs needed? */
19816 jnz nmi_restore
19817 nmi_swapgs:
19818+#ifdef CONFIG_PAX_MEMORY_UDEREF
19819+ pax_exit_kernel_user
19820+#else
19821+ pax_exit_kernel
19822+#endif
19823 SWAPGS_UNSAFE_STACK
19824+ RESTORE_ALL 6*8
19825+ /* Clear the NMI executing stack variable */
19826+ movq $0, 5*8(%rsp)
19827+ jmp irq_return
19828 nmi_restore:
19829+ pax_exit_kernel
19830 /* Pop the extra iret frame at once */
19831 RESTORE_ALL 6*8
19832+ pax_force_retaddr_bts
19833
19834 /* Clear the NMI executing stack variable */
19835 movq $0, 5*8(%rsp)
19836 jmp irq_return
19837 CFI_ENDPROC
19838-END(nmi)
19839+ENDPROC(nmi)
19840
19841 ENTRY(ignore_sysret)
19842 CFI_STARTPROC
19843 mov $-ENOSYS,%eax
19844 sysret
19845 CFI_ENDPROC
19846-END(ignore_sysret)
19847+ENDPROC(ignore_sysret)
19848
19849 /*
19850 * End of kprobes section
19851diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19852index 1d41402..af9a46a 100644
19853--- a/arch/x86/kernel/ftrace.c
19854+++ b/arch/x86/kernel/ftrace.c
19855@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19856 {
19857 unsigned char replaced[MCOUNT_INSN_SIZE];
19858
19859+ ip = ktla_ktva(ip);
19860+
19861 /*
19862 * Note: Due to modules and __init, code can
19863 * disappear and change, we need to protect against faulting
19864@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19865 unsigned char old[MCOUNT_INSN_SIZE], *new;
19866 int ret;
19867
19868- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19869+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19870 new = ftrace_call_replace(ip, (unsigned long)func);
19871
19872 /* See comment above by declaration of modifying_ftrace_code */
19873@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19874 /* Also update the regs callback function */
19875 if (!ret) {
19876 ip = (unsigned long)(&ftrace_regs_call);
19877- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19878+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19879 new = ftrace_call_replace(ip, (unsigned long)func);
19880 ret = ftrace_modify_code(ip, old, new);
19881 }
19882@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19883 * kernel identity mapping to modify code.
19884 */
19885 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19886- ip = (unsigned long)__va(__pa(ip));
19887+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19888
19889 return probe_kernel_write((void *)ip, val, size);
19890 }
19891@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19892 unsigned char replaced[MCOUNT_INSN_SIZE];
19893 unsigned char brk = BREAKPOINT_INSTRUCTION;
19894
19895- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19896+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19897 return -EFAULT;
19898
19899 /* Make sure it is what we expect it to be */
19900@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19901 return ret;
19902
19903 fail_update:
19904- probe_kernel_write((void *)ip, &old_code[0], 1);
19905+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19906 goto out;
19907 }
19908
19909@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19910 {
19911 unsigned char code[MCOUNT_INSN_SIZE];
19912
19913+ ip = ktla_ktva(ip);
19914+
19915 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19916 return -EFAULT;
19917
19918diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19919index c18f59d..9c0c9f6 100644
19920--- a/arch/x86/kernel/head32.c
19921+++ b/arch/x86/kernel/head32.c
19922@@ -18,6 +18,7 @@
19923 #include <asm/io_apic.h>
19924 #include <asm/bios_ebda.h>
19925 #include <asm/tlbflush.h>
19926+#include <asm/boot.h>
19927
19928 static void __init i386_default_early_setup(void)
19929 {
19930@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19931
19932 void __init i386_start_kernel(void)
19933 {
19934- memblock_reserve(__pa_symbol(&_text),
19935- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19936+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19937
19938 #ifdef CONFIG_BLK_DEV_INITRD
19939 /* Reserve INITRD */
19940diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19941index c8932c7..d56b622 100644
19942--- a/arch/x86/kernel/head_32.S
19943+++ b/arch/x86/kernel/head_32.S
19944@@ -26,6 +26,12 @@
19945 /* Physical address */
19946 #define pa(X) ((X) - __PAGE_OFFSET)
19947
19948+#ifdef CONFIG_PAX_KERNEXEC
19949+#define ta(X) (X)
19950+#else
19951+#define ta(X) ((X) - __PAGE_OFFSET)
19952+#endif
19953+
19954 /*
19955 * References to members of the new_cpu_data structure.
19956 */
19957@@ -55,11 +61,7 @@
19958 * and small than max_low_pfn, otherwise will waste some page table entries
19959 */
19960
19961-#if PTRS_PER_PMD > 1
19962-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19963-#else
19964-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19965-#endif
19966+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19967
19968 /* Number of possible pages in the lowmem region */
19969 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19970@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19971 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19972
19973 /*
19974+ * Real beginning of normal "text" segment
19975+ */
19976+ENTRY(stext)
19977+ENTRY(_stext)
19978+
19979+/*
19980 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19981 * %esi points to the real-mode code as a 32-bit pointer.
19982 * CS and DS must be 4 GB flat segments, but we don't depend on
19983@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19984 * can.
19985 */
19986 __HEAD
19987+
19988+#ifdef CONFIG_PAX_KERNEXEC
19989+ jmp startup_32
19990+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19991+.fill PAGE_SIZE-5,1,0xcc
19992+#endif
19993+
19994 ENTRY(startup_32)
19995 movl pa(stack_start),%ecx
19996
19997@@ -106,6 +121,59 @@ ENTRY(startup_32)
19998 2:
19999 leal -__PAGE_OFFSET(%ecx),%esp
20000
20001+#ifdef CONFIG_SMP
20002+ movl $pa(cpu_gdt_table),%edi
20003+ movl $__per_cpu_load,%eax
20004+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20005+ rorl $16,%eax
20006+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20007+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20008+ movl $__per_cpu_end - 1,%eax
20009+ subl $__per_cpu_start,%eax
20010+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20011+#endif
20012+
20013+#ifdef CONFIG_PAX_MEMORY_UDEREF
20014+ movl $NR_CPUS,%ecx
20015+ movl $pa(cpu_gdt_table),%edi
20016+1:
20017+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20018+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20019+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20020+ addl $PAGE_SIZE_asm,%edi
20021+ loop 1b
20022+#endif
20023+
20024+#ifdef CONFIG_PAX_KERNEXEC
20025+ movl $pa(boot_gdt),%edi
20026+ movl $__LOAD_PHYSICAL_ADDR,%eax
20027+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20028+ rorl $16,%eax
20029+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20030+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20031+ rorl $16,%eax
20032+
20033+ ljmp $(__BOOT_CS),$1f
20034+1:
20035+
20036+ movl $NR_CPUS,%ecx
20037+ movl $pa(cpu_gdt_table),%edi
20038+ addl $__PAGE_OFFSET,%eax
20039+1:
20040+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20041+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20042+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20043+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20044+ rorl $16,%eax
20045+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20046+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20047+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20048+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20049+ rorl $16,%eax
20050+ addl $PAGE_SIZE_asm,%edi
20051+ loop 1b
20052+#endif
20053+
20054 /*
20055 * Clear BSS first so that there are no surprises...
20056 */
20057@@ -196,8 +264,11 @@ ENTRY(startup_32)
20058 movl %eax, pa(max_pfn_mapped)
20059
20060 /* Do early initialization of the fixmap area */
20061- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20062- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20063+#ifdef CONFIG_COMPAT_VDSO
20064+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20065+#else
20066+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20067+#endif
20068 #else /* Not PAE */
20069
20070 page_pde_offset = (__PAGE_OFFSET >> 20);
20071@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20072 movl %eax, pa(max_pfn_mapped)
20073
20074 /* Do early initialization of the fixmap area */
20075- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20076- movl %eax,pa(initial_page_table+0xffc)
20077+#ifdef CONFIG_COMPAT_VDSO
20078+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20079+#else
20080+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20081+#endif
20082 #endif
20083
20084 #ifdef CONFIG_PARAVIRT
20085@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20086 cmpl $num_subarch_entries, %eax
20087 jae bad_subarch
20088
20089- movl pa(subarch_entries)(,%eax,4), %eax
20090- subl $__PAGE_OFFSET, %eax
20091- jmp *%eax
20092+ jmp *pa(subarch_entries)(,%eax,4)
20093
20094 bad_subarch:
20095 WEAK(lguest_entry)
20096@@ -256,10 +328,10 @@ WEAK(xen_entry)
20097 __INITDATA
20098
20099 subarch_entries:
20100- .long default_entry /* normal x86/PC */
20101- .long lguest_entry /* lguest hypervisor */
20102- .long xen_entry /* Xen hypervisor */
20103- .long default_entry /* Moorestown MID */
20104+ .long ta(default_entry) /* normal x86/PC */
20105+ .long ta(lguest_entry) /* lguest hypervisor */
20106+ .long ta(xen_entry) /* Xen hypervisor */
20107+ .long ta(default_entry) /* Moorestown MID */
20108 num_subarch_entries = (. - subarch_entries) / 4
20109 .previous
20110 #else
20111@@ -335,6 +407,7 @@ default_entry:
20112 movl pa(mmu_cr4_features),%eax
20113 movl %eax,%cr4
20114
20115+#ifdef CONFIG_X86_PAE
20116 testb $X86_CR4_PAE, %al # check if PAE is enabled
20117 jz 6f
20118
20119@@ -363,6 +436,9 @@ default_entry:
20120 /* Make changes effective */
20121 wrmsr
20122
20123+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20124+#endif
20125+
20126 6:
20127
20128 /*
20129@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
20130 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20131 movl %eax,%ss # after changing gdt.
20132
20133- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20134+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20135 movl %eax,%ds
20136 movl %eax,%es
20137
20138 movl $(__KERNEL_PERCPU), %eax
20139 movl %eax,%fs # set this cpu's percpu
20140
20141+#ifdef CONFIG_CC_STACKPROTECTOR
20142 movl $(__KERNEL_STACK_CANARY),%eax
20143+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20144+ movl $(__USER_DS),%eax
20145+#else
20146+ xorl %eax,%eax
20147+#endif
20148 movl %eax,%gs
20149
20150 xorl %eax,%eax # Clear LDT
20151@@ -544,8 +626,11 @@ setup_once:
20152 * relocation. Manually set base address in stack canary
20153 * segment descriptor.
20154 */
20155- movl $gdt_page,%eax
20156+ movl $cpu_gdt_table,%eax
20157 movl $stack_canary,%ecx
20158+#ifdef CONFIG_SMP
20159+ addl $__per_cpu_load,%ecx
20160+#endif
20161 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20162 shrl $16, %ecx
20163 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20164@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
20165 /* This is global to keep gas from relaxing the jumps */
20166 ENTRY(early_idt_handler)
20167 cld
20168- cmpl $2,%ss:early_recursion_flag
20169+ cmpl $1,%ss:early_recursion_flag
20170 je hlt_loop
20171 incl %ss:early_recursion_flag
20172
20173@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
20174 pushl (20+6*4)(%esp) /* trapno */
20175 pushl $fault_msg
20176 call printk
20177-#endif
20178 call dump_stack
20179+#endif
20180 hlt_loop:
20181 hlt
20182 jmp hlt_loop
20183@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
20184 /* This is the default interrupt "handler" :-) */
20185 ALIGN
20186 ignore_int:
20187- cld
20188 #ifdef CONFIG_PRINTK
20189+ cmpl $2,%ss:early_recursion_flag
20190+ je hlt_loop
20191+ incl %ss:early_recursion_flag
20192+ cld
20193 pushl %eax
20194 pushl %ecx
20195 pushl %edx
20196@@ -644,9 +732,6 @@ ignore_int:
20197 movl $(__KERNEL_DS),%eax
20198 movl %eax,%ds
20199 movl %eax,%es
20200- cmpl $2,early_recursion_flag
20201- je hlt_loop
20202- incl early_recursion_flag
20203 pushl 16(%esp)
20204 pushl 24(%esp)
20205 pushl 32(%esp)
20206@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
20207 /*
20208 * BSS section
20209 */
20210-__PAGE_ALIGNED_BSS
20211- .align PAGE_SIZE
20212 #ifdef CONFIG_X86_PAE
20213+.section .initial_pg_pmd,"a",@progbits
20214 initial_pg_pmd:
20215 .fill 1024*KPMDS,4,0
20216 #else
20217+.section .initial_page_table,"a",@progbits
20218 ENTRY(initial_page_table)
20219 .fill 1024,4,0
20220 #endif
20221+.section .initial_pg_fixmap,"a",@progbits
20222 initial_pg_fixmap:
20223 .fill 1024,4,0
20224+.section .empty_zero_page,"a",@progbits
20225 ENTRY(empty_zero_page)
20226 .fill 4096,1,0
20227+.section .swapper_pg_dir,"a",@progbits
20228 ENTRY(swapper_pg_dir)
20229+#ifdef CONFIG_X86_PAE
20230+ .fill 4,8,0
20231+#else
20232 .fill 1024,4,0
20233+#endif
20234+
20235+/*
20236+ * The IDT has to be page-aligned to simplify the Pentium
20237+ * F0 0F bug workaround.. We have a special link segment
20238+ * for this.
20239+ */
20240+.section .idt,"a",@progbits
20241+ENTRY(idt_table)
20242+ .fill 256,8,0
20243
20244 /*
20245 * This starts the data section.
20246 */
20247 #ifdef CONFIG_X86_PAE
20248-__PAGE_ALIGNED_DATA
20249- /* Page-aligned for the benefit of paravirt? */
20250- .align PAGE_SIZE
20251+.section .initial_page_table,"a",@progbits
20252 ENTRY(initial_page_table)
20253 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20254 # if KPMDS == 3
20255@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
20256 # error "Kernel PMDs should be 1, 2 or 3"
20257 # endif
20258 .align PAGE_SIZE /* needs to be page-sized too */
20259+
20260+#ifdef CONFIG_PAX_PER_CPU_PGD
20261+ENTRY(cpu_pgd)
20262+ .rept NR_CPUS
20263+ .fill 4,8,0
20264+ .endr
20265+#endif
20266+
20267 #endif
20268
20269 .data
20270 .balign 4
20271 ENTRY(stack_start)
20272- .long init_thread_union+THREAD_SIZE
20273+ .long init_thread_union+THREAD_SIZE-8
20274
20275 __INITRODATA
20276 int_msg:
20277@@ -754,7 +861,7 @@ fault_msg:
20278 * segment size, and 32-bit linear address value:
20279 */
20280
20281- .data
20282+.section .rodata,"a",@progbits
20283 .globl boot_gdt_descr
20284 .globl idt_descr
20285
20286@@ -763,7 +870,7 @@ fault_msg:
20287 .word 0 # 32 bit align gdt_desc.address
20288 boot_gdt_descr:
20289 .word __BOOT_DS+7
20290- .long boot_gdt - __PAGE_OFFSET
20291+ .long pa(boot_gdt)
20292
20293 .word 0 # 32-bit align idt_desc.address
20294 idt_descr:
20295@@ -774,7 +881,7 @@ idt_descr:
20296 .word 0 # 32 bit align gdt_desc.address
20297 ENTRY(early_gdt_descr)
20298 .word GDT_ENTRIES*8-1
20299- .long gdt_page /* Overwritten for secondary CPUs */
20300+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20301
20302 /*
20303 * The boot_gdt must mirror the equivalent in setup.S and is
20304@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
20305 .align L1_CACHE_BYTES
20306 ENTRY(boot_gdt)
20307 .fill GDT_ENTRY_BOOT_CS,8,0
20308- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20309- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20310+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20311+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20312+
20313+ .align PAGE_SIZE_asm
20314+ENTRY(cpu_gdt_table)
20315+ .rept NR_CPUS
20316+ .quad 0x0000000000000000 /* NULL descriptor */
20317+ .quad 0x0000000000000000 /* 0x0b reserved */
20318+ .quad 0x0000000000000000 /* 0x13 reserved */
20319+ .quad 0x0000000000000000 /* 0x1b reserved */
20320+
20321+#ifdef CONFIG_PAX_KERNEXEC
20322+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20323+#else
20324+ .quad 0x0000000000000000 /* 0x20 unused */
20325+#endif
20326+
20327+ .quad 0x0000000000000000 /* 0x28 unused */
20328+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20329+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20330+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20331+ .quad 0x0000000000000000 /* 0x4b reserved */
20332+ .quad 0x0000000000000000 /* 0x53 reserved */
20333+ .quad 0x0000000000000000 /* 0x5b reserved */
20334+
20335+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20336+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20337+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20338+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20339+
20340+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20341+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20342+
20343+ /*
20344+ * Segments used for calling PnP BIOS have byte granularity.
20345+ * The code segments and data segments have fixed 64k limits,
20346+ * the transfer segment sizes are set at run time.
20347+ */
20348+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20349+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20350+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20351+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20352+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20353+
20354+ /*
20355+ * The APM segments have byte granularity and their bases
20356+ * are set at run time. All have 64k limits.
20357+ */
20358+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20359+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20360+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20361+
20362+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20363+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20364+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20365+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20366+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20367+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20368+
20369+ /* Be sure this is zeroed to avoid false validations in Xen */
20370+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20371+ .endr
20372diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20373index 980053c..74d3b44 100644
20374--- a/arch/x86/kernel/head_64.S
20375+++ b/arch/x86/kernel/head_64.S
20376@@ -20,6 +20,8 @@
20377 #include <asm/processor-flags.h>
20378 #include <asm/percpu.h>
20379 #include <asm/nops.h>
20380+#include <asm/cpufeature.h>
20381+#include <asm/alternative-asm.h>
20382
20383 #ifdef CONFIG_PARAVIRT
20384 #include <asm/asm-offsets.h>
20385@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20386 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20387 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20388 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20389+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20390+L3_VMALLOC_START = pud_index(VMALLOC_START)
20391+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20392+L3_VMALLOC_END = pud_index(VMALLOC_END)
20393+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20394+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20395
20396 .text
20397 __HEAD
20398@@ -88,35 +96,23 @@ startup_64:
20399 */
20400 addq %rbp, init_level4_pgt + 0(%rip)
20401 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20402+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20403+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20404+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20405 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20406
20407 addq %rbp, level3_ident_pgt + 0(%rip)
20408+#ifndef CONFIG_XEN
20409+ addq %rbp, level3_ident_pgt + 8(%rip)
20410+#endif
20411
20412- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20413- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20414+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20415+
20416+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20417+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20418
20419 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20420-
20421- /* Add an Identity mapping if I am above 1G */
20422- leaq _text(%rip), %rdi
20423- andq $PMD_PAGE_MASK, %rdi
20424-
20425- movq %rdi, %rax
20426- shrq $PUD_SHIFT, %rax
20427- andq $(PTRS_PER_PUD - 1), %rax
20428- jz ident_complete
20429-
20430- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20431- leaq level3_ident_pgt(%rip), %rbx
20432- movq %rdx, 0(%rbx, %rax, 8)
20433-
20434- movq %rdi, %rax
20435- shrq $PMD_SHIFT, %rax
20436- andq $(PTRS_PER_PMD - 1), %rax
20437- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20438- leaq level2_spare_pgt(%rip), %rbx
20439- movq %rdx, 0(%rbx, %rax, 8)
20440-ident_complete:
20441+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20442
20443 /*
20444 * Fixup the kernel text+data virtual addresses. Note that
20445@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20446 * after the boot processor executes this code.
20447 */
20448
20449- /* Enable PAE mode and PGE */
20450- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20451+ /* Enable PAE mode and PSE/PGE */
20452+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20453 movq %rax, %cr4
20454
20455 /* Setup early boot stage 4 level pagetables. */
20456@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20457 movl $MSR_EFER, %ecx
20458 rdmsr
20459 btsl $_EFER_SCE, %eax /* Enable System Call */
20460- btl $20,%edi /* No Execute supported? */
20461+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20462 jnc 1f
20463 btsl $_EFER_NX, %eax
20464+ leaq init_level4_pgt(%rip), %rdi
20465+#ifndef CONFIG_EFI
20466+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20467+#endif
20468+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20469+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20470+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20471+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20472 1: wrmsr /* Make changes effective */
20473
20474 /* Setup cr0 */
20475@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20476 * jump. In addition we need to ensure %cs is set so we make this
20477 * a far return.
20478 */
20479+ pax_set_fptr_mask
20480 movq initial_code(%rip),%rax
20481 pushq $0 # fake return address to stop unwinder
20482 pushq $__KERNEL_CS # set correct cs
20483@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20484 bad_address:
20485 jmp bad_address
20486
20487- .section ".init.text","ax"
20488+ __INIT
20489 .globl early_idt_handlers
20490 early_idt_handlers:
20491 # 104(%rsp) %rflags
20492@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20493 call dump_stack
20494 #ifdef CONFIG_KALLSYMS
20495 leaq early_idt_ripmsg(%rip),%rdi
20496- movq 40(%rsp),%rsi # %rip again
20497+ movq 88(%rsp),%rsi # %rip again
20498 call __print_symbol
20499 #endif
20500 #endif /* EARLY_PRINTK */
20501@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20502 addq $16,%rsp # drop vector number and error code
20503 decl early_recursion_flag(%rip)
20504 INTERRUPT_RETURN
20505+ .previous
20506
20507+ __INITDATA
20508 .balign 4
20509 early_recursion_flag:
20510 .long 0
20511+ .previous
20512
20513+ .section .rodata,"a",@progbits
20514 #ifdef CONFIG_EARLY_PRINTK
20515 early_idt_msg:
20516 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20517@@ -376,6 +385,7 @@ early_idt_ripmsg:
20518 #endif /* CONFIG_EARLY_PRINTK */
20519 .previous
20520
20521+ .section .rodata,"a",@progbits
20522 #define NEXT_PAGE(name) \
20523 .balign PAGE_SIZE; \
20524 ENTRY(name)
20525@@ -388,7 +398,6 @@ ENTRY(name)
20526 i = i + 1 ; \
20527 .endr
20528
20529- .data
20530 /*
20531 * This default setting generates an ident mapping at address 0x100000
20532 * and a mapping for the kernel that precisely maps virtual address
20533@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20534 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20535 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20536 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20537+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20538+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20539+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20540+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20541+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20542+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20543 .org init_level4_pgt + L4_START_KERNEL*8, 0
20544 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20545 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20546
20547+#ifdef CONFIG_PAX_PER_CPU_PGD
20548+NEXT_PAGE(cpu_pgd)
20549+ .rept NR_CPUS
20550+ .fill 512,8,0
20551+ .endr
20552+#endif
20553+
20554 NEXT_PAGE(level3_ident_pgt)
20555 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20556+#ifdef CONFIG_XEN
20557 .fill 511,8,0
20558+#else
20559+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20560+ .fill 510,8,0
20561+#endif
20562+
20563+NEXT_PAGE(level3_vmalloc_start_pgt)
20564+ .fill 512,8,0
20565+
20566+NEXT_PAGE(level3_vmalloc_end_pgt)
20567+ .fill 512,8,0
20568+
20569+NEXT_PAGE(level3_vmemmap_pgt)
20570+ .fill L3_VMEMMAP_START,8,0
20571+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20572
20573 NEXT_PAGE(level3_kernel_pgt)
20574 .fill L3_START_KERNEL,8,0
20575@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20576 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20577 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20578
20579+NEXT_PAGE(level2_vmemmap_pgt)
20580+ .fill 512,8,0
20581+
20582 NEXT_PAGE(level2_fixmap_pgt)
20583- .fill 506,8,0
20584- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20585- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20586- .fill 5,8,0
20587+ .fill 507,8,0
20588+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20589+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20590+ .fill 4,8,0
20591
20592-NEXT_PAGE(level1_fixmap_pgt)
20593+NEXT_PAGE(level1_vsyscall_pgt)
20594 .fill 512,8,0
20595
20596-NEXT_PAGE(level2_ident_pgt)
20597- /* Since I easily can, map the first 1G.
20598+ /* Since I easily can, map the first 2G.
20599 * Don't set NX because code runs from these pages.
20600 */
20601- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20602+NEXT_PAGE(level2_ident_pgt)
20603+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20604
20605 NEXT_PAGE(level2_kernel_pgt)
20606 /*
20607@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20608 * If you want to increase this then increase MODULES_VADDR
20609 * too.)
20610 */
20611- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20612- KERNEL_IMAGE_SIZE/PMD_SIZE)
20613-
20614-NEXT_PAGE(level2_spare_pgt)
20615- .fill 512, 8, 0
20616+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20617
20618 #undef PMDS
20619 #undef NEXT_PAGE
20620
20621- .data
20622+ .align PAGE_SIZE
20623+ENTRY(cpu_gdt_table)
20624+ .rept NR_CPUS
20625+ .quad 0x0000000000000000 /* NULL descriptor */
20626+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20627+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20628+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20629+ .quad 0x00cffb000000ffff /* __USER32_CS */
20630+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20631+ .quad 0x00affb000000ffff /* __USER_CS */
20632+
20633+#ifdef CONFIG_PAX_KERNEXEC
20634+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20635+#else
20636+ .quad 0x0 /* unused */
20637+#endif
20638+
20639+ .quad 0,0 /* TSS */
20640+ .quad 0,0 /* LDT */
20641+ .quad 0,0,0 /* three TLS descriptors */
20642+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20643+ /* asm/segment.h:GDT_ENTRIES must match this */
20644+
20645+ /* zero the remaining page */
20646+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20647+ .endr
20648+
20649 .align 16
20650 .globl early_gdt_descr
20651 early_gdt_descr:
20652 .word GDT_ENTRIES*8-1
20653 early_gdt_descr_base:
20654- .quad INIT_PER_CPU_VAR(gdt_page)
20655+ .quad cpu_gdt_table
20656
20657 ENTRY(phys_base)
20658 /* This must match the first entry in level2_kernel_pgt */
20659 .quad 0x0000000000000000
20660
20661 #include "../../x86/xen/xen-head.S"
20662-
20663- .section .bss, "aw", @nobits
20664+
20665+ .section .rodata,"a",@progbits
20666 .align L1_CACHE_BYTES
20667 ENTRY(idt_table)
20668- .skip IDT_ENTRIES * 16
20669+ .fill 512,8,0
20670
20671 .align L1_CACHE_BYTES
20672 ENTRY(nmi_idt_table)
20673- .skip IDT_ENTRIES * 16
20674+ .fill 512,8,0
20675
20676 __PAGE_ALIGNED_BSS
20677 .align PAGE_SIZE
20678diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20679index 9c3bd4a..e1d9b35 100644
20680--- a/arch/x86/kernel/i386_ksyms_32.c
20681+++ b/arch/x86/kernel/i386_ksyms_32.c
20682@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20683 EXPORT_SYMBOL(cmpxchg8b_emu);
20684 #endif
20685
20686+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20687+
20688 /* Networking helper routines. */
20689 EXPORT_SYMBOL(csum_partial_copy_generic);
20690+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20691+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20692
20693 EXPORT_SYMBOL(__get_user_1);
20694 EXPORT_SYMBOL(__get_user_2);
20695@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20696
20697 EXPORT_SYMBOL(csum_partial);
20698 EXPORT_SYMBOL(empty_zero_page);
20699+
20700+#ifdef CONFIG_PAX_KERNEXEC
20701+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20702+#endif
20703diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20704index 245a71d..89d9ce4 100644
20705--- a/arch/x86/kernel/i387.c
20706+++ b/arch/x86/kernel/i387.c
20707@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20708 static inline bool interrupted_user_mode(void)
20709 {
20710 struct pt_regs *regs = get_irq_regs();
20711- return regs && user_mode_vm(regs);
20712+ return regs && user_mode(regs);
20713 }
20714
20715 /*
20716diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20717index 9a5c460..b332a4b 100644
20718--- a/arch/x86/kernel/i8259.c
20719+++ b/arch/x86/kernel/i8259.c
20720@@ -209,7 +209,7 @@ spurious_8259A_irq:
20721 "spurious 8259A interrupt: IRQ%d.\n", irq);
20722 spurious_irq_mask |= irqmask;
20723 }
20724- atomic_inc(&irq_err_count);
20725+ atomic_inc_unchecked(&irq_err_count);
20726 /*
20727 * Theoretically we do not have to handle this IRQ,
20728 * but in Linux this does not cause problems and is
20729@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20730 /* (slave's support for AEOI in flat mode is to be investigated) */
20731 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20732
20733+ pax_open_kernel();
20734 if (auto_eoi)
20735 /*
20736 * In AEOI mode we just have to mask the interrupt
20737 * when acking.
20738 */
20739- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20740+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20741 else
20742- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20743+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20744+ pax_close_kernel();
20745
20746 udelay(100); /* wait for 8259A to initialize */
20747
20748diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20749index a979b5b..1d6db75 100644
20750--- a/arch/x86/kernel/io_delay.c
20751+++ b/arch/x86/kernel/io_delay.c
20752@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20753 * Quirk table for systems that misbehave (lock up, etc.) if port
20754 * 0x80 is used:
20755 */
20756-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20757+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20758 {
20759 .callback = dmi_io_delay_0xed_port,
20760 .ident = "Compaq Presario V6000",
20761diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20762index 8c96897..be66bfa 100644
20763--- a/arch/x86/kernel/ioport.c
20764+++ b/arch/x86/kernel/ioport.c
20765@@ -6,6 +6,7 @@
20766 #include <linux/sched.h>
20767 #include <linux/kernel.h>
20768 #include <linux/capability.h>
20769+#include <linux/security.h>
20770 #include <linux/errno.h>
20771 #include <linux/types.h>
20772 #include <linux/ioport.h>
20773@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20774
20775 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20776 return -EINVAL;
20777+#ifdef CONFIG_GRKERNSEC_IO
20778+ if (turn_on && grsec_disable_privio) {
20779+ gr_handle_ioperm();
20780+ return -EPERM;
20781+ }
20782+#endif
20783 if (turn_on && !capable(CAP_SYS_RAWIO))
20784 return -EPERM;
20785
20786@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20787 * because the ->io_bitmap_max value must match the bitmap
20788 * contents:
20789 */
20790- tss = &per_cpu(init_tss, get_cpu());
20791+ tss = init_tss + get_cpu();
20792
20793 if (turn_on)
20794 bitmap_clear(t->io_bitmap_ptr, from, num);
20795@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20796 return -EINVAL;
20797 /* Trying to gain more privileges? */
20798 if (level > old) {
20799+#ifdef CONFIG_GRKERNSEC_IO
20800+ if (grsec_disable_privio) {
20801+ gr_handle_iopl();
20802+ return -EPERM;
20803+ }
20804+#endif
20805 if (!capable(CAP_SYS_RAWIO))
20806 return -EPERM;
20807 }
20808diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20809index e4595f1..ee3bfb8 100644
20810--- a/arch/x86/kernel/irq.c
20811+++ b/arch/x86/kernel/irq.c
20812@@ -18,7 +18,7 @@
20813 #include <asm/mce.h>
20814 #include <asm/hw_irq.h>
20815
20816-atomic_t irq_err_count;
20817+atomic_unchecked_t irq_err_count;
20818
20819 /* Function pointer for generic interrupt vector handling */
20820 void (*x86_platform_ipi_callback)(void) = NULL;
20821@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20822 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20823 seq_printf(p, " Machine check polls\n");
20824 #endif
20825- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20826+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20827 #if defined(CONFIG_X86_IO_APIC)
20828- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20829+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20830 #endif
20831 return 0;
20832 }
20833@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20834
20835 u64 arch_irq_stat(void)
20836 {
20837- u64 sum = atomic_read(&irq_err_count);
20838+ u64 sum = atomic_read_unchecked(&irq_err_count);
20839
20840 #ifdef CONFIG_X86_IO_APIC
20841- sum += atomic_read(&irq_mis_count);
20842+ sum += atomic_read_unchecked(&irq_mis_count);
20843 #endif
20844 return sum;
20845 }
20846diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20847index 344faf8..355f60d 100644
20848--- a/arch/x86/kernel/irq_32.c
20849+++ b/arch/x86/kernel/irq_32.c
20850@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20851 __asm__ __volatile__("andl %%esp,%0" :
20852 "=r" (sp) : "0" (THREAD_SIZE - 1));
20853
20854- return sp < (sizeof(struct thread_info) + STACK_WARN);
20855+ return sp < STACK_WARN;
20856 }
20857
20858 static void print_stack_overflow(void)
20859@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20860 * per-CPU IRQ handling contexts (thread information and stack)
20861 */
20862 union irq_ctx {
20863- struct thread_info tinfo;
20864- u32 stack[THREAD_SIZE/sizeof(u32)];
20865+ unsigned long previous_esp;
20866+ u32 stack[THREAD_SIZE/sizeof(u32)];
20867 } __attribute__((aligned(THREAD_SIZE)));
20868
20869 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20870@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20871 static inline int
20872 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20873 {
20874- union irq_ctx *curctx, *irqctx;
20875+ union irq_ctx *irqctx;
20876 u32 *isp, arg1, arg2;
20877
20878- curctx = (union irq_ctx *) current_thread_info();
20879 irqctx = __this_cpu_read(hardirq_ctx);
20880
20881 /*
20882@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20883 * handler) we can't do that and just have to keep using the
20884 * current stack (which is the irq stack already after all)
20885 */
20886- if (unlikely(curctx == irqctx))
20887+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20888 return 0;
20889
20890 /* build the stack frame on the IRQ stack */
20891- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20892- irqctx->tinfo.task = curctx->tinfo.task;
20893- irqctx->tinfo.previous_esp = current_stack_pointer;
20894+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20895+ irqctx->previous_esp = current_stack_pointer;
20896
20897- /* Copy the preempt_count so that the [soft]irq checks work. */
20898- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20899+#ifdef CONFIG_PAX_MEMORY_UDEREF
20900+ __set_fs(MAKE_MM_SEG(0));
20901+#endif
20902
20903 if (unlikely(overflow))
20904 call_on_stack(print_stack_overflow, isp);
20905@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20906 : "0" (irq), "1" (desc), "2" (isp),
20907 "D" (desc->handle_irq)
20908 : "memory", "cc", "ecx");
20909+
20910+#ifdef CONFIG_PAX_MEMORY_UDEREF
20911+ __set_fs(current_thread_info()->addr_limit);
20912+#endif
20913+
20914 return 1;
20915 }
20916
20917@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20918 */
20919 void __cpuinit irq_ctx_init(int cpu)
20920 {
20921- union irq_ctx *irqctx;
20922-
20923 if (per_cpu(hardirq_ctx, cpu))
20924 return;
20925
20926- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20927- THREADINFO_GFP,
20928- THREAD_SIZE_ORDER));
20929- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20930- irqctx->tinfo.cpu = cpu;
20931- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20932- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20933-
20934- per_cpu(hardirq_ctx, cpu) = irqctx;
20935-
20936- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20937- THREADINFO_GFP,
20938- THREAD_SIZE_ORDER));
20939- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20940- irqctx->tinfo.cpu = cpu;
20941- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20942-
20943- per_cpu(softirq_ctx, cpu) = irqctx;
20944+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20945+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20946+
20947+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20948+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20949
20950 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20951 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20952@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20953 asmlinkage void do_softirq(void)
20954 {
20955 unsigned long flags;
20956- struct thread_info *curctx;
20957 union irq_ctx *irqctx;
20958 u32 *isp;
20959
20960@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20961 local_irq_save(flags);
20962
20963 if (local_softirq_pending()) {
20964- curctx = current_thread_info();
20965 irqctx = __this_cpu_read(softirq_ctx);
20966- irqctx->tinfo.task = curctx->task;
20967- irqctx->tinfo.previous_esp = current_stack_pointer;
20968+ irqctx->previous_esp = current_stack_pointer;
20969
20970 /* build the stack frame on the softirq stack */
20971- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20972+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20973+
20974+#ifdef CONFIG_PAX_MEMORY_UDEREF
20975+ __set_fs(MAKE_MM_SEG(0));
20976+#endif
20977
20978 call_on_stack(__do_softirq, isp);
20979+
20980+#ifdef CONFIG_PAX_MEMORY_UDEREF
20981+ __set_fs(current_thread_info()->addr_limit);
20982+#endif
20983+
20984 /*
20985 * Shouldn't happen, we returned above if in_interrupt():
20986 */
20987@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20988 if (unlikely(!desc))
20989 return false;
20990
20991- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20992+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20993 if (unlikely(overflow))
20994 print_stack_overflow();
20995 desc->handle_irq(irq, desc);
20996diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20997index d04d3ec..ea4b374 100644
20998--- a/arch/x86/kernel/irq_64.c
20999+++ b/arch/x86/kernel/irq_64.c
21000@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21001 u64 estack_top, estack_bottom;
21002 u64 curbase = (u64)task_stack_page(current);
21003
21004- if (user_mode_vm(regs))
21005+ if (user_mode(regs))
21006 return;
21007
21008 if (regs->sp >= curbase + sizeof(struct thread_info) +
21009diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21010index dc1404b..bbc43e7 100644
21011--- a/arch/x86/kernel/kdebugfs.c
21012+++ b/arch/x86/kernel/kdebugfs.c
21013@@ -27,7 +27,7 @@ struct setup_data_node {
21014 u32 len;
21015 };
21016
21017-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21018+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21019 size_t count, loff_t *ppos)
21020 {
21021 struct setup_data_node *node = file->private_data;
21022diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21023index 836f832..a8bda67 100644
21024--- a/arch/x86/kernel/kgdb.c
21025+++ b/arch/x86/kernel/kgdb.c
21026@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21027 #ifdef CONFIG_X86_32
21028 switch (regno) {
21029 case GDB_SS:
21030- if (!user_mode_vm(regs))
21031+ if (!user_mode(regs))
21032 *(unsigned long *)mem = __KERNEL_DS;
21033 break;
21034 case GDB_SP:
21035- if (!user_mode_vm(regs))
21036+ if (!user_mode(regs))
21037 *(unsigned long *)mem = kernel_stack_pointer(regs);
21038 break;
21039 case GDB_GS:
21040@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21041 bp->attr.bp_addr = breakinfo[breakno].addr;
21042 bp->attr.bp_len = breakinfo[breakno].len;
21043 bp->attr.bp_type = breakinfo[breakno].type;
21044- info->address = breakinfo[breakno].addr;
21045+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21046+ info->address = ktla_ktva(breakinfo[breakno].addr);
21047+ else
21048+ info->address = breakinfo[breakno].addr;
21049 info->len = breakinfo[breakno].len;
21050 info->type = breakinfo[breakno].type;
21051 val = arch_install_hw_breakpoint(bp);
21052@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21053 case 'k':
21054 /* clear the trace bit */
21055 linux_regs->flags &= ~X86_EFLAGS_TF;
21056- atomic_set(&kgdb_cpu_doing_single_step, -1);
21057+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21058
21059 /* set the trace bit if we're stepping */
21060 if (remcomInBuffer[0] == 's') {
21061 linux_regs->flags |= X86_EFLAGS_TF;
21062- atomic_set(&kgdb_cpu_doing_single_step,
21063+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21064 raw_smp_processor_id());
21065 }
21066
21067@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21068
21069 switch (cmd) {
21070 case DIE_DEBUG:
21071- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21072+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21073 if (user_mode(regs))
21074 return single_step_cont(regs, args);
21075 break;
21076@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21077 #endif /* CONFIG_DEBUG_RODATA */
21078
21079 bpt->type = BP_BREAKPOINT;
21080- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21081+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21082 BREAK_INSTR_SIZE);
21083 if (err)
21084 return err;
21085- err = probe_kernel_write((char *)bpt->bpt_addr,
21086+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21087 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21088 #ifdef CONFIG_DEBUG_RODATA
21089 if (!err)
21090@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21091 return -EBUSY;
21092 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21093 BREAK_INSTR_SIZE);
21094- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21095+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21096 if (err)
21097 return err;
21098 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21099@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21100 if (mutex_is_locked(&text_mutex))
21101 goto knl_write;
21102 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21103- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21104+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21105 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21106 goto knl_write;
21107 return err;
21108 knl_write:
21109 #endif /* CONFIG_DEBUG_RODATA */
21110- return probe_kernel_write((char *)bpt->bpt_addr,
21111+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21112 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21113 }
21114
21115diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
21116index c5e410e..ed5a7f0 100644
21117--- a/arch/x86/kernel/kprobes-opt.c
21118+++ b/arch/x86/kernel/kprobes-opt.c
21119@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21120 * Verify if the address gap is in 2GB range, because this uses
21121 * a relative jump.
21122 */
21123- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21124+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21125 if (abs(rel) > 0x7fffffff)
21126 return -ERANGE;
21127
21128@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21129 op->optinsn.size = ret;
21130
21131 /* Copy arch-dep-instance from template */
21132- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21133+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21134
21135 /* Set probe information */
21136 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21137
21138 /* Set probe function call */
21139- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21140+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21141
21142 /* Set returning jmp instruction at the tail of out-of-line buffer */
21143- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21144+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21145 (u8 *)op->kp.addr + op->optinsn.size);
21146
21147 flush_icache_range((unsigned long) buf,
21148@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21149 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21150
21151 /* Backup instructions which will be replaced by jump address */
21152- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21153+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21154 RELATIVE_ADDR_SIZE);
21155
21156 insn_buf[0] = RELATIVEJUMP_OPCODE;
21157@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21158 /* This kprobe is really able to run optimized path. */
21159 op = container_of(p, struct optimized_kprobe, kp);
21160 /* Detour through copied instructions */
21161- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21162+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21163 if (!reenter)
21164 reset_current_kprobe();
21165 preempt_enable_no_resched();
21166diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
21167index 57916c0..9e0b9d0 100644
21168--- a/arch/x86/kernel/kprobes.c
21169+++ b/arch/x86/kernel/kprobes.c
21170@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21171 s32 raddr;
21172 } __attribute__((packed)) *insn;
21173
21174- insn = (struct __arch_relative_insn *)from;
21175+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21176+
21177+ pax_open_kernel();
21178 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21179 insn->op = op;
21180+ pax_close_kernel();
21181 }
21182
21183 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21184@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21185 kprobe_opcode_t opcode;
21186 kprobe_opcode_t *orig_opcodes = opcodes;
21187
21188- if (search_exception_tables((unsigned long)opcodes))
21189+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21190 return 0; /* Page fault may occur on this address. */
21191
21192 retry:
21193@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21194 * for the first byte, we can recover the original instruction
21195 * from it and kp->opcode.
21196 */
21197- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21198+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21199 buf[0] = kp->opcode;
21200- return (unsigned long)buf;
21201+ return ktva_ktla((unsigned long)buf);
21202 }
21203
21204 /*
21205@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21206 /* Another subsystem puts a breakpoint, failed to recover */
21207 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21208 return 0;
21209+ pax_open_kernel();
21210 memcpy(dest, insn.kaddr, insn.length);
21211+ pax_close_kernel();
21212
21213 #ifdef CONFIG_X86_64
21214 if (insn_rip_relative(&insn)) {
21215@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21216 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21217 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21218 disp = (u8 *) dest + insn_offset_displacement(&insn);
21219+ pax_open_kernel();
21220 *(s32 *) disp = (s32) newdisp;
21221+ pax_close_kernel();
21222 }
21223 #endif
21224 return insn.length;
21225@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21226 * nor set current_kprobe, because it doesn't use single
21227 * stepping.
21228 */
21229- regs->ip = (unsigned long)p->ainsn.insn;
21230+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21231 preempt_enable_no_resched();
21232 return;
21233 }
21234@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21235 regs->flags &= ~X86_EFLAGS_IF;
21236 /* single step inline if the instruction is an int3 */
21237 if (p->opcode == BREAKPOINT_INSTRUCTION)
21238- regs->ip = (unsigned long)p->addr;
21239+ regs->ip = ktla_ktva((unsigned long)p->addr);
21240 else
21241- regs->ip = (unsigned long)p->ainsn.insn;
21242+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21243 }
21244
21245 /*
21246@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21247 setup_singlestep(p, regs, kcb, 0);
21248 return 1;
21249 }
21250- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21251+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21252 /*
21253 * The breakpoint instruction was removed right
21254 * after we hit it. Another cpu has removed
21255@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21256 " movq %rax, 152(%rsp)\n"
21257 RESTORE_REGS_STRING
21258 " popfq\n"
21259+#ifdef KERNEXEC_PLUGIN
21260+ " btsq $63,(%rsp)\n"
21261+#endif
21262 #else
21263 " pushf\n"
21264 SAVE_REGS_STRING
21265@@ -788,7 +798,7 @@ static void __kprobes
21266 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21267 {
21268 unsigned long *tos = stack_addr(regs);
21269- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21270+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21271 unsigned long orig_ip = (unsigned long)p->addr;
21272 kprobe_opcode_t *insn = p->ainsn.insn;
21273
21274@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21275 struct die_args *args = data;
21276 int ret = NOTIFY_DONE;
21277
21278- if (args->regs && user_mode_vm(args->regs))
21279+ if (args->regs && user_mode(args->regs))
21280 return ret;
21281
21282 switch (val) {
21283diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21284index 9c2bd8b..bb1131c 100644
21285--- a/arch/x86/kernel/kvm.c
21286+++ b/arch/x86/kernel/kvm.c
21287@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21288 return NOTIFY_OK;
21289 }
21290
21291-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21292+static struct notifier_block kvm_cpu_notifier = {
21293 .notifier_call = kvm_cpu_notify,
21294 };
21295 #endif
21296diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21297index ebc9873..1b9724b 100644
21298--- a/arch/x86/kernel/ldt.c
21299+++ b/arch/x86/kernel/ldt.c
21300@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21301 if (reload) {
21302 #ifdef CONFIG_SMP
21303 preempt_disable();
21304- load_LDT(pc);
21305+ load_LDT_nolock(pc);
21306 if (!cpumask_equal(mm_cpumask(current->mm),
21307 cpumask_of(smp_processor_id())))
21308 smp_call_function(flush_ldt, current->mm, 1);
21309 preempt_enable();
21310 #else
21311- load_LDT(pc);
21312+ load_LDT_nolock(pc);
21313 #endif
21314 }
21315 if (oldsize) {
21316@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21317 return err;
21318
21319 for (i = 0; i < old->size; i++)
21320- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21321+ write_ldt_entry(new->ldt, i, old->ldt + i);
21322 return 0;
21323 }
21324
21325@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21326 retval = copy_ldt(&mm->context, &old_mm->context);
21327 mutex_unlock(&old_mm->context.lock);
21328 }
21329+
21330+ if (tsk == current) {
21331+ mm->context.vdso = 0;
21332+
21333+#ifdef CONFIG_X86_32
21334+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21335+ mm->context.user_cs_base = 0UL;
21336+ mm->context.user_cs_limit = ~0UL;
21337+
21338+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21339+ cpus_clear(mm->context.cpu_user_cs_mask);
21340+#endif
21341+
21342+#endif
21343+#endif
21344+
21345+ }
21346+
21347 return retval;
21348 }
21349
21350@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21351 }
21352 }
21353
21354+#ifdef CONFIG_PAX_SEGMEXEC
21355+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21356+ error = -EINVAL;
21357+ goto out_unlock;
21358+ }
21359+#endif
21360+
21361 fill_ldt(&ldt, &ldt_info);
21362 if (oldmode)
21363 ldt.avl = 0;
21364diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21365index 5b19e4d..6476a76 100644
21366--- a/arch/x86/kernel/machine_kexec_32.c
21367+++ b/arch/x86/kernel/machine_kexec_32.c
21368@@ -26,7 +26,7 @@
21369 #include <asm/cacheflush.h>
21370 #include <asm/debugreg.h>
21371
21372-static void set_idt(void *newidt, __u16 limit)
21373+static void set_idt(struct desc_struct *newidt, __u16 limit)
21374 {
21375 struct desc_ptr curidt;
21376
21377@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21378 }
21379
21380
21381-static void set_gdt(void *newgdt, __u16 limit)
21382+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21383 {
21384 struct desc_ptr curgdt;
21385
21386@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21387 }
21388
21389 control_page = page_address(image->control_code_page);
21390- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21391+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21392
21393 relocate_kernel_ptr = control_page;
21394 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21395diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21396index 3a04b22..1d2eb09 100644
21397--- a/arch/x86/kernel/microcode_core.c
21398+++ b/arch/x86/kernel/microcode_core.c
21399@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21400 return NOTIFY_OK;
21401 }
21402
21403-static struct notifier_block __refdata mc_cpu_notifier = {
21404+static struct notifier_block mc_cpu_notifier = {
21405 .notifier_call = mc_cpu_callback,
21406 };
21407
21408diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21409index 3544aed..01ddc1c 100644
21410--- a/arch/x86/kernel/microcode_intel.c
21411+++ b/arch/x86/kernel/microcode_intel.c
21412@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21413
21414 static int get_ucode_user(void *to, const void *from, size_t n)
21415 {
21416- return copy_from_user(to, from, n);
21417+ return copy_from_user(to, (const void __force_user *)from, n);
21418 }
21419
21420 static enum ucode_state
21421 request_microcode_user(int cpu, const void __user *buf, size_t size)
21422 {
21423- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21424+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21425 }
21426
21427 static void microcode_fini_cpu(int cpu)
21428diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21429index 216a4d7..228255a 100644
21430--- a/arch/x86/kernel/module.c
21431+++ b/arch/x86/kernel/module.c
21432@@ -43,15 +43,60 @@ do { \
21433 } while (0)
21434 #endif
21435
21436-void *module_alloc(unsigned long size)
21437+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21438 {
21439- if (PAGE_ALIGN(size) > MODULES_LEN)
21440+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21441 return NULL;
21442 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21443- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21444+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21445 -1, __builtin_return_address(0));
21446 }
21447
21448+void *module_alloc(unsigned long size)
21449+{
21450+
21451+#ifdef CONFIG_PAX_KERNEXEC
21452+ return __module_alloc(size, PAGE_KERNEL);
21453+#else
21454+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21455+#endif
21456+
21457+}
21458+
21459+#ifdef CONFIG_PAX_KERNEXEC
21460+#ifdef CONFIG_X86_32
21461+void *module_alloc_exec(unsigned long size)
21462+{
21463+ struct vm_struct *area;
21464+
21465+ if (size == 0)
21466+ return NULL;
21467+
21468+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21469+ return area ? area->addr : NULL;
21470+}
21471+EXPORT_SYMBOL(module_alloc_exec);
21472+
21473+void module_free_exec(struct module *mod, void *module_region)
21474+{
21475+ vunmap(module_region);
21476+}
21477+EXPORT_SYMBOL(module_free_exec);
21478+#else
21479+void module_free_exec(struct module *mod, void *module_region)
21480+{
21481+ module_free(mod, module_region);
21482+}
21483+EXPORT_SYMBOL(module_free_exec);
21484+
21485+void *module_alloc_exec(unsigned long size)
21486+{
21487+ return __module_alloc(size, PAGE_KERNEL_RX);
21488+}
21489+EXPORT_SYMBOL(module_alloc_exec);
21490+#endif
21491+#endif
21492+
21493 #ifdef CONFIG_X86_32
21494 int apply_relocate(Elf32_Shdr *sechdrs,
21495 const char *strtab,
21496@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21497 unsigned int i;
21498 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21499 Elf32_Sym *sym;
21500- uint32_t *location;
21501+ uint32_t *plocation, location;
21502
21503 DEBUGP("Applying relocate section %u to %u\n",
21504 relsec, sechdrs[relsec].sh_info);
21505 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21506 /* This is where to make the change */
21507- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21508- + rel[i].r_offset;
21509+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21510+ location = (uint32_t)plocation;
21511+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21512+ plocation = ktla_ktva((void *)plocation);
21513 /* This is the symbol it is referring to. Note that all
21514 undefined symbols have been resolved. */
21515 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21516@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21517 switch (ELF32_R_TYPE(rel[i].r_info)) {
21518 case R_386_32:
21519 /* We add the value into the location given */
21520- *location += sym->st_value;
21521+ pax_open_kernel();
21522+ *plocation += sym->st_value;
21523+ pax_close_kernel();
21524 break;
21525 case R_386_PC32:
21526 /* Add the value, subtract its position */
21527- *location += sym->st_value - (uint32_t)location;
21528+ pax_open_kernel();
21529+ *plocation += sym->st_value - location;
21530+ pax_close_kernel();
21531 break;
21532 default:
21533 pr_err("%s: Unknown relocation: %u\n",
21534@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21535 case R_X86_64_NONE:
21536 break;
21537 case R_X86_64_64:
21538+ pax_open_kernel();
21539 *(u64 *)loc = val;
21540+ pax_close_kernel();
21541 break;
21542 case R_X86_64_32:
21543+ pax_open_kernel();
21544 *(u32 *)loc = val;
21545+ pax_close_kernel();
21546 if (val != *(u32 *)loc)
21547 goto overflow;
21548 break;
21549 case R_X86_64_32S:
21550+ pax_open_kernel();
21551 *(s32 *)loc = val;
21552+ pax_close_kernel();
21553 if ((s64)val != *(s32 *)loc)
21554 goto overflow;
21555 break;
21556 case R_X86_64_PC32:
21557 val -= (u64)loc;
21558+ pax_open_kernel();
21559 *(u32 *)loc = val;
21560+ pax_close_kernel();
21561+
21562 #if 0
21563 if ((s64)val != *(s32 *)loc)
21564 goto overflow;
21565diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21566index 4929502..686c291 100644
21567--- a/arch/x86/kernel/msr.c
21568+++ b/arch/x86/kernel/msr.c
21569@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21570 return notifier_from_errno(err);
21571 }
21572
21573-static struct notifier_block __refdata msr_class_cpu_notifier = {
21574+static struct notifier_block msr_class_cpu_notifier = {
21575 .notifier_call = msr_class_cpu_callback,
21576 };
21577
21578diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21579index f84f5c5..f404e81 100644
21580--- a/arch/x86/kernel/nmi.c
21581+++ b/arch/x86/kernel/nmi.c
21582@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21583 return handled;
21584 }
21585
21586-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21587+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21588 {
21589 struct nmi_desc *desc = nmi_to_desc(type);
21590 unsigned long flags;
21591@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21592 * event confuses some handlers (kdump uses this flag)
21593 */
21594 if (action->flags & NMI_FLAG_FIRST)
21595- list_add_rcu(&action->list, &desc->head);
21596+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21597 else
21598- list_add_tail_rcu(&action->list, &desc->head);
21599+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21600
21601 spin_unlock_irqrestore(&desc->lock, flags);
21602 return 0;
21603@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21604 if (!strcmp(n->name, name)) {
21605 WARN(in_nmi(),
21606 "Trying to free NMI (%s) from NMI context!\n", n->name);
21607- list_del_rcu(&n->list);
21608+ pax_list_del_rcu((struct list_head *)&n->list);
21609 break;
21610 }
21611 }
21612@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21613 dotraplinkage notrace __kprobes void
21614 do_nmi(struct pt_regs *regs, long error_code)
21615 {
21616+
21617+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21618+ if (!user_mode(regs)) {
21619+ unsigned long cs = regs->cs & 0xFFFF;
21620+ unsigned long ip = ktva_ktla(regs->ip);
21621+
21622+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21623+ regs->ip = ip;
21624+ }
21625+#endif
21626+
21627 nmi_nesting_preprocess(regs);
21628
21629 nmi_enter();
21630diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21631index 6d9582e..f746287 100644
21632--- a/arch/x86/kernel/nmi_selftest.c
21633+++ b/arch/x86/kernel/nmi_selftest.c
21634@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21635 {
21636 /* trap all the unknown NMIs we may generate */
21637 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21638- __initdata);
21639+ __initconst);
21640 }
21641
21642 static void __init cleanup_nmi_testsuite(void)
21643@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21644 unsigned long timeout;
21645
21646 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21647- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21648+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21649 nmi_fail = FAILURE;
21650 return;
21651 }
21652diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21653index 676b8c7..870ba04 100644
21654--- a/arch/x86/kernel/paravirt-spinlocks.c
21655+++ b/arch/x86/kernel/paravirt-spinlocks.c
21656@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21657 arch_spin_lock(lock);
21658 }
21659
21660-struct pv_lock_ops pv_lock_ops = {
21661+struct pv_lock_ops pv_lock_ops __read_only = {
21662 #ifdef CONFIG_SMP
21663 .spin_is_locked = __ticket_spin_is_locked,
21664 .spin_is_contended = __ticket_spin_is_contended,
21665diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21666index 17fff18..5cfa0f4 100644
21667--- a/arch/x86/kernel/paravirt.c
21668+++ b/arch/x86/kernel/paravirt.c
21669@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21670 {
21671 return x;
21672 }
21673+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21674+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21675+#endif
21676
21677 void __init default_banner(void)
21678 {
21679@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21680 if (opfunc == NULL)
21681 /* If there's no function, patch it with a ud2a (BUG) */
21682 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21683- else if (opfunc == _paravirt_nop)
21684+ else if (opfunc == (void *)_paravirt_nop)
21685 /* If the operation is a nop, then nop the callsite */
21686 ret = paravirt_patch_nop();
21687
21688 /* identity functions just return their single argument */
21689- else if (opfunc == _paravirt_ident_32)
21690+ else if (opfunc == (void *)_paravirt_ident_32)
21691 ret = paravirt_patch_ident_32(insnbuf, len);
21692- else if (opfunc == _paravirt_ident_64)
21693+ else if (opfunc == (void *)_paravirt_ident_64)
21694 ret = paravirt_patch_ident_64(insnbuf, len);
21695+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21696+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21697+ ret = paravirt_patch_ident_64(insnbuf, len);
21698+#endif
21699
21700 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21701 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21702@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21703 if (insn_len > len || start == NULL)
21704 insn_len = len;
21705 else
21706- memcpy(insnbuf, start, insn_len);
21707+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21708
21709 return insn_len;
21710 }
21711@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21712 preempt_enable();
21713 }
21714
21715-struct pv_info pv_info = {
21716+struct pv_info pv_info __read_only = {
21717 .name = "bare hardware",
21718 .paravirt_enabled = 0,
21719 .kernel_rpl = 0,
21720@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21721 #endif
21722 };
21723
21724-struct pv_init_ops pv_init_ops = {
21725+struct pv_init_ops pv_init_ops __read_only = {
21726 .patch = native_patch,
21727 };
21728
21729-struct pv_time_ops pv_time_ops = {
21730+struct pv_time_ops pv_time_ops __read_only = {
21731 .sched_clock = native_sched_clock,
21732 .steal_clock = native_steal_clock,
21733 };
21734
21735-struct pv_irq_ops pv_irq_ops = {
21736+struct pv_irq_ops pv_irq_ops __read_only = {
21737 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21738 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21739 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21740@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21741 #endif
21742 };
21743
21744-struct pv_cpu_ops pv_cpu_ops = {
21745+struct pv_cpu_ops pv_cpu_ops __read_only = {
21746 .cpuid = native_cpuid,
21747 .get_debugreg = native_get_debugreg,
21748 .set_debugreg = native_set_debugreg,
21749@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21750 .end_context_switch = paravirt_nop,
21751 };
21752
21753-struct pv_apic_ops pv_apic_ops = {
21754+struct pv_apic_ops pv_apic_ops __read_only= {
21755 #ifdef CONFIG_X86_LOCAL_APIC
21756 .startup_ipi_hook = paravirt_nop,
21757 #endif
21758 };
21759
21760-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21761+#ifdef CONFIG_X86_32
21762+#ifdef CONFIG_X86_PAE
21763+/* 64-bit pagetable entries */
21764+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21765+#else
21766 /* 32-bit pagetable entries */
21767 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21768+#endif
21769 #else
21770 /* 64-bit pagetable entries */
21771 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21772 #endif
21773
21774-struct pv_mmu_ops pv_mmu_ops = {
21775+struct pv_mmu_ops pv_mmu_ops __read_only = {
21776
21777 .read_cr2 = native_read_cr2,
21778 .write_cr2 = native_write_cr2,
21779@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21780 .make_pud = PTE_IDENT,
21781
21782 .set_pgd = native_set_pgd,
21783+ .set_pgd_batched = native_set_pgd_batched,
21784 #endif
21785 #endif /* PAGETABLE_LEVELS >= 3 */
21786
21787@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21788 },
21789
21790 .set_fixmap = native_set_fixmap,
21791+
21792+#ifdef CONFIG_PAX_KERNEXEC
21793+ .pax_open_kernel = native_pax_open_kernel,
21794+ .pax_close_kernel = native_pax_close_kernel,
21795+#endif
21796+
21797 };
21798
21799 EXPORT_SYMBOL_GPL(pv_time_ops);
21800diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21801index 35ccf75..7a15747 100644
21802--- a/arch/x86/kernel/pci-iommu_table.c
21803+++ b/arch/x86/kernel/pci-iommu_table.c
21804@@ -2,7 +2,7 @@
21805 #include <asm/iommu_table.h>
21806 #include <linux/string.h>
21807 #include <linux/kallsyms.h>
21808-
21809+#include <linux/sched.h>
21810
21811 #define DEBUG 1
21812
21813diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
21814index 6c483ba..d10ce2f 100644
21815--- a/arch/x86/kernel/pci-swiotlb.c
21816+++ b/arch/x86/kernel/pci-swiotlb.c
21817@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
21818 void *vaddr, dma_addr_t dma_addr,
21819 struct dma_attrs *attrs)
21820 {
21821- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
21822+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
21823 }
21824
21825 static struct dma_map_ops swiotlb_dma_ops = {
21826diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21827index 2ed787f..f70c9f6 100644
21828--- a/arch/x86/kernel/process.c
21829+++ b/arch/x86/kernel/process.c
21830@@ -36,7 +36,8 @@
21831 * section. Since TSS's are completely CPU-local, we want them
21832 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21833 */
21834-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21835+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21836+EXPORT_SYMBOL(init_tss);
21837
21838 #ifdef CONFIG_X86_64
21839 static DEFINE_PER_CPU(unsigned char, is_idle);
21840@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21841 task_xstate_cachep =
21842 kmem_cache_create("task_xstate", xstate_size,
21843 __alignof__(union thread_xstate),
21844- SLAB_PANIC | SLAB_NOTRACK, NULL);
21845+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21846 }
21847
21848 /*
21849@@ -105,7 +106,7 @@ void exit_thread(void)
21850 unsigned long *bp = t->io_bitmap_ptr;
21851
21852 if (bp) {
21853- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21854+ struct tss_struct *tss = init_tss + get_cpu();
21855
21856 t->io_bitmap_ptr = NULL;
21857 clear_thread_flag(TIF_IO_BITMAP);
21858@@ -136,7 +137,7 @@ void show_regs_common(void)
21859 board = dmi_get_system_info(DMI_BOARD_NAME);
21860
21861 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21862- current->pid, current->comm, print_tainted(),
21863+ task_pid_nr(current), current->comm, print_tainted(),
21864 init_utsname()->release,
21865 (int)strcspn(init_utsname()->version, " "),
21866 init_utsname()->version,
21867@@ -149,6 +150,9 @@ void flush_thread(void)
21868 {
21869 struct task_struct *tsk = current;
21870
21871+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21872+ loadsegment(gs, 0);
21873+#endif
21874 flush_ptrace_hw_breakpoint(tsk);
21875 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21876 drop_init_fpu(tsk);
21877@@ -301,7 +305,7 @@ static void __exit_idle(void)
21878 void exit_idle(void)
21879 {
21880 /* idle loop has pid 0 */
21881- if (current->pid)
21882+ if (task_pid_nr(current))
21883 return;
21884 __exit_idle();
21885 }
21886@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21887
21888 return ret;
21889 }
21890-void stop_this_cpu(void *dummy)
21891+__noreturn void stop_this_cpu(void *dummy)
21892 {
21893 local_irq_disable();
21894 /*
21895@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21896 }
21897 early_param("idle", idle_setup);
21898
21899-unsigned long arch_align_stack(unsigned long sp)
21900+#ifdef CONFIG_PAX_RANDKSTACK
21901+void pax_randomize_kstack(struct pt_regs *regs)
21902 {
21903- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21904- sp -= get_random_int() % 8192;
21905- return sp & ~0xf;
21906-}
21907+ struct thread_struct *thread = &current->thread;
21908+ unsigned long time;
21909
21910-unsigned long arch_randomize_brk(struct mm_struct *mm)
21911-{
21912- unsigned long range_end = mm->brk + 0x02000000;
21913- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21914-}
21915+ if (!randomize_va_space)
21916+ return;
21917+
21918+ if (v8086_mode(regs))
21919+ return;
21920
21921+ rdtscl(time);
21922+
21923+ /* P4 seems to return a 0 LSB, ignore it */
21924+#ifdef CONFIG_MPENTIUM4
21925+ time &= 0x3EUL;
21926+ time <<= 2;
21927+#elif defined(CONFIG_X86_64)
21928+ time &= 0xFUL;
21929+ time <<= 4;
21930+#else
21931+ time &= 0x1FUL;
21932+ time <<= 3;
21933+#endif
21934+
21935+ thread->sp0 ^= time;
21936+ load_sp0(init_tss + smp_processor_id(), thread);
21937+
21938+#ifdef CONFIG_X86_64
21939+ this_cpu_write(kernel_stack, thread->sp0);
21940+#endif
21941+}
21942+#endif
21943diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21944index b5a8905..d9cacac 100644
21945--- a/arch/x86/kernel/process_32.c
21946+++ b/arch/x86/kernel/process_32.c
21947@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21948 unsigned long thread_saved_pc(struct task_struct *tsk)
21949 {
21950 return ((unsigned long *)tsk->thread.sp)[3];
21951+//XXX return tsk->thread.eip;
21952 }
21953
21954 void __show_regs(struct pt_regs *regs, int all)
21955@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21956 unsigned long sp;
21957 unsigned short ss, gs;
21958
21959- if (user_mode_vm(regs)) {
21960+ if (user_mode(regs)) {
21961 sp = regs->sp;
21962 ss = regs->ss & 0xffff;
21963- gs = get_user_gs(regs);
21964 } else {
21965 sp = kernel_stack_pointer(regs);
21966 savesegment(ss, ss);
21967- savesegment(gs, gs);
21968 }
21969+ gs = get_user_gs(regs);
21970
21971 show_regs_common();
21972
21973 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21974 (u16)regs->cs, regs->ip, regs->flags,
21975- smp_processor_id());
21976+ raw_smp_processor_id());
21977 print_symbol("EIP is at %s\n", regs->ip);
21978
21979 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21980@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21981 int copy_thread(unsigned long clone_flags, unsigned long sp,
21982 unsigned long arg, struct task_struct *p)
21983 {
21984- struct pt_regs *childregs = task_pt_regs(p);
21985+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21986 struct task_struct *tsk;
21987 int err;
21988
21989 p->thread.sp = (unsigned long) childregs;
21990 p->thread.sp0 = (unsigned long) (childregs+1);
21991+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21992
21993 if (unlikely(p->flags & PF_KTHREAD)) {
21994 /* kernel thread */
21995 memset(childregs, 0, sizeof(struct pt_regs));
21996 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21997- task_user_gs(p) = __KERNEL_STACK_CANARY;
21998- childregs->ds = __USER_DS;
21999- childregs->es = __USER_DS;
22000+ savesegment(gs, childregs->gs);
22001+ childregs->ds = __KERNEL_DS;
22002+ childregs->es = __KERNEL_DS;
22003 childregs->fs = __KERNEL_PERCPU;
22004 childregs->bx = sp; /* function */
22005 childregs->bp = arg;
22006@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22007 struct thread_struct *prev = &prev_p->thread,
22008 *next = &next_p->thread;
22009 int cpu = smp_processor_id();
22010- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22011+ struct tss_struct *tss = init_tss + cpu;
22012 fpu_switch_t fpu;
22013
22014 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22015@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22016 */
22017 lazy_save_gs(prev->gs);
22018
22019+#ifdef CONFIG_PAX_MEMORY_UDEREF
22020+ __set_fs(task_thread_info(next_p)->addr_limit);
22021+#endif
22022+
22023 /*
22024 * Load the per-thread Thread-Local Storage descriptor.
22025 */
22026@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22027 */
22028 arch_end_context_switch(next_p);
22029
22030+ this_cpu_write(current_task, next_p);
22031+ this_cpu_write(current_tinfo, &next_p->tinfo);
22032+
22033 /*
22034 * Restore %gs if needed (which is common)
22035 */
22036@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22037
22038 switch_fpu_finish(next_p, fpu);
22039
22040- this_cpu_write(current_task, next_p);
22041-
22042 return prev_p;
22043 }
22044
22045@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22046 } while (count++ < 16);
22047 return 0;
22048 }
22049-
22050diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22051index 6e68a61..955a9a5 100644
22052--- a/arch/x86/kernel/process_64.c
22053+++ b/arch/x86/kernel/process_64.c
22054@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22055 struct pt_regs *childregs;
22056 struct task_struct *me = current;
22057
22058- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22059+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22060 childregs = task_pt_regs(p);
22061 p->thread.sp = (unsigned long) childregs;
22062 p->thread.usersp = me->thread.usersp;
22063+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22064 set_tsk_thread_flag(p, TIF_FORK);
22065 p->fpu_counter = 0;
22066 p->thread.io_bitmap_ptr = NULL;
22067@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22068 struct thread_struct *prev = &prev_p->thread;
22069 struct thread_struct *next = &next_p->thread;
22070 int cpu = smp_processor_id();
22071- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22072+ struct tss_struct *tss = init_tss + cpu;
22073 unsigned fsindex, gsindex;
22074 fpu_switch_t fpu;
22075
22076@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22077 prev->usersp = this_cpu_read(old_rsp);
22078 this_cpu_write(old_rsp, next->usersp);
22079 this_cpu_write(current_task, next_p);
22080+ this_cpu_write(current_tinfo, &next_p->tinfo);
22081
22082- this_cpu_write(kernel_stack,
22083- (unsigned long)task_stack_page(next_p) +
22084- THREAD_SIZE - KERNEL_STACK_OFFSET);
22085+ this_cpu_write(kernel_stack, next->sp0);
22086
22087 /*
22088 * Now maybe reload the debug registers and handle I/O bitmaps
22089@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22090 if (!p || p == current || p->state == TASK_RUNNING)
22091 return 0;
22092 stack = (unsigned long)task_stack_page(p);
22093- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22094+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22095 return 0;
22096 fp = *(u64 *)(p->thread.sp);
22097 do {
22098- if (fp < (unsigned long)stack ||
22099- fp >= (unsigned long)stack+THREAD_SIZE)
22100+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22101 return 0;
22102 ip = *(u64 *)(fp+8);
22103 if (!in_sched_functions(ip))
22104diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22105index b629bbe..0fa615a 100644
22106--- a/arch/x86/kernel/ptrace.c
22107+++ b/arch/x86/kernel/ptrace.c
22108@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22109 {
22110 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22111 unsigned long sp = (unsigned long)&regs->sp;
22112- struct thread_info *tinfo;
22113
22114- if (context == (sp & ~(THREAD_SIZE - 1)))
22115+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22116 return sp;
22117
22118- tinfo = (struct thread_info *)context;
22119- if (tinfo->previous_esp)
22120- return tinfo->previous_esp;
22121+ sp = *(unsigned long *)context;
22122+ if (sp)
22123+ return sp;
22124
22125 return (unsigned long)regs;
22126 }
22127@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22128 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22129 {
22130 int i;
22131- int dr7 = 0;
22132+ unsigned long dr7 = 0;
22133 struct arch_hw_breakpoint *info;
22134
22135 for (i = 0; i < HBP_NUM; i++) {
22136@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22137 unsigned long addr, unsigned long data)
22138 {
22139 int ret;
22140- unsigned long __user *datap = (unsigned long __user *)data;
22141+ unsigned long __user *datap = (__force unsigned long __user *)data;
22142
22143 switch (request) {
22144 /* read the word at location addr in the USER area. */
22145@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22146 if ((int) addr < 0)
22147 return -EIO;
22148 ret = do_get_thread_area(child, addr,
22149- (struct user_desc __user *)data);
22150+ (__force struct user_desc __user *) data);
22151 break;
22152
22153 case PTRACE_SET_THREAD_AREA:
22154 if ((int) addr < 0)
22155 return -EIO;
22156 ret = do_set_thread_area(child, addr,
22157- (struct user_desc __user *)data, 0);
22158+ (__force struct user_desc __user *) data, 0);
22159 break;
22160 #endif
22161
22162@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22163
22164 #ifdef CONFIG_X86_64
22165
22166-static struct user_regset x86_64_regsets[] __read_mostly = {
22167+static user_regset_no_const x86_64_regsets[] __read_only = {
22168 [REGSET_GENERAL] = {
22169 .core_note_type = NT_PRSTATUS,
22170 .n = sizeof(struct user_regs_struct) / sizeof(long),
22171@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22172 #endif /* CONFIG_X86_64 */
22173
22174 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22175-static struct user_regset x86_32_regsets[] __read_mostly = {
22176+static user_regset_no_const x86_32_regsets[] __read_only = {
22177 [REGSET_GENERAL] = {
22178 .core_note_type = NT_PRSTATUS,
22179 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22180@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22181 */
22182 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22183
22184-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22185+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22186 {
22187 #ifdef CONFIG_X86_64
22188 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22189@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22190 memset(info, 0, sizeof(*info));
22191 info->si_signo = SIGTRAP;
22192 info->si_code = si_code;
22193- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22194+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22195 }
22196
22197 void user_single_step_siginfo(struct task_struct *tsk,
22198@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22199 # define IS_IA32 0
22200 #endif
22201
22202+#ifdef CONFIG_GRKERNSEC_SETXID
22203+extern void gr_delayed_cred_worker(void);
22204+#endif
22205+
22206 /*
22207 * We must return the syscall number to actually look up in the table.
22208 * This can be -1L to skip running any syscall at all.
22209@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22210
22211 user_exit();
22212
22213+#ifdef CONFIG_GRKERNSEC_SETXID
22214+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22215+ gr_delayed_cred_worker();
22216+#endif
22217+
22218 /*
22219 * If we stepped into a sysenter/syscall insn, it trapped in
22220 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22221@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22222 */
22223 user_exit();
22224
22225+#ifdef CONFIG_GRKERNSEC_SETXID
22226+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22227+ gr_delayed_cred_worker();
22228+#endif
22229+
22230 audit_syscall_exit(regs);
22231
22232 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22233diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22234index 2cb9470..ff1fd80 100644
22235--- a/arch/x86/kernel/pvclock.c
22236+++ b/arch/x86/kernel/pvclock.c
22237@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22238 return pv_tsc_khz;
22239 }
22240
22241-static atomic64_t last_value = ATOMIC64_INIT(0);
22242+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22243
22244 void pvclock_resume(void)
22245 {
22246- atomic64_set(&last_value, 0);
22247+ atomic64_set_unchecked(&last_value, 0);
22248 }
22249
22250 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22251@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22252 * updating at the same time, and one of them could be slightly behind,
22253 * making the assumption that last_value always go forward fail to hold.
22254 */
22255- last = atomic64_read(&last_value);
22256+ last = atomic64_read_unchecked(&last_value);
22257 do {
22258 if (ret < last)
22259 return last;
22260- last = atomic64_cmpxchg(&last_value, last, ret);
22261+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22262 } while (unlikely(last != ret));
22263
22264 return ret;
22265diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22266index 76fa1e9..abf09ea 100644
22267--- a/arch/x86/kernel/reboot.c
22268+++ b/arch/x86/kernel/reboot.c
22269@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22270 EXPORT_SYMBOL(pm_power_off);
22271
22272 static const struct desc_ptr no_idt = {};
22273-static int reboot_mode;
22274+static unsigned short reboot_mode;
22275 enum reboot_type reboot_type = BOOT_ACPI;
22276 int reboot_force;
22277
22278@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22279
22280 void __noreturn machine_real_restart(unsigned int type)
22281 {
22282+
22283+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22284+ struct desc_struct *gdt;
22285+#endif
22286+
22287 local_irq_disable();
22288
22289 /*
22290@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22291
22292 /* Jump to the identity-mapped low memory code */
22293 #ifdef CONFIG_X86_32
22294- asm volatile("jmpl *%0" : :
22295+
22296+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22297+ gdt = get_cpu_gdt_table(smp_processor_id());
22298+ pax_open_kernel();
22299+#ifdef CONFIG_PAX_MEMORY_UDEREF
22300+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22301+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22302+ loadsegment(ds, __KERNEL_DS);
22303+ loadsegment(es, __KERNEL_DS);
22304+ loadsegment(ss, __KERNEL_DS);
22305+#endif
22306+#ifdef CONFIG_PAX_KERNEXEC
22307+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22308+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22309+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22310+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22311+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22312+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22313+#endif
22314+ pax_close_kernel();
22315+#endif
22316+
22317+ asm volatile("ljmpl *%0" : :
22318 "rm" (real_mode_header->machine_real_restart_asm),
22319 "a" (type));
22320 #else
22321@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22322 * try to force a triple fault and then cycle between hitting the keyboard
22323 * controller and doing that
22324 */
22325-static void native_machine_emergency_restart(void)
22326+static void __noreturn native_machine_emergency_restart(void)
22327 {
22328 int i;
22329 int attempt = 0;
22330@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22331 #endif
22332 }
22333
22334-static void __machine_emergency_restart(int emergency)
22335+static void __noreturn __machine_emergency_restart(int emergency)
22336 {
22337 reboot_emergency = emergency;
22338 machine_ops.emergency_restart();
22339 }
22340
22341-static void native_machine_restart(char *__unused)
22342+static void __noreturn native_machine_restart(char *__unused)
22343 {
22344 pr_notice("machine restart\n");
22345
22346@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22347 __machine_emergency_restart(0);
22348 }
22349
22350-static void native_machine_halt(void)
22351+static void __noreturn native_machine_halt(void)
22352 {
22353 /* Stop other cpus and apics */
22354 machine_shutdown();
22355@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22356 stop_this_cpu(NULL);
22357 }
22358
22359-static void native_machine_power_off(void)
22360+static void __noreturn native_machine_power_off(void)
22361 {
22362 if (pm_power_off) {
22363 if (!reboot_force)
22364@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22365 }
22366 /* A fallback in case there is no PM info available */
22367 tboot_shutdown(TB_SHUTDOWN_HALT);
22368+ unreachable();
22369 }
22370
22371-struct machine_ops machine_ops = {
22372+struct machine_ops machine_ops __read_only = {
22373 .power_off = native_machine_power_off,
22374 .shutdown = native_machine_shutdown,
22375 .emergency_restart = native_machine_emergency_restart,
22376diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22377index 7a6f3b3..bed145d7 100644
22378--- a/arch/x86/kernel/relocate_kernel_64.S
22379+++ b/arch/x86/kernel/relocate_kernel_64.S
22380@@ -11,6 +11,7 @@
22381 #include <asm/kexec.h>
22382 #include <asm/processor-flags.h>
22383 #include <asm/pgtable_types.h>
22384+#include <asm/alternative-asm.h>
22385
22386 /*
22387 * Must be relocatable PIC code callable as a C function
22388@@ -160,13 +161,14 @@ identity_mapped:
22389 xorq %rbp, %rbp
22390 xorq %r8, %r8
22391 xorq %r9, %r9
22392- xorq %r10, %r9
22393+ xorq %r10, %r10
22394 xorq %r11, %r11
22395 xorq %r12, %r12
22396 xorq %r13, %r13
22397 xorq %r14, %r14
22398 xorq %r15, %r15
22399
22400+ pax_force_retaddr 0, 1
22401 ret
22402
22403 1:
22404diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22405index 8b24289..d37b58b 100644
22406--- a/arch/x86/kernel/setup.c
22407+++ b/arch/x86/kernel/setup.c
22408@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22409
22410 switch (data->type) {
22411 case SETUP_E820_EXT:
22412- parse_e820_ext(data);
22413+ parse_e820_ext((struct setup_data __force_kernel *)data);
22414 break;
22415 case SETUP_DTB:
22416 add_dtb(pa_data);
22417@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22418 * area (640->1Mb) as ram even though it is not.
22419 * take them out.
22420 */
22421- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22422+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22423
22424 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22425 }
22426@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22427
22428 if (!boot_params.hdr.root_flags)
22429 root_mountflags &= ~MS_RDONLY;
22430- init_mm.start_code = (unsigned long) _text;
22431- init_mm.end_code = (unsigned long) _etext;
22432+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22433+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22434 init_mm.end_data = (unsigned long) _edata;
22435 init_mm.brk = _brk_end;
22436
22437- code_resource.start = virt_to_phys(_text);
22438- code_resource.end = virt_to_phys(_etext)-1;
22439- data_resource.start = virt_to_phys(_etext);
22440+ code_resource.start = virt_to_phys(ktla_ktva(_text));
22441+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22442+ data_resource.start = virt_to_phys(_sdata);
22443 data_resource.end = virt_to_phys(_edata)-1;
22444 bss_resource.start = virt_to_phys(&__bss_start);
22445 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22446diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22447index 5cdff03..80fa283 100644
22448--- a/arch/x86/kernel/setup_percpu.c
22449+++ b/arch/x86/kernel/setup_percpu.c
22450@@ -21,19 +21,17 @@
22451 #include <asm/cpu.h>
22452 #include <asm/stackprotector.h>
22453
22454-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22455+#ifdef CONFIG_SMP
22456+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22457 EXPORT_PER_CPU_SYMBOL(cpu_number);
22458+#endif
22459
22460-#ifdef CONFIG_X86_64
22461 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22462-#else
22463-#define BOOT_PERCPU_OFFSET 0
22464-#endif
22465
22466 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22467 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22468
22469-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22470+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22471 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22472 };
22473 EXPORT_SYMBOL(__per_cpu_offset);
22474@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22475 {
22476 #ifdef CONFIG_NEED_MULTIPLE_NODES
22477 pg_data_t *last = NULL;
22478- unsigned int cpu;
22479+ int cpu;
22480
22481 for_each_possible_cpu(cpu) {
22482 int node = early_cpu_to_node(cpu);
22483@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22484 {
22485 #ifdef CONFIG_X86_32
22486 struct desc_struct gdt;
22487+ unsigned long base = per_cpu_offset(cpu);
22488
22489- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22490- 0x2 | DESCTYPE_S, 0x8);
22491- gdt.s = 1;
22492+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22493+ 0x83 | DESCTYPE_S, 0xC);
22494 write_gdt_entry(get_cpu_gdt_table(cpu),
22495 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22496 #endif
22497@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22498 /* alrighty, percpu areas up and running */
22499 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22500 for_each_possible_cpu(cpu) {
22501+#ifdef CONFIG_CC_STACKPROTECTOR
22502+#ifdef CONFIG_X86_32
22503+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22504+#endif
22505+#endif
22506 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22507 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22508 per_cpu(cpu_number, cpu) = cpu;
22509@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22510 */
22511 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22512 #endif
22513+#ifdef CONFIG_CC_STACKPROTECTOR
22514+#ifdef CONFIG_X86_32
22515+ if (!cpu)
22516+ per_cpu(stack_canary.canary, cpu) = canary;
22517+#endif
22518+#endif
22519 /*
22520 * Up to this point, the boot CPU has been using .init.data
22521 * area. Reload any changed state for the boot CPU.
22522diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22523index d6bf1f3..3ffce5a 100644
22524--- a/arch/x86/kernel/signal.c
22525+++ b/arch/x86/kernel/signal.c
22526@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22527 * Align the stack pointer according to the i386 ABI,
22528 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22529 */
22530- sp = ((sp + 4) & -16ul) - 4;
22531+ sp = ((sp - 12) & -16ul) - 4;
22532 #else /* !CONFIG_X86_32 */
22533 sp = round_down(sp, 16) - 8;
22534 #endif
22535@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22536 }
22537
22538 if (current->mm->context.vdso)
22539- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22540+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22541 else
22542- restorer = &frame->retcode;
22543+ restorer = (void __user *)&frame->retcode;
22544 if (ka->sa.sa_flags & SA_RESTORER)
22545 restorer = ka->sa.sa_restorer;
22546
22547@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22548 * reasons and because gdb uses it as a signature to notice
22549 * signal handler stack frames.
22550 */
22551- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22552+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22553
22554 if (err)
22555 return -EFAULT;
22556@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22557 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22558
22559 /* Set up to return from userspace. */
22560- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22561+ if (current->mm->context.vdso)
22562+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22563+ else
22564+ restorer = (void __user *)&frame->retcode;
22565 if (ka->sa.sa_flags & SA_RESTORER)
22566 restorer = ka->sa.sa_restorer;
22567 put_user_ex(restorer, &frame->pretcode);
22568@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22569 * reasons and because gdb uses it as a signature to notice
22570 * signal handler stack frames.
22571 */
22572- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22573+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22574 } put_user_catch(err);
22575
22576 err |= copy_siginfo_to_user(&frame->info, info);
22577diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22578index 48d2b7d..90d328a 100644
22579--- a/arch/x86/kernel/smp.c
22580+++ b/arch/x86/kernel/smp.c
22581@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22582
22583 __setup("nonmi_ipi", nonmi_ipi_setup);
22584
22585-struct smp_ops smp_ops = {
22586+struct smp_ops smp_ops __read_only = {
22587 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22588 .smp_prepare_cpus = native_smp_prepare_cpus,
22589 .smp_cpus_done = native_smp_cpus_done,
22590diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22591index ed0fe38..87fc692 100644
22592--- a/arch/x86/kernel/smpboot.c
22593+++ b/arch/x86/kernel/smpboot.c
22594@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22595 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22596 (THREAD_SIZE + task_stack_page(idle))) - 1);
22597 per_cpu(current_task, cpu) = idle;
22598+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22599
22600 #ifdef CONFIG_X86_32
22601 /* Stack for startup_32 can be just as for start_secondary onwards */
22602@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22603 #else
22604 clear_tsk_thread_flag(idle, TIF_FORK);
22605 initial_gs = per_cpu_offset(cpu);
22606- per_cpu(kernel_stack, cpu) =
22607- (unsigned long)task_stack_page(idle) -
22608- KERNEL_STACK_OFFSET + THREAD_SIZE;
22609+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22610 #endif
22611+
22612+ pax_open_kernel();
22613 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22614+ pax_close_kernel();
22615+
22616 initial_code = (unsigned long)start_secondary;
22617 stack_start = idle->thread.sp;
22618
22619@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22620 /* the FPU context is blank, nobody can own it */
22621 __cpu_disable_lazy_restore(cpu);
22622
22623+#ifdef CONFIG_PAX_PER_CPU_PGD
22624+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22625+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22626+ KERNEL_PGD_PTRS);
22627+#endif
22628+
22629+ /* the FPU context is blank, nobody can own it */
22630+ __cpu_disable_lazy_restore(cpu);
22631+
22632 err = do_boot_cpu(apicid, cpu, tidle);
22633 if (err) {
22634 pr_debug("do_boot_cpu failed %d\n", err);
22635diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22636index 9b4d51d..5d28b58 100644
22637--- a/arch/x86/kernel/step.c
22638+++ b/arch/x86/kernel/step.c
22639@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22640 struct desc_struct *desc;
22641 unsigned long base;
22642
22643- seg &= ~7UL;
22644+ seg >>= 3;
22645
22646 mutex_lock(&child->mm->context.lock);
22647- if (unlikely((seg >> 3) >= child->mm->context.size))
22648+ if (unlikely(seg >= child->mm->context.size))
22649 addr = -1L; /* bogus selector, access would fault */
22650 else {
22651 desc = child->mm->context.ldt + seg;
22652@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22653 addr += base;
22654 }
22655 mutex_unlock(&child->mm->context.lock);
22656- }
22657+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22658+ addr = ktla_ktva(addr);
22659
22660 return addr;
22661 }
22662@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22663 unsigned char opcode[15];
22664 unsigned long addr = convert_ip_to_linear(child, regs);
22665
22666+ if (addr == -EINVAL)
22667+ return 0;
22668+
22669 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22670 for (i = 0; i < copied; i++) {
22671 switch (opcode[i]) {
22672diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22673new file mode 100644
22674index 0000000..207bec6
22675--- /dev/null
22676+++ b/arch/x86/kernel/sys_i386_32.c
22677@@ -0,0 +1,250 @@
22678+/*
22679+ * This file contains various random system calls that
22680+ * have a non-standard calling sequence on the Linux/i386
22681+ * platform.
22682+ */
22683+
22684+#include <linux/errno.h>
22685+#include <linux/sched.h>
22686+#include <linux/mm.h>
22687+#include <linux/fs.h>
22688+#include <linux/smp.h>
22689+#include <linux/sem.h>
22690+#include <linux/msg.h>
22691+#include <linux/shm.h>
22692+#include <linux/stat.h>
22693+#include <linux/syscalls.h>
22694+#include <linux/mman.h>
22695+#include <linux/file.h>
22696+#include <linux/utsname.h>
22697+#include <linux/ipc.h>
22698+
22699+#include <linux/uaccess.h>
22700+#include <linux/unistd.h>
22701+
22702+#include <asm/syscalls.h>
22703+
22704+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22705+{
22706+ unsigned long pax_task_size = TASK_SIZE;
22707+
22708+#ifdef CONFIG_PAX_SEGMEXEC
22709+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22710+ pax_task_size = SEGMEXEC_TASK_SIZE;
22711+#endif
22712+
22713+ if (flags & MAP_FIXED)
22714+ if (len > pax_task_size || addr > pax_task_size - len)
22715+ return -EINVAL;
22716+
22717+ return 0;
22718+}
22719+
22720+unsigned long
22721+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22722+ unsigned long len, unsigned long pgoff, unsigned long flags)
22723+{
22724+ struct mm_struct *mm = current->mm;
22725+ struct vm_area_struct *vma;
22726+ unsigned long start_addr, pax_task_size = TASK_SIZE;
22727+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22728+
22729+#ifdef CONFIG_PAX_SEGMEXEC
22730+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22731+ pax_task_size = SEGMEXEC_TASK_SIZE;
22732+#endif
22733+
22734+ pax_task_size -= PAGE_SIZE;
22735+
22736+ if (len > pax_task_size)
22737+ return -ENOMEM;
22738+
22739+ if (flags & MAP_FIXED)
22740+ return addr;
22741+
22742+#ifdef CONFIG_PAX_RANDMMAP
22743+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22744+#endif
22745+
22746+ if (addr) {
22747+ addr = PAGE_ALIGN(addr);
22748+ if (pax_task_size - len >= addr) {
22749+ vma = find_vma(mm, addr);
22750+ if (check_heap_stack_gap(vma, addr, len, offset))
22751+ return addr;
22752+ }
22753+ }
22754+ if (len > mm->cached_hole_size) {
22755+ start_addr = addr = mm->free_area_cache;
22756+ } else {
22757+ start_addr = addr = mm->mmap_base;
22758+ mm->cached_hole_size = 0;
22759+ }
22760+
22761+#ifdef CONFIG_PAX_PAGEEXEC
22762+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22763+ start_addr = 0x00110000UL;
22764+
22765+#ifdef CONFIG_PAX_RANDMMAP
22766+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22767+ start_addr += mm->delta_mmap & 0x03FFF000UL;
22768+#endif
22769+
22770+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22771+ start_addr = addr = mm->mmap_base;
22772+ else
22773+ addr = start_addr;
22774+ }
22775+#endif
22776+
22777+full_search:
22778+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22779+ /* At this point: (!vma || addr < vma->vm_end). */
22780+ if (pax_task_size - len < addr) {
22781+ /*
22782+ * Start a new search - just in case we missed
22783+ * some holes.
22784+ */
22785+ if (start_addr != mm->mmap_base) {
22786+ start_addr = addr = mm->mmap_base;
22787+ mm->cached_hole_size = 0;
22788+ goto full_search;
22789+ }
22790+ return -ENOMEM;
22791+ }
22792+ if (check_heap_stack_gap(vma, addr, len, offset))
22793+ break;
22794+ if (addr + mm->cached_hole_size < vma->vm_start)
22795+ mm->cached_hole_size = vma->vm_start - addr;
22796+ addr = vma->vm_end;
22797+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
22798+ start_addr = addr = mm->mmap_base;
22799+ mm->cached_hole_size = 0;
22800+ goto full_search;
22801+ }
22802+ }
22803+
22804+ /*
22805+ * Remember the place where we stopped the search:
22806+ */
22807+ mm->free_area_cache = addr + len;
22808+ return addr;
22809+}
22810+
22811+unsigned long
22812+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22813+ const unsigned long len, const unsigned long pgoff,
22814+ const unsigned long flags)
22815+{
22816+ struct vm_area_struct *vma;
22817+ struct mm_struct *mm = current->mm;
22818+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22819+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22820+
22821+#ifdef CONFIG_PAX_SEGMEXEC
22822+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22823+ pax_task_size = SEGMEXEC_TASK_SIZE;
22824+#endif
22825+
22826+ pax_task_size -= PAGE_SIZE;
22827+
22828+ /* requested length too big for entire address space */
22829+ if (len > pax_task_size)
22830+ return -ENOMEM;
22831+
22832+ if (flags & MAP_FIXED)
22833+ return addr;
22834+
22835+#ifdef CONFIG_PAX_PAGEEXEC
22836+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22837+ goto bottomup;
22838+#endif
22839+
22840+#ifdef CONFIG_PAX_RANDMMAP
22841+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22842+#endif
22843+
22844+ /* requesting a specific address */
22845+ if (addr) {
22846+ addr = PAGE_ALIGN(addr);
22847+ if (pax_task_size - len >= addr) {
22848+ vma = find_vma(mm, addr);
22849+ if (check_heap_stack_gap(vma, addr, len, offset))
22850+ return addr;
22851+ }
22852+ }
22853+
22854+ /* check if free_area_cache is useful for us */
22855+ if (len <= mm->cached_hole_size) {
22856+ mm->cached_hole_size = 0;
22857+ mm->free_area_cache = mm->mmap_base;
22858+ }
22859+
22860+ /* either no address requested or can't fit in requested address hole */
22861+ addr = mm->free_area_cache;
22862+
22863+ /* make sure it can fit in the remaining address space */
22864+ if (addr > len) {
22865+ vma = find_vma(mm, addr-len);
22866+ if (check_heap_stack_gap(vma, addr - len, len, offset))
22867+ /* remember the address as a hint for next time */
22868+ return (mm->free_area_cache = addr-len);
22869+ }
22870+
22871+ if (mm->mmap_base < len)
22872+ goto bottomup;
22873+
22874+ addr = mm->mmap_base-len;
22875+
22876+ do {
22877+ /*
22878+ * Lookup failure means no vma is above this address,
22879+ * else if new region fits below vma->vm_start,
22880+ * return with success:
22881+ */
22882+ vma = find_vma(mm, addr);
22883+ if (check_heap_stack_gap(vma, addr, len, offset))
22884+ /* remember the address as a hint for next time */
22885+ return (mm->free_area_cache = addr);
22886+
22887+ /* remember the largest hole we saw so far */
22888+ if (addr + mm->cached_hole_size < vma->vm_start)
22889+ mm->cached_hole_size = vma->vm_start - addr;
22890+
22891+ /* try just below the current vma->vm_start */
22892+ addr = skip_heap_stack_gap(vma, len, offset);
22893+ } while (!IS_ERR_VALUE(addr));
22894+
22895+bottomup:
22896+ /*
22897+ * A failed mmap() very likely causes application failure,
22898+ * so fall back to the bottom-up function here. This scenario
22899+ * can happen with large stack limits and large mmap()
22900+ * allocations.
22901+ */
22902+
22903+#ifdef CONFIG_PAX_SEGMEXEC
22904+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22905+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22906+ else
22907+#endif
22908+
22909+ mm->mmap_base = TASK_UNMAPPED_BASE;
22910+
22911+#ifdef CONFIG_PAX_RANDMMAP
22912+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22913+ mm->mmap_base += mm->delta_mmap;
22914+#endif
22915+
22916+ mm->free_area_cache = mm->mmap_base;
22917+ mm->cached_hole_size = ~0UL;
22918+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22919+ /*
22920+ * Restore the topdown base:
22921+ */
22922+ mm->mmap_base = base;
22923+ mm->free_area_cache = base;
22924+ mm->cached_hole_size = ~0UL;
22925+
22926+ return addr;
22927+}
22928diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22929index 97ef74b..57a1882 100644
22930--- a/arch/x86/kernel/sys_x86_64.c
22931+++ b/arch/x86/kernel/sys_x86_64.c
22932@@ -81,8 +81,8 @@ out:
22933 return error;
22934 }
22935
22936-static void find_start_end(unsigned long flags, unsigned long *begin,
22937- unsigned long *end)
22938+static void find_start_end(struct mm_struct *mm, unsigned long flags,
22939+ unsigned long *begin, unsigned long *end)
22940 {
22941 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22942 unsigned long new_begin;
22943@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22944 *begin = new_begin;
22945 }
22946 } else {
22947- *begin = TASK_UNMAPPED_BASE;
22948+ *begin = mm->mmap_base;
22949 *end = TASK_SIZE;
22950 }
22951 }
22952@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22953 struct vm_area_struct *vma;
22954 struct vm_unmapped_area_info info;
22955 unsigned long begin, end;
22956+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22957
22958 if (flags & MAP_FIXED)
22959 return addr;
22960
22961- find_start_end(flags, &begin, &end);
22962+ find_start_end(mm, flags, &begin, &end);
22963
22964 if (len > end)
22965 return -ENOMEM;
22966
22967+#ifdef CONFIG_PAX_RANDMMAP
22968+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22969+#endif
22970+
22971 if (addr) {
22972 addr = PAGE_ALIGN(addr);
22973 vma = find_vma(mm, addr);
22974- if (end - len >= addr &&
22975- (!vma || addr + len <= vma->vm_start))
22976+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22977 return addr;
22978 }
22979
22980@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22981 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22982 goto bottomup;
22983
22984+#ifdef CONFIG_PAX_RANDMMAP
22985+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22986+#endif
22987+
22988 /* requesting a specific address */
22989 if (addr) {
22990 addr = PAGE_ALIGN(addr);
22991diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22992index f84fe00..f41d9f1 100644
22993--- a/arch/x86/kernel/tboot.c
22994+++ b/arch/x86/kernel/tboot.c
22995@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22996
22997 void tboot_shutdown(u32 shutdown_type)
22998 {
22999- void (*shutdown)(void);
23000+ void (* __noreturn shutdown)(void);
23001
23002 if (!tboot_enabled())
23003 return;
23004@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23005
23006 switch_to_tboot_pt();
23007
23008- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23009+ shutdown = (void *)tboot->shutdown_entry;
23010 shutdown();
23011
23012 /* should not reach here */
23013@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23014 return 0;
23015 }
23016
23017-static atomic_t ap_wfs_count;
23018+static atomic_unchecked_t ap_wfs_count;
23019
23020 static int tboot_wait_for_aps(int num_aps)
23021 {
23022@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23023 {
23024 switch (action) {
23025 case CPU_DYING:
23026- atomic_inc(&ap_wfs_count);
23027+ atomic_inc_unchecked(&ap_wfs_count);
23028 if (num_online_cpus() == 1)
23029- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23030+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23031 return NOTIFY_BAD;
23032 break;
23033 }
23034 return NOTIFY_OK;
23035 }
23036
23037-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23038+static struct notifier_block tboot_cpu_notifier =
23039 {
23040 .notifier_call = tboot_cpu_callback,
23041 };
23042@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23043
23044 tboot_create_trampoline();
23045
23046- atomic_set(&ap_wfs_count, 0);
23047+ atomic_set_unchecked(&ap_wfs_count, 0);
23048 register_hotcpu_notifier(&tboot_cpu_notifier);
23049
23050 acpi_os_set_prepare_sleep(&tboot_sleep);
23051diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23052index 24d3c91..d06b473 100644
23053--- a/arch/x86/kernel/time.c
23054+++ b/arch/x86/kernel/time.c
23055@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23056 {
23057 unsigned long pc = instruction_pointer(regs);
23058
23059- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23060+ if (!user_mode(regs) && in_lock_functions(pc)) {
23061 #ifdef CONFIG_FRAME_POINTER
23062- return *(unsigned long *)(regs->bp + sizeof(long));
23063+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23064 #else
23065 unsigned long *sp =
23066 (unsigned long *)kernel_stack_pointer(regs);
23067@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23068 * or above a saved flags. Eflags has bits 22-31 zero,
23069 * kernel addresses don't.
23070 */
23071+
23072+#ifdef CONFIG_PAX_KERNEXEC
23073+ return ktla_ktva(sp[0]);
23074+#else
23075 if (sp[0] >> 22)
23076 return sp[0];
23077 if (sp[1] >> 22)
23078 return sp[1];
23079 #endif
23080+
23081+#endif
23082 }
23083 return pc;
23084 }
23085diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23086index 9d9d2f9..cad418a 100644
23087--- a/arch/x86/kernel/tls.c
23088+++ b/arch/x86/kernel/tls.c
23089@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23090 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23091 return -EINVAL;
23092
23093+#ifdef CONFIG_PAX_SEGMEXEC
23094+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23095+ return -EINVAL;
23096+#endif
23097+
23098 set_tls_desc(p, idx, &info, 1);
23099
23100 return 0;
23101@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23102
23103 if (kbuf)
23104 info = kbuf;
23105- else if (__copy_from_user(infobuf, ubuf, count))
23106+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23107 return -EFAULT;
23108 else
23109 info = infobuf;
23110diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23111index ecffca1..95c4d13 100644
23112--- a/arch/x86/kernel/traps.c
23113+++ b/arch/x86/kernel/traps.c
23114@@ -68,12 +68,6 @@
23115 #include <asm/setup.h>
23116
23117 asmlinkage int system_call(void);
23118-
23119-/*
23120- * The IDT has to be page-aligned to simplify the Pentium
23121- * F0 0F bug workaround.
23122- */
23123-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23124 #endif
23125
23126 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23127@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23128 }
23129
23130 static int __kprobes
23131-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23132+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23133 struct pt_regs *regs, long error_code)
23134 {
23135 #ifdef CONFIG_X86_32
23136- if (regs->flags & X86_VM_MASK) {
23137+ if (v8086_mode(regs)) {
23138 /*
23139 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23140 * On nmi (interrupt 2), do_trap should not be called.
23141@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23142 return -1;
23143 }
23144 #endif
23145- if (!user_mode(regs)) {
23146+ if (!user_mode_novm(regs)) {
23147 if (!fixup_exception(regs)) {
23148 tsk->thread.error_code = error_code;
23149 tsk->thread.trap_nr = trapnr;
23150+
23151+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23152+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23153+ str = "PAX: suspicious stack segment fault";
23154+#endif
23155+
23156 die(str, regs, error_code);
23157 }
23158+
23159+#ifdef CONFIG_PAX_REFCOUNT
23160+ if (trapnr == 4)
23161+ pax_report_refcount_overflow(regs);
23162+#endif
23163+
23164 return 0;
23165 }
23166
23167@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23168 }
23169
23170 static void __kprobes
23171-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23172+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23173 long error_code, siginfo_t *info)
23174 {
23175 struct task_struct *tsk = current;
23176@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23177 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23178 printk_ratelimit()) {
23179 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23180- tsk->comm, tsk->pid, str,
23181+ tsk->comm, task_pid_nr(tsk), str,
23182 regs->ip, regs->sp, error_code);
23183 print_vma_addr(" in ", regs->ip);
23184 pr_cont("\n");
23185@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23186 conditional_sti(regs);
23187
23188 #ifdef CONFIG_X86_32
23189- if (regs->flags & X86_VM_MASK) {
23190+ if (v8086_mode(regs)) {
23191 local_irq_enable();
23192 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23193 goto exit;
23194@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23195 #endif
23196
23197 tsk = current;
23198- if (!user_mode(regs)) {
23199+ if (!user_mode_novm(regs)) {
23200 if (fixup_exception(regs))
23201 goto exit;
23202
23203 tsk->thread.error_code = error_code;
23204 tsk->thread.trap_nr = X86_TRAP_GP;
23205 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23206- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23207+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23208+
23209+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23210+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23211+ die("PAX: suspicious general protection fault", regs, error_code);
23212+ else
23213+#endif
23214+
23215 die("general protection fault", regs, error_code);
23216+ }
23217 goto exit;
23218 }
23219
23220+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23221+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23222+ struct mm_struct *mm = tsk->mm;
23223+ unsigned long limit;
23224+
23225+ down_write(&mm->mmap_sem);
23226+ limit = mm->context.user_cs_limit;
23227+ if (limit < TASK_SIZE) {
23228+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23229+ up_write(&mm->mmap_sem);
23230+ return;
23231+ }
23232+ up_write(&mm->mmap_sem);
23233+ }
23234+#endif
23235+
23236 tsk->thread.error_code = error_code;
23237 tsk->thread.trap_nr = X86_TRAP_GP;
23238
23239@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23240 /* It's safe to allow irq's after DR6 has been saved */
23241 preempt_conditional_sti(regs);
23242
23243- if (regs->flags & X86_VM_MASK) {
23244+ if (v8086_mode(regs)) {
23245 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23246 X86_TRAP_DB);
23247 preempt_conditional_cli(regs);
23248@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23249 * We already checked v86 mode above, so we can check for kernel mode
23250 * by just checking the CPL of CS.
23251 */
23252- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23253+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23254 tsk->thread.debugreg6 &= ~DR_STEP;
23255 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23256 regs->flags &= ~X86_EFLAGS_TF;
23257@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23258 return;
23259 conditional_sti(regs);
23260
23261- if (!user_mode_vm(regs))
23262+ if (!user_mode(regs))
23263 {
23264 if (!fixup_exception(regs)) {
23265 task->thread.error_code = error_code;
23266diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23267index c71025b..b117501 100644
23268--- a/arch/x86/kernel/uprobes.c
23269+++ b/arch/x86/kernel/uprobes.c
23270@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23271 int ret = NOTIFY_DONE;
23272
23273 /* We are only interested in userspace traps */
23274- if (regs && !user_mode_vm(regs))
23275+ if (regs && !user_mode(regs))
23276 return NOTIFY_DONE;
23277
23278 switch (val) {
23279diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23280index b9242ba..50c5edd 100644
23281--- a/arch/x86/kernel/verify_cpu.S
23282+++ b/arch/x86/kernel/verify_cpu.S
23283@@ -20,6 +20,7 @@
23284 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23285 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23286 * arch/x86/kernel/head_32.S: processor startup
23287+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23288 *
23289 * verify_cpu, returns the status of longmode and SSE in register %eax.
23290 * 0: Success 1: Failure
23291diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23292index 1dfe69c..a3df6f6 100644
23293--- a/arch/x86/kernel/vm86_32.c
23294+++ b/arch/x86/kernel/vm86_32.c
23295@@ -43,6 +43,7 @@
23296 #include <linux/ptrace.h>
23297 #include <linux/audit.h>
23298 #include <linux/stddef.h>
23299+#include <linux/grsecurity.h>
23300
23301 #include <asm/uaccess.h>
23302 #include <asm/io.h>
23303@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23304 do_exit(SIGSEGV);
23305 }
23306
23307- tss = &per_cpu(init_tss, get_cpu());
23308+ tss = init_tss + get_cpu();
23309 current->thread.sp0 = current->thread.saved_sp0;
23310 current->thread.sysenter_cs = __KERNEL_CS;
23311 load_sp0(tss, &current->thread);
23312@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
23313 struct task_struct *tsk;
23314 int tmp, ret = -EPERM;
23315
23316+#ifdef CONFIG_GRKERNSEC_VM86
23317+ if (!capable(CAP_SYS_RAWIO)) {
23318+ gr_handle_vm86();
23319+ goto out;
23320+ }
23321+#endif
23322+
23323 tsk = current;
23324 if (tsk->thread.saved_sp0)
23325 goto out;
23326@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23327 int tmp, ret;
23328 struct vm86plus_struct __user *v86;
23329
23330+#ifdef CONFIG_GRKERNSEC_VM86
23331+ if (!capable(CAP_SYS_RAWIO)) {
23332+ gr_handle_vm86();
23333+ ret = -EPERM;
23334+ goto out;
23335+ }
23336+#endif
23337+
23338 tsk = current;
23339 switch (cmd) {
23340 case VM86_REQUEST_IRQ:
23341@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23342 tsk->thread.saved_fs = info->regs32->fs;
23343 tsk->thread.saved_gs = get_user_gs(info->regs32);
23344
23345- tss = &per_cpu(init_tss, get_cpu());
23346+ tss = init_tss + get_cpu();
23347 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23348 if (cpu_has_sep)
23349 tsk->thread.sysenter_cs = 0;
23350@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23351 goto cannot_handle;
23352 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23353 goto cannot_handle;
23354- intr_ptr = (unsigned long __user *) (i << 2);
23355+ intr_ptr = (__force unsigned long __user *) (i << 2);
23356 if (get_user(segoffs, intr_ptr))
23357 goto cannot_handle;
23358 if ((segoffs >> 16) == BIOSSEG)
23359diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23360index 22a1530..8fbaaad 100644
23361--- a/arch/x86/kernel/vmlinux.lds.S
23362+++ b/arch/x86/kernel/vmlinux.lds.S
23363@@ -26,6 +26,13 @@
23364 #include <asm/page_types.h>
23365 #include <asm/cache.h>
23366 #include <asm/boot.h>
23367+#include <asm/segment.h>
23368+
23369+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23370+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23371+#else
23372+#define __KERNEL_TEXT_OFFSET 0
23373+#endif
23374
23375 #undef i386 /* in case the preprocessor is a 32bit one */
23376
23377@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23378
23379 PHDRS {
23380 text PT_LOAD FLAGS(5); /* R_E */
23381+#ifdef CONFIG_X86_32
23382+ module PT_LOAD FLAGS(5); /* R_E */
23383+#endif
23384+#ifdef CONFIG_XEN
23385+ rodata PT_LOAD FLAGS(5); /* R_E */
23386+#else
23387+ rodata PT_LOAD FLAGS(4); /* R__ */
23388+#endif
23389 data PT_LOAD FLAGS(6); /* RW_ */
23390-#ifdef CONFIG_X86_64
23391+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23392 #ifdef CONFIG_SMP
23393 percpu PT_LOAD FLAGS(6); /* RW_ */
23394 #endif
23395+ text.init PT_LOAD FLAGS(5); /* R_E */
23396+ text.exit PT_LOAD FLAGS(5); /* R_E */
23397 init PT_LOAD FLAGS(7); /* RWE */
23398-#endif
23399 note PT_NOTE FLAGS(0); /* ___ */
23400 }
23401
23402 SECTIONS
23403 {
23404 #ifdef CONFIG_X86_32
23405- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23406- phys_startup_32 = startup_32 - LOAD_OFFSET;
23407+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23408 #else
23409- . = __START_KERNEL;
23410- phys_startup_64 = startup_64 - LOAD_OFFSET;
23411+ . = __START_KERNEL;
23412 #endif
23413
23414 /* Text and read-only data */
23415- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23416- _text = .;
23417+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23418 /* bootstrapping code */
23419+#ifdef CONFIG_X86_32
23420+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23421+#else
23422+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23423+#endif
23424+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23425+ _text = .;
23426 HEAD_TEXT
23427 #ifdef CONFIG_X86_32
23428 . = ALIGN(PAGE_SIZE);
23429@@ -108,13 +128,48 @@ SECTIONS
23430 IRQENTRY_TEXT
23431 *(.fixup)
23432 *(.gnu.warning)
23433- /* End of text section */
23434- _etext = .;
23435 } :text = 0x9090
23436
23437- NOTES :text :note
23438+ . += __KERNEL_TEXT_OFFSET;
23439
23440- EXCEPTION_TABLE(16) :text = 0x9090
23441+#ifdef CONFIG_X86_32
23442+ . = ALIGN(PAGE_SIZE);
23443+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23444+
23445+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23446+ MODULES_EXEC_VADDR = .;
23447+ BYTE(0)
23448+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23449+ . = ALIGN(HPAGE_SIZE) - 1;
23450+ MODULES_EXEC_END = .;
23451+#endif
23452+
23453+ } :module
23454+#endif
23455+
23456+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23457+ /* End of text section */
23458+ BYTE(0)
23459+ _etext = . - __KERNEL_TEXT_OFFSET;
23460+ }
23461+
23462+#ifdef CONFIG_X86_32
23463+ . = ALIGN(PAGE_SIZE);
23464+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23465+ *(.idt)
23466+ . = ALIGN(PAGE_SIZE);
23467+ *(.empty_zero_page)
23468+ *(.initial_pg_fixmap)
23469+ *(.initial_pg_pmd)
23470+ *(.initial_page_table)
23471+ *(.swapper_pg_dir)
23472+ } :rodata
23473+#endif
23474+
23475+ . = ALIGN(PAGE_SIZE);
23476+ NOTES :rodata :note
23477+
23478+ EXCEPTION_TABLE(16) :rodata
23479
23480 #if defined(CONFIG_DEBUG_RODATA)
23481 /* .text should occupy whole number of pages */
23482@@ -126,16 +181,20 @@ SECTIONS
23483
23484 /* Data */
23485 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23486+
23487+#ifdef CONFIG_PAX_KERNEXEC
23488+ . = ALIGN(HPAGE_SIZE);
23489+#else
23490+ . = ALIGN(PAGE_SIZE);
23491+#endif
23492+
23493 /* Start of data section */
23494 _sdata = .;
23495
23496 /* init_task */
23497 INIT_TASK_DATA(THREAD_SIZE)
23498
23499-#ifdef CONFIG_X86_32
23500- /* 32 bit has nosave before _edata */
23501 NOSAVE_DATA
23502-#endif
23503
23504 PAGE_ALIGNED_DATA(PAGE_SIZE)
23505
23506@@ -176,12 +235,19 @@ SECTIONS
23507 #endif /* CONFIG_X86_64 */
23508
23509 /* Init code and data - will be freed after init */
23510- . = ALIGN(PAGE_SIZE);
23511 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23512+ BYTE(0)
23513+
23514+#ifdef CONFIG_PAX_KERNEXEC
23515+ . = ALIGN(HPAGE_SIZE);
23516+#else
23517+ . = ALIGN(PAGE_SIZE);
23518+#endif
23519+
23520 __init_begin = .; /* paired with __init_end */
23521- }
23522+ } :init.begin
23523
23524-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23525+#ifdef CONFIG_SMP
23526 /*
23527 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23528 * output PHDR, so the next output section - .init.text - should
23529@@ -190,12 +256,27 @@ SECTIONS
23530 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23531 #endif
23532
23533- INIT_TEXT_SECTION(PAGE_SIZE)
23534-#ifdef CONFIG_X86_64
23535- :init
23536-#endif
23537+ . = ALIGN(PAGE_SIZE);
23538+ init_begin = .;
23539+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23540+ VMLINUX_SYMBOL(_sinittext) = .;
23541+ INIT_TEXT
23542+ VMLINUX_SYMBOL(_einittext) = .;
23543+ . = ALIGN(PAGE_SIZE);
23544+ } :text.init
23545
23546- INIT_DATA_SECTION(16)
23547+ /*
23548+ * .exit.text is discard at runtime, not link time, to deal with
23549+ * references from .altinstructions and .eh_frame
23550+ */
23551+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23552+ EXIT_TEXT
23553+ . = ALIGN(16);
23554+ } :text.exit
23555+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23556+
23557+ . = ALIGN(PAGE_SIZE);
23558+ INIT_DATA_SECTION(16) :init
23559
23560 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23561 __x86_cpu_dev_start = .;
23562@@ -257,19 +338,12 @@ SECTIONS
23563 }
23564
23565 . = ALIGN(8);
23566- /*
23567- * .exit.text is discard at runtime, not link time, to deal with
23568- * references from .altinstructions and .eh_frame
23569- */
23570- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23571- EXIT_TEXT
23572- }
23573
23574 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23575 EXIT_DATA
23576 }
23577
23578-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23579+#ifndef CONFIG_SMP
23580 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23581 #endif
23582
23583@@ -288,16 +362,10 @@ SECTIONS
23584 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23585 __smp_locks = .;
23586 *(.smp_locks)
23587- . = ALIGN(PAGE_SIZE);
23588 __smp_locks_end = .;
23589+ . = ALIGN(PAGE_SIZE);
23590 }
23591
23592-#ifdef CONFIG_X86_64
23593- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23594- NOSAVE_DATA
23595- }
23596-#endif
23597-
23598 /* BSS */
23599 . = ALIGN(PAGE_SIZE);
23600 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23601@@ -313,6 +381,7 @@ SECTIONS
23602 __brk_base = .;
23603 . += 64 * 1024; /* 64k alignment slop space */
23604 *(.brk_reservation) /* areas brk users have reserved */
23605+ . = ALIGN(HPAGE_SIZE);
23606 __brk_limit = .;
23607 }
23608
23609@@ -339,13 +408,12 @@ SECTIONS
23610 * for the boot processor.
23611 */
23612 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23613-INIT_PER_CPU(gdt_page);
23614 INIT_PER_CPU(irq_stack_union);
23615
23616 /*
23617 * Build-time check on the image size:
23618 */
23619-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23620+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23621 "kernel image bigger than KERNEL_IMAGE_SIZE");
23622
23623 #ifdef CONFIG_SMP
23624diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23625index 9a907a6..f83f921 100644
23626--- a/arch/x86/kernel/vsyscall_64.c
23627+++ b/arch/x86/kernel/vsyscall_64.c
23628@@ -56,15 +56,13 @@
23629 DEFINE_VVAR(int, vgetcpu_mode);
23630 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23631
23632-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23633+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23634
23635 static int __init vsyscall_setup(char *str)
23636 {
23637 if (str) {
23638 if (!strcmp("emulate", str))
23639 vsyscall_mode = EMULATE;
23640- else if (!strcmp("native", str))
23641- vsyscall_mode = NATIVE;
23642 else if (!strcmp("none", str))
23643 vsyscall_mode = NONE;
23644 else
23645@@ -323,8 +321,7 @@ do_ret:
23646 return true;
23647
23648 sigsegv:
23649- force_sig(SIGSEGV, current);
23650- return true;
23651+ do_group_exit(SIGKILL);
23652 }
23653
23654 /*
23655@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23656 extern char __vvar_page;
23657 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23658
23659- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23660- vsyscall_mode == NATIVE
23661- ? PAGE_KERNEL_VSYSCALL
23662- : PAGE_KERNEL_VVAR);
23663+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23664 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23665 (unsigned long)VSYSCALL_START);
23666
23667diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23668index 1330dd1..d220b99 100644
23669--- a/arch/x86/kernel/x8664_ksyms_64.c
23670+++ b/arch/x86/kernel/x8664_ksyms_64.c
23671@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23672 EXPORT_SYMBOL(copy_user_generic_unrolled);
23673 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23674 EXPORT_SYMBOL(__copy_user_nocache);
23675-EXPORT_SYMBOL(_copy_from_user);
23676-EXPORT_SYMBOL(_copy_to_user);
23677
23678 EXPORT_SYMBOL(copy_page);
23679 EXPORT_SYMBOL(clear_page);
23680diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23681index 7a3d075..6cb373d 100644
23682--- a/arch/x86/kernel/x86_init.c
23683+++ b/arch/x86/kernel/x86_init.c
23684@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23685 },
23686 };
23687
23688-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23689+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23690 .early_percpu_clock_init = x86_init_noop,
23691 .setup_percpu_clockev = setup_secondary_APIC_clock,
23692 };
23693@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23694 static void default_nmi_init(void) { };
23695 static int default_i8042_detect(void) { return 1; };
23696
23697-struct x86_platform_ops x86_platform = {
23698+struct x86_platform_ops x86_platform __read_only = {
23699 .calibrate_tsc = native_calibrate_tsc,
23700 .get_wallclock = mach_get_cmos_time,
23701 .set_wallclock = mach_set_rtc_mmss,
23702@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23703 };
23704
23705 EXPORT_SYMBOL_GPL(x86_platform);
23706-struct x86_msi_ops x86_msi = {
23707+struct x86_msi_ops x86_msi __read_only = {
23708 .setup_msi_irqs = native_setup_msi_irqs,
23709 .teardown_msi_irq = native_teardown_msi_irq,
23710 .teardown_msi_irqs = default_teardown_msi_irqs,
23711 .restore_msi_irqs = default_restore_msi_irqs,
23712 };
23713
23714-struct x86_io_apic_ops x86_io_apic_ops = {
23715+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23716 .init = native_io_apic_init_mappings,
23717 .read = native_io_apic_read,
23718 .write = native_io_apic_write,
23719diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23720index ada87a3..afea76d 100644
23721--- a/arch/x86/kernel/xsave.c
23722+++ b/arch/x86/kernel/xsave.c
23723@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23724 {
23725 int err;
23726
23727+ buf = (struct xsave_struct __user *)____m(buf);
23728 if (use_xsave())
23729 err = xsave_user(buf);
23730 else if (use_fxsr())
23731@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23732 */
23733 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23734 {
23735+ buf = (void __user *)____m(buf);
23736 if (use_xsave()) {
23737 if ((unsigned long)buf % 64 || fx_only) {
23738 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23739diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23740index a20ecb5..d0e2194 100644
23741--- a/arch/x86/kvm/cpuid.c
23742+++ b/arch/x86/kvm/cpuid.c
23743@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23744 struct kvm_cpuid2 *cpuid,
23745 struct kvm_cpuid_entry2 __user *entries)
23746 {
23747- int r;
23748+ int r, i;
23749
23750 r = -E2BIG;
23751 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23752 goto out;
23753 r = -EFAULT;
23754- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23755- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23756+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23757 goto out;
23758+ for (i = 0; i < cpuid->nent; ++i) {
23759+ struct kvm_cpuid_entry2 cpuid_entry;
23760+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23761+ goto out;
23762+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23763+ }
23764 vcpu->arch.cpuid_nent = cpuid->nent;
23765 kvm_apic_set_version(vcpu);
23766 kvm_x86_ops->cpuid_update(vcpu);
23767@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23768 struct kvm_cpuid2 *cpuid,
23769 struct kvm_cpuid_entry2 __user *entries)
23770 {
23771- int r;
23772+ int r, i;
23773
23774 r = -E2BIG;
23775 if (cpuid->nent < vcpu->arch.cpuid_nent)
23776 goto out;
23777 r = -EFAULT;
23778- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23779- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23780+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23781 goto out;
23782+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23783+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23784+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23785+ goto out;
23786+ }
23787 return 0;
23788
23789 out:
23790diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23791index a27e763..54bfe43 100644
23792--- a/arch/x86/kvm/emulate.c
23793+++ b/arch/x86/kvm/emulate.c
23794@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23795
23796 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23797 do { \
23798+ unsigned long _tmp; \
23799 __asm__ __volatile__ ( \
23800 _PRE_EFLAGS("0", "4", "2") \
23801 _op _suffix " %"_x"3,%1; " \
23802@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23803 /* Raw emulation: instruction has two explicit operands. */
23804 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23805 do { \
23806- unsigned long _tmp; \
23807- \
23808 switch ((ctxt)->dst.bytes) { \
23809 case 2: \
23810 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23811@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23812
23813 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23814 do { \
23815- unsigned long _tmp; \
23816 switch ((ctxt)->dst.bytes) { \
23817 case 1: \
23818 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23819diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23820index 9392f52..0e56d77 100644
23821--- a/arch/x86/kvm/lapic.c
23822+++ b/arch/x86/kvm/lapic.c
23823@@ -55,7 +55,7 @@
23824 #define APIC_BUS_CYCLE_NS 1
23825
23826 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23827-#define apic_debug(fmt, arg...)
23828+#define apic_debug(fmt, arg...) do {} while (0)
23829
23830 #define APIC_LVT_NUM 6
23831 /* 14 is the version for Xeon and Pentium 8.4.8*/
23832diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23833index 891eb6d..e027900 100644
23834--- a/arch/x86/kvm/paging_tmpl.h
23835+++ b/arch/x86/kvm/paging_tmpl.h
23836@@ -208,7 +208,7 @@ retry_walk:
23837 if (unlikely(kvm_is_error_hva(host_addr)))
23838 goto error;
23839
23840- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23841+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23842 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23843 goto error;
23844 walker->ptep_user[walker->level - 1] = ptep_user;
23845diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23846index d29d3cd..ec9d522 100644
23847--- a/arch/x86/kvm/svm.c
23848+++ b/arch/x86/kvm/svm.c
23849@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23850 int cpu = raw_smp_processor_id();
23851
23852 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23853+
23854+ pax_open_kernel();
23855 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23856+ pax_close_kernel();
23857+
23858 load_TR_desc();
23859 }
23860
23861@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23862 #endif
23863 #endif
23864
23865+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23866+ __set_fs(current_thread_info()->addr_limit);
23867+#endif
23868+
23869 reload_tss(vcpu);
23870
23871 local_irq_disable();
23872diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23873index 9120ae1..238abc0 100644
23874--- a/arch/x86/kvm/vmx.c
23875+++ b/arch/x86/kvm/vmx.c
23876@@ -1370,7 +1370,11 @@ static void reload_tss(void)
23877 struct desc_struct *descs;
23878
23879 descs = (void *)gdt->address;
23880+
23881+ pax_open_kernel();
23882 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23883+ pax_close_kernel();
23884+
23885 load_TR_desc();
23886 }
23887
23888@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23889 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23890 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23891
23892+#ifdef CONFIG_PAX_PER_CPU_PGD
23893+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23894+#endif
23895+
23896 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23897 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23898 vmx->loaded_vmcs->cpu = cpu;
23899@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23900 if (!cpu_has_vmx_flexpriority())
23901 flexpriority_enabled = 0;
23902
23903- if (!cpu_has_vmx_tpr_shadow())
23904- kvm_x86_ops->update_cr8_intercept = NULL;
23905+ if (!cpu_has_vmx_tpr_shadow()) {
23906+ pax_open_kernel();
23907+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23908+ pax_close_kernel();
23909+ }
23910
23911 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23912 kvm_disable_largepages();
23913@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23914
23915 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23916 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23917+
23918+#ifndef CONFIG_PAX_PER_CPU_PGD
23919 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23920+#endif
23921
23922 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23923 #ifdef CONFIG_X86_64
23924@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23925 native_store_idt(&dt);
23926 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23927
23928- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23929+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23930
23931 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23932 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23933@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23934 "jmp 2f \n\t"
23935 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23936 "2: "
23937+
23938+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23939+ "ljmp %[cs],$3f\n\t"
23940+ "3: "
23941+#endif
23942+
23943 /* Save guest registers, load host registers, keep flags */
23944 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23945 "pop %0 \n\t"
23946@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23947 #endif
23948 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23949 [wordsize]"i"(sizeof(ulong))
23950+
23951+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23952+ ,[cs]"i"(__KERNEL_CS)
23953+#endif
23954+
23955 : "cc", "memory"
23956 #ifdef CONFIG_X86_64
23957 , "rax", "rbx", "rdi", "rsi"
23958@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23959 if (debugctlmsr)
23960 update_debugctlmsr(debugctlmsr);
23961
23962-#ifndef CONFIG_X86_64
23963+#ifdef CONFIG_X86_32
23964 /*
23965 * The sysexit path does not restore ds/es, so we must set them to
23966 * a reasonable value ourselves.
23967@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23968 * may be executed in interrupt context, which saves and restore segments
23969 * around it, nullifying its effect.
23970 */
23971- loadsegment(ds, __USER_DS);
23972- loadsegment(es, __USER_DS);
23973+ loadsegment(ds, __KERNEL_DS);
23974+ loadsegment(es, __KERNEL_DS);
23975+ loadsegment(ss, __KERNEL_DS);
23976+
23977+#ifdef CONFIG_PAX_KERNEXEC
23978+ loadsegment(fs, __KERNEL_PERCPU);
23979+#endif
23980+
23981+#ifdef CONFIG_PAX_MEMORY_UDEREF
23982+ __set_fs(current_thread_info()->addr_limit);
23983+#endif
23984+
23985 #endif
23986
23987 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23988diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23989index c243b81..9eb193f 100644
23990--- a/arch/x86/kvm/x86.c
23991+++ b/arch/x86/kvm/x86.c
23992@@ -1692,8 +1692,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
23993 {
23994 struct kvm *kvm = vcpu->kvm;
23995 int lm = is_long_mode(vcpu);
23996- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23997- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23998+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23999+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24000 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24001 : kvm->arch.xen_hvm_config.blob_size_32;
24002 u32 page_num = data & ~PAGE_MASK;
24003@@ -2571,6 +2571,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24004 if (n < msr_list.nmsrs)
24005 goto out;
24006 r = -EFAULT;
24007+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24008+ goto out;
24009 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24010 num_msrs_to_save * sizeof(u32)))
24011 goto out;
24012@@ -2700,7 +2702,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24013 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24014 struct kvm_interrupt *irq)
24015 {
24016- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24017+ if (irq->irq >= KVM_NR_INTERRUPTS)
24018 return -EINVAL;
24019 if (irqchip_in_kernel(vcpu->kvm))
24020 return -ENXIO;
24021@@ -5213,7 +5215,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24022 };
24023 #endif
24024
24025-int kvm_arch_init(void *opaque)
24026+int kvm_arch_init(const void *opaque)
24027 {
24028 int r;
24029 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24030diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24031index df4176c..23ce092 100644
24032--- a/arch/x86/lguest/boot.c
24033+++ b/arch/x86/lguest/boot.c
24034@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24035 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24036 * Launcher to reboot us.
24037 */
24038-static void lguest_restart(char *reason)
24039+static __noreturn void lguest_restart(char *reason)
24040 {
24041 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24042+ BUG();
24043 }
24044
24045 /*G:050
24046diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24047index 00933d5..3a64af9 100644
24048--- a/arch/x86/lib/atomic64_386_32.S
24049+++ b/arch/x86/lib/atomic64_386_32.S
24050@@ -48,6 +48,10 @@ BEGIN(read)
24051 movl (v), %eax
24052 movl 4(v), %edx
24053 RET_ENDP
24054+BEGIN(read_unchecked)
24055+ movl (v), %eax
24056+ movl 4(v), %edx
24057+RET_ENDP
24058 #undef v
24059
24060 #define v %esi
24061@@ -55,6 +59,10 @@ BEGIN(set)
24062 movl %ebx, (v)
24063 movl %ecx, 4(v)
24064 RET_ENDP
24065+BEGIN(set_unchecked)
24066+ movl %ebx, (v)
24067+ movl %ecx, 4(v)
24068+RET_ENDP
24069 #undef v
24070
24071 #define v %esi
24072@@ -70,6 +78,20 @@ RET_ENDP
24073 BEGIN(add)
24074 addl %eax, (v)
24075 adcl %edx, 4(v)
24076+
24077+#ifdef CONFIG_PAX_REFCOUNT
24078+ jno 0f
24079+ subl %eax, (v)
24080+ sbbl %edx, 4(v)
24081+ int $4
24082+0:
24083+ _ASM_EXTABLE(0b, 0b)
24084+#endif
24085+
24086+RET_ENDP
24087+BEGIN(add_unchecked)
24088+ addl %eax, (v)
24089+ adcl %edx, 4(v)
24090 RET_ENDP
24091 #undef v
24092
24093@@ -77,6 +99,24 @@ RET_ENDP
24094 BEGIN(add_return)
24095 addl (v), %eax
24096 adcl 4(v), %edx
24097+
24098+#ifdef CONFIG_PAX_REFCOUNT
24099+ into
24100+1234:
24101+ _ASM_EXTABLE(1234b, 2f)
24102+#endif
24103+
24104+ movl %eax, (v)
24105+ movl %edx, 4(v)
24106+
24107+#ifdef CONFIG_PAX_REFCOUNT
24108+2:
24109+#endif
24110+
24111+RET_ENDP
24112+BEGIN(add_return_unchecked)
24113+ addl (v), %eax
24114+ adcl 4(v), %edx
24115 movl %eax, (v)
24116 movl %edx, 4(v)
24117 RET_ENDP
24118@@ -86,6 +126,20 @@ RET_ENDP
24119 BEGIN(sub)
24120 subl %eax, (v)
24121 sbbl %edx, 4(v)
24122+
24123+#ifdef CONFIG_PAX_REFCOUNT
24124+ jno 0f
24125+ addl %eax, (v)
24126+ adcl %edx, 4(v)
24127+ int $4
24128+0:
24129+ _ASM_EXTABLE(0b, 0b)
24130+#endif
24131+
24132+RET_ENDP
24133+BEGIN(sub_unchecked)
24134+ subl %eax, (v)
24135+ sbbl %edx, 4(v)
24136 RET_ENDP
24137 #undef v
24138
24139@@ -96,6 +150,27 @@ BEGIN(sub_return)
24140 sbbl $0, %edx
24141 addl (v), %eax
24142 adcl 4(v), %edx
24143+
24144+#ifdef CONFIG_PAX_REFCOUNT
24145+ into
24146+1234:
24147+ _ASM_EXTABLE(1234b, 2f)
24148+#endif
24149+
24150+ movl %eax, (v)
24151+ movl %edx, 4(v)
24152+
24153+#ifdef CONFIG_PAX_REFCOUNT
24154+2:
24155+#endif
24156+
24157+RET_ENDP
24158+BEGIN(sub_return_unchecked)
24159+ negl %edx
24160+ negl %eax
24161+ sbbl $0, %edx
24162+ addl (v), %eax
24163+ adcl 4(v), %edx
24164 movl %eax, (v)
24165 movl %edx, 4(v)
24166 RET_ENDP
24167@@ -105,6 +180,20 @@ RET_ENDP
24168 BEGIN(inc)
24169 addl $1, (v)
24170 adcl $0, 4(v)
24171+
24172+#ifdef CONFIG_PAX_REFCOUNT
24173+ jno 0f
24174+ subl $1, (v)
24175+ sbbl $0, 4(v)
24176+ int $4
24177+0:
24178+ _ASM_EXTABLE(0b, 0b)
24179+#endif
24180+
24181+RET_ENDP
24182+BEGIN(inc_unchecked)
24183+ addl $1, (v)
24184+ adcl $0, 4(v)
24185 RET_ENDP
24186 #undef v
24187
24188@@ -114,6 +203,26 @@ BEGIN(inc_return)
24189 movl 4(v), %edx
24190 addl $1, %eax
24191 adcl $0, %edx
24192+
24193+#ifdef CONFIG_PAX_REFCOUNT
24194+ into
24195+1234:
24196+ _ASM_EXTABLE(1234b, 2f)
24197+#endif
24198+
24199+ movl %eax, (v)
24200+ movl %edx, 4(v)
24201+
24202+#ifdef CONFIG_PAX_REFCOUNT
24203+2:
24204+#endif
24205+
24206+RET_ENDP
24207+BEGIN(inc_return_unchecked)
24208+ movl (v), %eax
24209+ movl 4(v), %edx
24210+ addl $1, %eax
24211+ adcl $0, %edx
24212 movl %eax, (v)
24213 movl %edx, 4(v)
24214 RET_ENDP
24215@@ -123,6 +232,20 @@ RET_ENDP
24216 BEGIN(dec)
24217 subl $1, (v)
24218 sbbl $0, 4(v)
24219+
24220+#ifdef CONFIG_PAX_REFCOUNT
24221+ jno 0f
24222+ addl $1, (v)
24223+ adcl $0, 4(v)
24224+ int $4
24225+0:
24226+ _ASM_EXTABLE(0b, 0b)
24227+#endif
24228+
24229+RET_ENDP
24230+BEGIN(dec_unchecked)
24231+ subl $1, (v)
24232+ sbbl $0, 4(v)
24233 RET_ENDP
24234 #undef v
24235
24236@@ -132,6 +255,26 @@ BEGIN(dec_return)
24237 movl 4(v), %edx
24238 subl $1, %eax
24239 sbbl $0, %edx
24240+
24241+#ifdef CONFIG_PAX_REFCOUNT
24242+ into
24243+1234:
24244+ _ASM_EXTABLE(1234b, 2f)
24245+#endif
24246+
24247+ movl %eax, (v)
24248+ movl %edx, 4(v)
24249+
24250+#ifdef CONFIG_PAX_REFCOUNT
24251+2:
24252+#endif
24253+
24254+RET_ENDP
24255+BEGIN(dec_return_unchecked)
24256+ movl (v), %eax
24257+ movl 4(v), %edx
24258+ subl $1, %eax
24259+ sbbl $0, %edx
24260 movl %eax, (v)
24261 movl %edx, 4(v)
24262 RET_ENDP
24263@@ -143,6 +286,13 @@ BEGIN(add_unless)
24264 adcl %edx, %edi
24265 addl (v), %eax
24266 adcl 4(v), %edx
24267+
24268+#ifdef CONFIG_PAX_REFCOUNT
24269+ into
24270+1234:
24271+ _ASM_EXTABLE(1234b, 2f)
24272+#endif
24273+
24274 cmpl %eax, %ecx
24275 je 3f
24276 1:
24277@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24278 1:
24279 addl $1, %eax
24280 adcl $0, %edx
24281+
24282+#ifdef CONFIG_PAX_REFCOUNT
24283+ into
24284+1234:
24285+ _ASM_EXTABLE(1234b, 2f)
24286+#endif
24287+
24288 movl %eax, (v)
24289 movl %edx, 4(v)
24290 movl $1, %eax
24291@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24292 movl 4(v), %edx
24293 subl $1, %eax
24294 sbbl $0, %edx
24295+
24296+#ifdef CONFIG_PAX_REFCOUNT
24297+ into
24298+1234:
24299+ _ASM_EXTABLE(1234b, 1f)
24300+#endif
24301+
24302 js 1f
24303 movl %eax, (v)
24304 movl %edx, 4(v)
24305diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24306index f5cc9eb..51fa319 100644
24307--- a/arch/x86/lib/atomic64_cx8_32.S
24308+++ b/arch/x86/lib/atomic64_cx8_32.S
24309@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24310 CFI_STARTPROC
24311
24312 read64 %ecx
24313+ pax_force_retaddr
24314 ret
24315 CFI_ENDPROC
24316 ENDPROC(atomic64_read_cx8)
24317
24318+ENTRY(atomic64_read_unchecked_cx8)
24319+ CFI_STARTPROC
24320+
24321+ read64 %ecx
24322+ pax_force_retaddr
24323+ ret
24324+ CFI_ENDPROC
24325+ENDPROC(atomic64_read_unchecked_cx8)
24326+
24327 ENTRY(atomic64_set_cx8)
24328 CFI_STARTPROC
24329
24330@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24331 cmpxchg8b (%esi)
24332 jne 1b
24333
24334+ pax_force_retaddr
24335 ret
24336 CFI_ENDPROC
24337 ENDPROC(atomic64_set_cx8)
24338
24339+ENTRY(atomic64_set_unchecked_cx8)
24340+ CFI_STARTPROC
24341+
24342+1:
24343+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24344+ * are atomic on 586 and newer */
24345+ cmpxchg8b (%esi)
24346+ jne 1b
24347+
24348+ pax_force_retaddr
24349+ ret
24350+ CFI_ENDPROC
24351+ENDPROC(atomic64_set_unchecked_cx8)
24352+
24353 ENTRY(atomic64_xchg_cx8)
24354 CFI_STARTPROC
24355
24356@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24357 cmpxchg8b (%esi)
24358 jne 1b
24359
24360+ pax_force_retaddr
24361 ret
24362 CFI_ENDPROC
24363 ENDPROC(atomic64_xchg_cx8)
24364
24365-.macro addsub_return func ins insc
24366-ENTRY(atomic64_\func\()_return_cx8)
24367+.macro addsub_return func ins insc unchecked=""
24368+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24369 CFI_STARTPROC
24370 SAVE ebp
24371 SAVE ebx
24372@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24373 movl %edx, %ecx
24374 \ins\()l %esi, %ebx
24375 \insc\()l %edi, %ecx
24376+
24377+.ifb \unchecked
24378+#ifdef CONFIG_PAX_REFCOUNT
24379+ into
24380+2:
24381+ _ASM_EXTABLE(2b, 3f)
24382+#endif
24383+.endif
24384+
24385 LOCK_PREFIX
24386 cmpxchg8b (%ebp)
24387 jne 1b
24388-
24389-10:
24390 movl %ebx, %eax
24391 movl %ecx, %edx
24392+
24393+.ifb \unchecked
24394+#ifdef CONFIG_PAX_REFCOUNT
24395+3:
24396+#endif
24397+.endif
24398+
24399 RESTORE edi
24400 RESTORE esi
24401 RESTORE ebx
24402 RESTORE ebp
24403+ pax_force_retaddr
24404 ret
24405 CFI_ENDPROC
24406-ENDPROC(atomic64_\func\()_return_cx8)
24407+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24408 .endm
24409
24410 addsub_return add add adc
24411 addsub_return sub sub sbb
24412+addsub_return add add adc _unchecked
24413+addsub_return sub sub sbb _unchecked
24414
24415-.macro incdec_return func ins insc
24416-ENTRY(atomic64_\func\()_return_cx8)
24417+.macro incdec_return func ins insc unchecked=""
24418+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24419 CFI_STARTPROC
24420 SAVE ebx
24421
24422@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24423 movl %edx, %ecx
24424 \ins\()l $1, %ebx
24425 \insc\()l $0, %ecx
24426+
24427+.ifb \unchecked
24428+#ifdef CONFIG_PAX_REFCOUNT
24429+ into
24430+2:
24431+ _ASM_EXTABLE(2b, 3f)
24432+#endif
24433+.endif
24434+
24435 LOCK_PREFIX
24436 cmpxchg8b (%esi)
24437 jne 1b
24438
24439-10:
24440 movl %ebx, %eax
24441 movl %ecx, %edx
24442+
24443+.ifb \unchecked
24444+#ifdef CONFIG_PAX_REFCOUNT
24445+3:
24446+#endif
24447+.endif
24448+
24449 RESTORE ebx
24450+ pax_force_retaddr
24451 ret
24452 CFI_ENDPROC
24453-ENDPROC(atomic64_\func\()_return_cx8)
24454+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24455 .endm
24456
24457 incdec_return inc add adc
24458 incdec_return dec sub sbb
24459+incdec_return inc add adc _unchecked
24460+incdec_return dec sub sbb _unchecked
24461
24462 ENTRY(atomic64_dec_if_positive_cx8)
24463 CFI_STARTPROC
24464@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24465 movl %edx, %ecx
24466 subl $1, %ebx
24467 sbb $0, %ecx
24468+
24469+#ifdef CONFIG_PAX_REFCOUNT
24470+ into
24471+1234:
24472+ _ASM_EXTABLE(1234b, 2f)
24473+#endif
24474+
24475 js 2f
24476 LOCK_PREFIX
24477 cmpxchg8b (%esi)
24478@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24479 movl %ebx, %eax
24480 movl %ecx, %edx
24481 RESTORE ebx
24482+ pax_force_retaddr
24483 ret
24484 CFI_ENDPROC
24485 ENDPROC(atomic64_dec_if_positive_cx8)
24486@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24487 movl %edx, %ecx
24488 addl %ebp, %ebx
24489 adcl %edi, %ecx
24490+
24491+#ifdef CONFIG_PAX_REFCOUNT
24492+ into
24493+1234:
24494+ _ASM_EXTABLE(1234b, 3f)
24495+#endif
24496+
24497 LOCK_PREFIX
24498 cmpxchg8b (%esi)
24499 jne 1b
24500@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24501 CFI_ADJUST_CFA_OFFSET -8
24502 RESTORE ebx
24503 RESTORE ebp
24504+ pax_force_retaddr
24505 ret
24506 4:
24507 cmpl %edx, 4(%esp)
24508@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24509 xorl %ecx, %ecx
24510 addl $1, %ebx
24511 adcl %edx, %ecx
24512+
24513+#ifdef CONFIG_PAX_REFCOUNT
24514+ into
24515+1234:
24516+ _ASM_EXTABLE(1234b, 3f)
24517+#endif
24518+
24519 LOCK_PREFIX
24520 cmpxchg8b (%esi)
24521 jne 1b
24522@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24523 movl $1, %eax
24524 3:
24525 RESTORE ebx
24526+ pax_force_retaddr
24527 ret
24528 CFI_ENDPROC
24529 ENDPROC(atomic64_inc_not_zero_cx8)
24530diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24531index 2af5df3..62b1a5a 100644
24532--- a/arch/x86/lib/checksum_32.S
24533+++ b/arch/x86/lib/checksum_32.S
24534@@ -29,7 +29,8 @@
24535 #include <asm/dwarf2.h>
24536 #include <asm/errno.h>
24537 #include <asm/asm.h>
24538-
24539+#include <asm/segment.h>
24540+
24541 /*
24542 * computes a partial checksum, e.g. for TCP/UDP fragments
24543 */
24544@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24545
24546 #define ARGBASE 16
24547 #define FP 12
24548-
24549-ENTRY(csum_partial_copy_generic)
24550+
24551+ENTRY(csum_partial_copy_generic_to_user)
24552 CFI_STARTPROC
24553+
24554+#ifdef CONFIG_PAX_MEMORY_UDEREF
24555+ pushl_cfi %gs
24556+ popl_cfi %es
24557+ jmp csum_partial_copy_generic
24558+#endif
24559+
24560+ENTRY(csum_partial_copy_generic_from_user)
24561+
24562+#ifdef CONFIG_PAX_MEMORY_UDEREF
24563+ pushl_cfi %gs
24564+ popl_cfi %ds
24565+#endif
24566+
24567+ENTRY(csum_partial_copy_generic)
24568 subl $4,%esp
24569 CFI_ADJUST_CFA_OFFSET 4
24570 pushl_cfi %edi
24571@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24572 jmp 4f
24573 SRC(1: movw (%esi), %bx )
24574 addl $2, %esi
24575-DST( movw %bx, (%edi) )
24576+DST( movw %bx, %es:(%edi) )
24577 addl $2, %edi
24578 addw %bx, %ax
24579 adcl $0, %eax
24580@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24581 SRC(1: movl (%esi), %ebx )
24582 SRC( movl 4(%esi), %edx )
24583 adcl %ebx, %eax
24584-DST( movl %ebx, (%edi) )
24585+DST( movl %ebx, %es:(%edi) )
24586 adcl %edx, %eax
24587-DST( movl %edx, 4(%edi) )
24588+DST( movl %edx, %es:4(%edi) )
24589
24590 SRC( movl 8(%esi), %ebx )
24591 SRC( movl 12(%esi), %edx )
24592 adcl %ebx, %eax
24593-DST( movl %ebx, 8(%edi) )
24594+DST( movl %ebx, %es:8(%edi) )
24595 adcl %edx, %eax
24596-DST( movl %edx, 12(%edi) )
24597+DST( movl %edx, %es:12(%edi) )
24598
24599 SRC( movl 16(%esi), %ebx )
24600 SRC( movl 20(%esi), %edx )
24601 adcl %ebx, %eax
24602-DST( movl %ebx, 16(%edi) )
24603+DST( movl %ebx, %es:16(%edi) )
24604 adcl %edx, %eax
24605-DST( movl %edx, 20(%edi) )
24606+DST( movl %edx, %es:20(%edi) )
24607
24608 SRC( movl 24(%esi), %ebx )
24609 SRC( movl 28(%esi), %edx )
24610 adcl %ebx, %eax
24611-DST( movl %ebx, 24(%edi) )
24612+DST( movl %ebx, %es:24(%edi) )
24613 adcl %edx, %eax
24614-DST( movl %edx, 28(%edi) )
24615+DST( movl %edx, %es:28(%edi) )
24616
24617 lea 32(%esi), %esi
24618 lea 32(%edi), %edi
24619@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24620 shrl $2, %edx # This clears CF
24621 SRC(3: movl (%esi), %ebx )
24622 adcl %ebx, %eax
24623-DST( movl %ebx, (%edi) )
24624+DST( movl %ebx, %es:(%edi) )
24625 lea 4(%esi), %esi
24626 lea 4(%edi), %edi
24627 dec %edx
24628@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24629 jb 5f
24630 SRC( movw (%esi), %cx )
24631 leal 2(%esi), %esi
24632-DST( movw %cx, (%edi) )
24633+DST( movw %cx, %es:(%edi) )
24634 leal 2(%edi), %edi
24635 je 6f
24636 shll $16,%ecx
24637 SRC(5: movb (%esi), %cl )
24638-DST( movb %cl, (%edi) )
24639+DST( movb %cl, %es:(%edi) )
24640 6: addl %ecx, %eax
24641 adcl $0, %eax
24642 7:
24643@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24644
24645 6001:
24646 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24647- movl $-EFAULT, (%ebx)
24648+ movl $-EFAULT, %ss:(%ebx)
24649
24650 # zero the complete destination - computing the rest
24651 # is too much work
24652@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24653
24654 6002:
24655 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24656- movl $-EFAULT,(%ebx)
24657+ movl $-EFAULT,%ss:(%ebx)
24658 jmp 5000b
24659
24660 .previous
24661
24662+ pushl_cfi %ss
24663+ popl_cfi %ds
24664+ pushl_cfi %ss
24665+ popl_cfi %es
24666 popl_cfi %ebx
24667 CFI_RESTORE ebx
24668 popl_cfi %esi
24669@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24670 popl_cfi %ecx # equivalent to addl $4,%esp
24671 ret
24672 CFI_ENDPROC
24673-ENDPROC(csum_partial_copy_generic)
24674+ENDPROC(csum_partial_copy_generic_to_user)
24675
24676 #else
24677
24678 /* Version for PentiumII/PPro */
24679
24680 #define ROUND1(x) \
24681+ nop; nop; nop; \
24682 SRC(movl x(%esi), %ebx ) ; \
24683 addl %ebx, %eax ; \
24684- DST(movl %ebx, x(%edi) ) ;
24685+ DST(movl %ebx, %es:x(%edi)) ;
24686
24687 #define ROUND(x) \
24688+ nop; nop; nop; \
24689 SRC(movl x(%esi), %ebx ) ; \
24690 adcl %ebx, %eax ; \
24691- DST(movl %ebx, x(%edi) ) ;
24692+ DST(movl %ebx, %es:x(%edi)) ;
24693
24694 #define ARGBASE 12
24695-
24696-ENTRY(csum_partial_copy_generic)
24697+
24698+ENTRY(csum_partial_copy_generic_to_user)
24699 CFI_STARTPROC
24700+
24701+#ifdef CONFIG_PAX_MEMORY_UDEREF
24702+ pushl_cfi %gs
24703+ popl_cfi %es
24704+ jmp csum_partial_copy_generic
24705+#endif
24706+
24707+ENTRY(csum_partial_copy_generic_from_user)
24708+
24709+#ifdef CONFIG_PAX_MEMORY_UDEREF
24710+ pushl_cfi %gs
24711+ popl_cfi %ds
24712+#endif
24713+
24714+ENTRY(csum_partial_copy_generic)
24715 pushl_cfi %ebx
24716 CFI_REL_OFFSET ebx, 0
24717 pushl_cfi %edi
24718@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24719 subl %ebx, %edi
24720 lea -1(%esi),%edx
24721 andl $-32,%edx
24722- lea 3f(%ebx,%ebx), %ebx
24723+ lea 3f(%ebx,%ebx,2), %ebx
24724 testl %esi, %esi
24725 jmp *%ebx
24726 1: addl $64,%esi
24727@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24728 jb 5f
24729 SRC( movw (%esi), %dx )
24730 leal 2(%esi), %esi
24731-DST( movw %dx, (%edi) )
24732+DST( movw %dx, %es:(%edi) )
24733 leal 2(%edi), %edi
24734 je 6f
24735 shll $16,%edx
24736 5:
24737 SRC( movb (%esi), %dl )
24738-DST( movb %dl, (%edi) )
24739+DST( movb %dl, %es:(%edi) )
24740 6: addl %edx, %eax
24741 adcl $0, %eax
24742 7:
24743 .section .fixup, "ax"
24744 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24745- movl $-EFAULT, (%ebx)
24746+ movl $-EFAULT, %ss:(%ebx)
24747 # zero the complete destination (computing the rest is too much work)
24748 movl ARGBASE+8(%esp),%edi # dst
24749 movl ARGBASE+12(%esp),%ecx # len
24750@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24751 rep; stosb
24752 jmp 7b
24753 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24754- movl $-EFAULT, (%ebx)
24755+ movl $-EFAULT, %ss:(%ebx)
24756 jmp 7b
24757 .previous
24758
24759+#ifdef CONFIG_PAX_MEMORY_UDEREF
24760+ pushl_cfi %ss
24761+ popl_cfi %ds
24762+ pushl_cfi %ss
24763+ popl_cfi %es
24764+#endif
24765+
24766 popl_cfi %esi
24767 CFI_RESTORE esi
24768 popl_cfi %edi
24769@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24770 CFI_RESTORE ebx
24771 ret
24772 CFI_ENDPROC
24773-ENDPROC(csum_partial_copy_generic)
24774+ENDPROC(csum_partial_copy_generic_to_user)
24775
24776 #undef ROUND
24777 #undef ROUND1
24778diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24779index f2145cf..cea889d 100644
24780--- a/arch/x86/lib/clear_page_64.S
24781+++ b/arch/x86/lib/clear_page_64.S
24782@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24783 movl $4096/8,%ecx
24784 xorl %eax,%eax
24785 rep stosq
24786+ pax_force_retaddr
24787 ret
24788 CFI_ENDPROC
24789 ENDPROC(clear_page_c)
24790@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24791 movl $4096,%ecx
24792 xorl %eax,%eax
24793 rep stosb
24794+ pax_force_retaddr
24795 ret
24796 CFI_ENDPROC
24797 ENDPROC(clear_page_c_e)
24798@@ -43,6 +45,7 @@ ENTRY(clear_page)
24799 leaq 64(%rdi),%rdi
24800 jnz .Lloop
24801 nop
24802+ pax_force_retaddr
24803 ret
24804 CFI_ENDPROC
24805 .Lclear_page_end:
24806@@ -58,7 +61,7 @@ ENDPROC(clear_page)
24807
24808 #include <asm/cpufeature.h>
24809
24810- .section .altinstr_replacement,"ax"
24811+ .section .altinstr_replacement,"a"
24812 1: .byte 0xeb /* jmp <disp8> */
24813 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24814 2: .byte 0xeb /* jmp <disp8> */
24815diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24816index 1e572c5..2a162cd 100644
24817--- a/arch/x86/lib/cmpxchg16b_emu.S
24818+++ b/arch/x86/lib/cmpxchg16b_emu.S
24819@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24820
24821 popf
24822 mov $1, %al
24823+ pax_force_retaddr
24824 ret
24825
24826 not_same:
24827 popf
24828 xor %al,%al
24829+ pax_force_retaddr
24830 ret
24831
24832 CFI_ENDPROC
24833diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24834index 176cca6..1166c50 100644
24835--- a/arch/x86/lib/copy_page_64.S
24836+++ b/arch/x86/lib/copy_page_64.S
24837@@ -9,6 +9,7 @@ copy_page_rep:
24838 CFI_STARTPROC
24839 movl $4096/8, %ecx
24840 rep movsq
24841+ pax_force_retaddr
24842 ret
24843 CFI_ENDPROC
24844 ENDPROC(copy_page_rep)
24845@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24846
24847 ENTRY(copy_page)
24848 CFI_STARTPROC
24849- subq $2*8, %rsp
24850- CFI_ADJUST_CFA_OFFSET 2*8
24851+ subq $3*8, %rsp
24852+ CFI_ADJUST_CFA_OFFSET 3*8
24853 movq %rbx, (%rsp)
24854 CFI_REL_OFFSET rbx, 0
24855 movq %r12, 1*8(%rsp)
24856 CFI_REL_OFFSET r12, 1*8
24857+ movq %r13, 2*8(%rsp)
24858+ CFI_REL_OFFSET r13, 2*8
24859
24860 movl $(4096/64)-5, %ecx
24861 .p2align 4
24862@@ -36,7 +39,7 @@ ENTRY(copy_page)
24863 movq 0x8*2(%rsi), %rdx
24864 movq 0x8*3(%rsi), %r8
24865 movq 0x8*4(%rsi), %r9
24866- movq 0x8*5(%rsi), %r10
24867+ movq 0x8*5(%rsi), %r13
24868 movq 0x8*6(%rsi), %r11
24869 movq 0x8*7(%rsi), %r12
24870
24871@@ -47,7 +50,7 @@ ENTRY(copy_page)
24872 movq %rdx, 0x8*2(%rdi)
24873 movq %r8, 0x8*3(%rdi)
24874 movq %r9, 0x8*4(%rdi)
24875- movq %r10, 0x8*5(%rdi)
24876+ movq %r13, 0x8*5(%rdi)
24877 movq %r11, 0x8*6(%rdi)
24878 movq %r12, 0x8*7(%rdi)
24879
24880@@ -66,7 +69,7 @@ ENTRY(copy_page)
24881 movq 0x8*2(%rsi), %rdx
24882 movq 0x8*3(%rsi), %r8
24883 movq 0x8*4(%rsi), %r9
24884- movq 0x8*5(%rsi), %r10
24885+ movq 0x8*5(%rsi), %r13
24886 movq 0x8*6(%rsi), %r11
24887 movq 0x8*7(%rsi), %r12
24888
24889@@ -75,7 +78,7 @@ ENTRY(copy_page)
24890 movq %rdx, 0x8*2(%rdi)
24891 movq %r8, 0x8*3(%rdi)
24892 movq %r9, 0x8*4(%rdi)
24893- movq %r10, 0x8*5(%rdi)
24894+ movq %r13, 0x8*5(%rdi)
24895 movq %r11, 0x8*6(%rdi)
24896 movq %r12, 0x8*7(%rdi)
24897
24898@@ -87,8 +90,11 @@ ENTRY(copy_page)
24899 CFI_RESTORE rbx
24900 movq 1*8(%rsp), %r12
24901 CFI_RESTORE r12
24902- addq $2*8, %rsp
24903- CFI_ADJUST_CFA_OFFSET -2*8
24904+ movq 2*8(%rsp), %r13
24905+ CFI_RESTORE r13
24906+ addq $3*8, %rsp
24907+ CFI_ADJUST_CFA_OFFSET -3*8
24908+ pax_force_retaddr
24909 ret
24910 .Lcopy_page_end:
24911 CFI_ENDPROC
24912@@ -99,7 +105,7 @@ ENDPROC(copy_page)
24913
24914 #include <asm/cpufeature.h>
24915
24916- .section .altinstr_replacement,"ax"
24917+ .section .altinstr_replacement,"a"
24918 1: .byte 0xeb /* jmp <disp8> */
24919 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
24920 2:
24921diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
24922index a30ca15..d25fab6 100644
24923--- a/arch/x86/lib/copy_user_64.S
24924+++ b/arch/x86/lib/copy_user_64.S
24925@@ -18,6 +18,7 @@
24926 #include <asm/alternative-asm.h>
24927 #include <asm/asm.h>
24928 #include <asm/smap.h>
24929+#include <asm/pgtable.h>
24930
24931 /*
24932 * By placing feature2 after feature1 in altinstructions section, we logically
24933@@ -31,7 +32,7 @@
24934 .byte 0xe9 /* 32bit jump */
24935 .long \orig-1f /* by default jump to orig */
24936 1:
24937- .section .altinstr_replacement,"ax"
24938+ .section .altinstr_replacement,"a"
24939 2: .byte 0xe9 /* near jump with 32bit immediate */
24940 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
24941 3: .byte 0xe9 /* near jump with 32bit immediate */
24942@@ -70,47 +71,20 @@
24943 #endif
24944 .endm
24945
24946-/* Standard copy_to_user with segment limit checking */
24947-ENTRY(_copy_to_user)
24948- CFI_STARTPROC
24949- GET_THREAD_INFO(%rax)
24950- movq %rdi,%rcx
24951- addq %rdx,%rcx
24952- jc bad_to_user
24953- cmpq TI_addr_limit(%rax),%rcx
24954- ja bad_to_user
24955- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24956- copy_user_generic_unrolled,copy_user_generic_string, \
24957- copy_user_enhanced_fast_string
24958- CFI_ENDPROC
24959-ENDPROC(_copy_to_user)
24960-
24961-/* Standard copy_from_user with segment limit checking */
24962-ENTRY(_copy_from_user)
24963- CFI_STARTPROC
24964- GET_THREAD_INFO(%rax)
24965- movq %rsi,%rcx
24966- addq %rdx,%rcx
24967- jc bad_from_user
24968- cmpq TI_addr_limit(%rax),%rcx
24969- ja bad_from_user
24970- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24971- copy_user_generic_unrolled,copy_user_generic_string, \
24972- copy_user_enhanced_fast_string
24973- CFI_ENDPROC
24974-ENDPROC(_copy_from_user)
24975-
24976 .section .fixup,"ax"
24977 /* must zero dest */
24978 ENTRY(bad_from_user)
24979 bad_from_user:
24980 CFI_STARTPROC
24981+ testl %edx,%edx
24982+ js bad_to_user
24983 movl %edx,%ecx
24984 xorl %eax,%eax
24985 rep
24986 stosb
24987 bad_to_user:
24988 movl %edx,%eax
24989+ pax_force_retaddr
24990 ret
24991 CFI_ENDPROC
24992 ENDPROC(bad_from_user)
24993@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
24994 jz 17f
24995 1: movq (%rsi),%r8
24996 2: movq 1*8(%rsi),%r9
24997-3: movq 2*8(%rsi),%r10
24998+3: movq 2*8(%rsi),%rax
24999 4: movq 3*8(%rsi),%r11
25000 5: movq %r8,(%rdi)
25001 6: movq %r9,1*8(%rdi)
25002-7: movq %r10,2*8(%rdi)
25003+7: movq %rax,2*8(%rdi)
25004 8: movq %r11,3*8(%rdi)
25005 9: movq 4*8(%rsi),%r8
25006 10: movq 5*8(%rsi),%r9
25007-11: movq 6*8(%rsi),%r10
25008+11: movq 6*8(%rsi),%rax
25009 12: movq 7*8(%rsi),%r11
25010 13: movq %r8,4*8(%rdi)
25011 14: movq %r9,5*8(%rdi)
25012-15: movq %r10,6*8(%rdi)
25013+15: movq %rax,6*8(%rdi)
25014 16: movq %r11,7*8(%rdi)
25015 leaq 64(%rsi),%rsi
25016 leaq 64(%rdi),%rdi
25017@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25018 jnz 21b
25019 23: xor %eax,%eax
25020 ASM_CLAC
25021+ pax_force_retaddr
25022 ret
25023
25024 .section .fixup,"ax"
25025@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25026 movsb
25027 4: xorl %eax,%eax
25028 ASM_CLAC
25029+ pax_force_retaddr
25030 ret
25031
25032 .section .fixup,"ax"
25033@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25034 movsb
25035 2: xorl %eax,%eax
25036 ASM_CLAC
25037+ pax_force_retaddr
25038 ret
25039
25040 .section .fixup,"ax"
25041diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25042index 6a4f43c..f5f9e26 100644
25043--- a/arch/x86/lib/copy_user_nocache_64.S
25044+++ b/arch/x86/lib/copy_user_nocache_64.S
25045@@ -8,6 +8,7 @@
25046
25047 #include <linux/linkage.h>
25048 #include <asm/dwarf2.h>
25049+#include <asm/alternative-asm.h>
25050
25051 #define FIX_ALIGNMENT 1
25052
25053@@ -16,6 +17,7 @@
25054 #include <asm/thread_info.h>
25055 #include <asm/asm.h>
25056 #include <asm/smap.h>
25057+#include <asm/pgtable.h>
25058
25059 .macro ALIGN_DESTINATION
25060 #ifdef FIX_ALIGNMENT
25061@@ -49,6 +51,15 @@
25062 */
25063 ENTRY(__copy_user_nocache)
25064 CFI_STARTPROC
25065+
25066+#ifdef CONFIG_PAX_MEMORY_UDEREF
25067+ mov $PAX_USER_SHADOW_BASE,%rcx
25068+ cmp %rcx,%rsi
25069+ jae 1f
25070+ add %rcx,%rsi
25071+1:
25072+#endif
25073+
25074 ASM_STAC
25075 cmpl $8,%edx
25076 jb 20f /* less then 8 bytes, go to byte copy loop */
25077@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25078 jz 17f
25079 1: movq (%rsi),%r8
25080 2: movq 1*8(%rsi),%r9
25081-3: movq 2*8(%rsi),%r10
25082+3: movq 2*8(%rsi),%rax
25083 4: movq 3*8(%rsi),%r11
25084 5: movnti %r8,(%rdi)
25085 6: movnti %r9,1*8(%rdi)
25086-7: movnti %r10,2*8(%rdi)
25087+7: movnti %rax,2*8(%rdi)
25088 8: movnti %r11,3*8(%rdi)
25089 9: movq 4*8(%rsi),%r8
25090 10: movq 5*8(%rsi),%r9
25091-11: movq 6*8(%rsi),%r10
25092+11: movq 6*8(%rsi),%rax
25093 12: movq 7*8(%rsi),%r11
25094 13: movnti %r8,4*8(%rdi)
25095 14: movnti %r9,5*8(%rdi)
25096-15: movnti %r10,6*8(%rdi)
25097+15: movnti %rax,6*8(%rdi)
25098 16: movnti %r11,7*8(%rdi)
25099 leaq 64(%rsi),%rsi
25100 leaq 64(%rdi),%rdi
25101@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25102 23: xorl %eax,%eax
25103 ASM_CLAC
25104 sfence
25105+ pax_force_retaddr
25106 ret
25107
25108 .section .fixup,"ax"
25109diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25110index 2419d5f..953ee51 100644
25111--- a/arch/x86/lib/csum-copy_64.S
25112+++ b/arch/x86/lib/csum-copy_64.S
25113@@ -9,6 +9,7 @@
25114 #include <asm/dwarf2.h>
25115 #include <asm/errno.h>
25116 #include <asm/asm.h>
25117+#include <asm/alternative-asm.h>
25118
25119 /*
25120 * Checksum copy with exception handling.
25121@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25122 CFI_RESTORE rbp
25123 addq $7*8, %rsp
25124 CFI_ADJUST_CFA_OFFSET -7*8
25125+ pax_force_retaddr 0, 1
25126 ret
25127 CFI_RESTORE_STATE
25128
25129diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25130index 25b7ae8..169fafc 100644
25131--- a/arch/x86/lib/csum-wrappers_64.c
25132+++ b/arch/x86/lib/csum-wrappers_64.c
25133@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25134 len -= 2;
25135 }
25136 }
25137- isum = csum_partial_copy_generic((__force const void *)src,
25138+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25139 dst, len, isum, errp, NULL);
25140 if (unlikely(*errp))
25141 goto out_err;
25142@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25143 }
25144
25145 *errp = 0;
25146- return csum_partial_copy_generic(src, (void __force *)dst,
25147+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25148 len, isum, NULL, errp);
25149 }
25150 EXPORT_SYMBOL(csum_partial_copy_to_user);
25151diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25152index 156b9c8..b144132 100644
25153--- a/arch/x86/lib/getuser.S
25154+++ b/arch/x86/lib/getuser.S
25155@@ -34,17 +34,40 @@
25156 #include <asm/thread_info.h>
25157 #include <asm/asm.h>
25158 #include <asm/smap.h>
25159+#include <asm/segment.h>
25160+#include <asm/pgtable.h>
25161+#include <asm/alternative-asm.h>
25162+
25163+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25164+#define __copyuser_seg gs;
25165+#else
25166+#define __copyuser_seg
25167+#endif
25168
25169 .text
25170 ENTRY(__get_user_1)
25171 CFI_STARTPROC
25172+
25173+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25174 GET_THREAD_INFO(%_ASM_DX)
25175 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25176 jae bad_get_user
25177 ASM_STAC
25178-1: movzb (%_ASM_AX),%edx
25179+
25180+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25181+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25182+ cmp %_ASM_DX,%_ASM_AX
25183+ jae 1234f
25184+ add %_ASM_DX,%_ASM_AX
25185+1234:
25186+#endif
25187+
25188+#endif
25189+
25190+1: __copyuser_seg movzb (%_ASM_AX),%edx
25191 xor %eax,%eax
25192 ASM_CLAC
25193+ pax_force_retaddr
25194 ret
25195 CFI_ENDPROC
25196 ENDPROC(__get_user_1)
25197@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
25198 ENTRY(__get_user_2)
25199 CFI_STARTPROC
25200 add $1,%_ASM_AX
25201+
25202+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25203 jc bad_get_user
25204 GET_THREAD_INFO(%_ASM_DX)
25205 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25206 jae bad_get_user
25207 ASM_STAC
25208-2: movzwl -1(%_ASM_AX),%edx
25209+
25210+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25211+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25212+ cmp %_ASM_DX,%_ASM_AX
25213+ jae 1234f
25214+ add %_ASM_DX,%_ASM_AX
25215+1234:
25216+#endif
25217+
25218+#endif
25219+
25220+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25221 xor %eax,%eax
25222 ASM_CLAC
25223+ pax_force_retaddr
25224 ret
25225 CFI_ENDPROC
25226 ENDPROC(__get_user_2)
25227@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
25228 ENTRY(__get_user_4)
25229 CFI_STARTPROC
25230 add $3,%_ASM_AX
25231+
25232+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25233 jc bad_get_user
25234 GET_THREAD_INFO(%_ASM_DX)
25235 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25236 jae bad_get_user
25237 ASM_STAC
25238-3: mov -3(%_ASM_AX),%edx
25239+
25240+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25241+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25242+ cmp %_ASM_DX,%_ASM_AX
25243+ jae 1234f
25244+ add %_ASM_DX,%_ASM_AX
25245+1234:
25246+#endif
25247+
25248+#endif
25249+
25250+3: __copyuser_seg mov -3(%_ASM_AX),%edx
25251 xor %eax,%eax
25252 ASM_CLAC
25253+ pax_force_retaddr
25254 ret
25255 CFI_ENDPROC
25256 ENDPROC(__get_user_4)
25257@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
25258 GET_THREAD_INFO(%_ASM_DX)
25259 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25260 jae bad_get_user
25261+
25262+#ifdef CONFIG_PAX_MEMORY_UDEREF
25263+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25264+ cmp %_ASM_DX,%_ASM_AX
25265+ jae 1234f
25266+ add %_ASM_DX,%_ASM_AX
25267+1234:
25268+#endif
25269+
25270 ASM_STAC
25271 4: movq -7(%_ASM_AX),%_ASM_DX
25272 xor %eax,%eax
25273 ASM_CLAC
25274+ pax_force_retaddr
25275 ret
25276 CFI_ENDPROC
25277 ENDPROC(__get_user_8)
25278@@ -101,6 +162,7 @@ bad_get_user:
25279 xor %edx,%edx
25280 mov $(-EFAULT),%_ASM_AX
25281 ASM_CLAC
25282+ pax_force_retaddr
25283 ret
25284 CFI_ENDPROC
25285 END(bad_get_user)
25286diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25287index 54fcffe..7be149e 100644
25288--- a/arch/x86/lib/insn.c
25289+++ b/arch/x86/lib/insn.c
25290@@ -20,8 +20,10 @@
25291
25292 #ifdef __KERNEL__
25293 #include <linux/string.h>
25294+#include <asm/pgtable_types.h>
25295 #else
25296 #include <string.h>
25297+#define ktla_ktva(addr) addr
25298 #endif
25299 #include <asm/inat.h>
25300 #include <asm/insn.h>
25301@@ -53,8 +55,8 @@
25302 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25303 {
25304 memset(insn, 0, sizeof(*insn));
25305- insn->kaddr = kaddr;
25306- insn->next_byte = kaddr;
25307+ insn->kaddr = ktla_ktva(kaddr);
25308+ insn->next_byte = ktla_ktva(kaddr);
25309 insn->x86_64 = x86_64 ? 1 : 0;
25310 insn->opnd_bytes = 4;
25311 if (x86_64)
25312diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25313index 05a95e7..326f2fa 100644
25314--- a/arch/x86/lib/iomap_copy_64.S
25315+++ b/arch/x86/lib/iomap_copy_64.S
25316@@ -17,6 +17,7 @@
25317
25318 #include <linux/linkage.h>
25319 #include <asm/dwarf2.h>
25320+#include <asm/alternative-asm.h>
25321
25322 /*
25323 * override generic version in lib/iomap_copy.c
25324@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25325 CFI_STARTPROC
25326 movl %edx,%ecx
25327 rep movsd
25328+ pax_force_retaddr
25329 ret
25330 CFI_ENDPROC
25331 ENDPROC(__iowrite32_copy)
25332diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25333index 1c273be..da9cc0e 100644
25334--- a/arch/x86/lib/memcpy_64.S
25335+++ b/arch/x86/lib/memcpy_64.S
25336@@ -33,6 +33,7 @@
25337 rep movsq
25338 movl %edx, %ecx
25339 rep movsb
25340+ pax_force_retaddr
25341 ret
25342 .Lmemcpy_e:
25343 .previous
25344@@ -49,6 +50,7 @@
25345 movq %rdi, %rax
25346 movq %rdx, %rcx
25347 rep movsb
25348+ pax_force_retaddr
25349 ret
25350 .Lmemcpy_e_e:
25351 .previous
25352@@ -76,13 +78,13 @@ ENTRY(memcpy)
25353 */
25354 movq 0*8(%rsi), %r8
25355 movq 1*8(%rsi), %r9
25356- movq 2*8(%rsi), %r10
25357+ movq 2*8(%rsi), %rcx
25358 movq 3*8(%rsi), %r11
25359 leaq 4*8(%rsi), %rsi
25360
25361 movq %r8, 0*8(%rdi)
25362 movq %r9, 1*8(%rdi)
25363- movq %r10, 2*8(%rdi)
25364+ movq %rcx, 2*8(%rdi)
25365 movq %r11, 3*8(%rdi)
25366 leaq 4*8(%rdi), %rdi
25367 jae .Lcopy_forward_loop
25368@@ -105,12 +107,12 @@ ENTRY(memcpy)
25369 subq $0x20, %rdx
25370 movq -1*8(%rsi), %r8
25371 movq -2*8(%rsi), %r9
25372- movq -3*8(%rsi), %r10
25373+ movq -3*8(%rsi), %rcx
25374 movq -4*8(%rsi), %r11
25375 leaq -4*8(%rsi), %rsi
25376 movq %r8, -1*8(%rdi)
25377 movq %r9, -2*8(%rdi)
25378- movq %r10, -3*8(%rdi)
25379+ movq %rcx, -3*8(%rdi)
25380 movq %r11, -4*8(%rdi)
25381 leaq -4*8(%rdi), %rdi
25382 jae .Lcopy_backward_loop
25383@@ -130,12 +132,13 @@ ENTRY(memcpy)
25384 */
25385 movq 0*8(%rsi), %r8
25386 movq 1*8(%rsi), %r9
25387- movq -2*8(%rsi, %rdx), %r10
25388+ movq -2*8(%rsi, %rdx), %rcx
25389 movq -1*8(%rsi, %rdx), %r11
25390 movq %r8, 0*8(%rdi)
25391 movq %r9, 1*8(%rdi)
25392- movq %r10, -2*8(%rdi, %rdx)
25393+ movq %rcx, -2*8(%rdi, %rdx)
25394 movq %r11, -1*8(%rdi, %rdx)
25395+ pax_force_retaddr
25396 retq
25397 .p2align 4
25398 .Lless_16bytes:
25399@@ -148,6 +151,7 @@ ENTRY(memcpy)
25400 movq -1*8(%rsi, %rdx), %r9
25401 movq %r8, 0*8(%rdi)
25402 movq %r9, -1*8(%rdi, %rdx)
25403+ pax_force_retaddr
25404 retq
25405 .p2align 4
25406 .Lless_8bytes:
25407@@ -161,6 +165,7 @@ ENTRY(memcpy)
25408 movl -4(%rsi, %rdx), %r8d
25409 movl %ecx, (%rdi)
25410 movl %r8d, -4(%rdi, %rdx)
25411+ pax_force_retaddr
25412 retq
25413 .p2align 4
25414 .Lless_3bytes:
25415@@ -179,6 +184,7 @@ ENTRY(memcpy)
25416 movb %cl, (%rdi)
25417
25418 .Lend:
25419+ pax_force_retaddr
25420 retq
25421 CFI_ENDPROC
25422 ENDPROC(memcpy)
25423diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25424index ee16461..c39c199 100644
25425--- a/arch/x86/lib/memmove_64.S
25426+++ b/arch/x86/lib/memmove_64.S
25427@@ -61,13 +61,13 @@ ENTRY(memmove)
25428 5:
25429 sub $0x20, %rdx
25430 movq 0*8(%rsi), %r11
25431- movq 1*8(%rsi), %r10
25432+ movq 1*8(%rsi), %rcx
25433 movq 2*8(%rsi), %r9
25434 movq 3*8(%rsi), %r8
25435 leaq 4*8(%rsi), %rsi
25436
25437 movq %r11, 0*8(%rdi)
25438- movq %r10, 1*8(%rdi)
25439+ movq %rcx, 1*8(%rdi)
25440 movq %r9, 2*8(%rdi)
25441 movq %r8, 3*8(%rdi)
25442 leaq 4*8(%rdi), %rdi
25443@@ -81,10 +81,10 @@ ENTRY(memmove)
25444 4:
25445 movq %rdx, %rcx
25446 movq -8(%rsi, %rdx), %r11
25447- lea -8(%rdi, %rdx), %r10
25448+ lea -8(%rdi, %rdx), %r9
25449 shrq $3, %rcx
25450 rep movsq
25451- movq %r11, (%r10)
25452+ movq %r11, (%r9)
25453 jmp 13f
25454 .Lmemmove_end_forward:
25455
25456@@ -95,14 +95,14 @@ ENTRY(memmove)
25457 7:
25458 movq %rdx, %rcx
25459 movq (%rsi), %r11
25460- movq %rdi, %r10
25461+ movq %rdi, %r9
25462 leaq -8(%rsi, %rdx), %rsi
25463 leaq -8(%rdi, %rdx), %rdi
25464 shrq $3, %rcx
25465 std
25466 rep movsq
25467 cld
25468- movq %r11, (%r10)
25469+ movq %r11, (%r9)
25470 jmp 13f
25471
25472 /*
25473@@ -127,13 +127,13 @@ ENTRY(memmove)
25474 8:
25475 subq $0x20, %rdx
25476 movq -1*8(%rsi), %r11
25477- movq -2*8(%rsi), %r10
25478+ movq -2*8(%rsi), %rcx
25479 movq -3*8(%rsi), %r9
25480 movq -4*8(%rsi), %r8
25481 leaq -4*8(%rsi), %rsi
25482
25483 movq %r11, -1*8(%rdi)
25484- movq %r10, -2*8(%rdi)
25485+ movq %rcx, -2*8(%rdi)
25486 movq %r9, -3*8(%rdi)
25487 movq %r8, -4*8(%rdi)
25488 leaq -4*8(%rdi), %rdi
25489@@ -151,11 +151,11 @@ ENTRY(memmove)
25490 * Move data from 16 bytes to 31 bytes.
25491 */
25492 movq 0*8(%rsi), %r11
25493- movq 1*8(%rsi), %r10
25494+ movq 1*8(%rsi), %rcx
25495 movq -2*8(%rsi, %rdx), %r9
25496 movq -1*8(%rsi, %rdx), %r8
25497 movq %r11, 0*8(%rdi)
25498- movq %r10, 1*8(%rdi)
25499+ movq %rcx, 1*8(%rdi)
25500 movq %r9, -2*8(%rdi, %rdx)
25501 movq %r8, -1*8(%rdi, %rdx)
25502 jmp 13f
25503@@ -167,9 +167,9 @@ ENTRY(memmove)
25504 * Move data from 8 bytes to 15 bytes.
25505 */
25506 movq 0*8(%rsi), %r11
25507- movq -1*8(%rsi, %rdx), %r10
25508+ movq -1*8(%rsi, %rdx), %r9
25509 movq %r11, 0*8(%rdi)
25510- movq %r10, -1*8(%rdi, %rdx)
25511+ movq %r9, -1*8(%rdi, %rdx)
25512 jmp 13f
25513 10:
25514 cmpq $4, %rdx
25515@@ -178,9 +178,9 @@ ENTRY(memmove)
25516 * Move data from 4 bytes to 7 bytes.
25517 */
25518 movl (%rsi), %r11d
25519- movl -4(%rsi, %rdx), %r10d
25520+ movl -4(%rsi, %rdx), %r9d
25521 movl %r11d, (%rdi)
25522- movl %r10d, -4(%rdi, %rdx)
25523+ movl %r9d, -4(%rdi, %rdx)
25524 jmp 13f
25525 11:
25526 cmp $2, %rdx
25527@@ -189,9 +189,9 @@ ENTRY(memmove)
25528 * Move data from 2 bytes to 3 bytes.
25529 */
25530 movw (%rsi), %r11w
25531- movw -2(%rsi, %rdx), %r10w
25532+ movw -2(%rsi, %rdx), %r9w
25533 movw %r11w, (%rdi)
25534- movw %r10w, -2(%rdi, %rdx)
25535+ movw %r9w, -2(%rdi, %rdx)
25536 jmp 13f
25537 12:
25538 cmp $1, %rdx
25539@@ -202,6 +202,7 @@ ENTRY(memmove)
25540 movb (%rsi), %r11b
25541 movb %r11b, (%rdi)
25542 13:
25543+ pax_force_retaddr
25544 retq
25545 CFI_ENDPROC
25546
25547@@ -210,6 +211,7 @@ ENTRY(memmove)
25548 /* Forward moving data. */
25549 movq %rdx, %rcx
25550 rep movsb
25551+ pax_force_retaddr
25552 retq
25553 .Lmemmove_end_forward_efs:
25554 .previous
25555diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25556index 2dcb380..963660a 100644
25557--- a/arch/x86/lib/memset_64.S
25558+++ b/arch/x86/lib/memset_64.S
25559@@ -30,6 +30,7 @@
25560 movl %edx,%ecx
25561 rep stosb
25562 movq %r9,%rax
25563+ pax_force_retaddr
25564 ret
25565 .Lmemset_e:
25566 .previous
25567@@ -52,6 +53,7 @@
25568 movq %rdx,%rcx
25569 rep stosb
25570 movq %r9,%rax
25571+ pax_force_retaddr
25572 ret
25573 .Lmemset_e_e:
25574 .previous
25575@@ -59,7 +61,7 @@
25576 ENTRY(memset)
25577 ENTRY(__memset)
25578 CFI_STARTPROC
25579- movq %rdi,%r10
25580+ movq %rdi,%r11
25581
25582 /* expand byte value */
25583 movzbl %sil,%ecx
25584@@ -117,7 +119,8 @@ ENTRY(__memset)
25585 jnz .Lloop_1
25586
25587 .Lende:
25588- movq %r10,%rax
25589+ movq %r11,%rax
25590+ pax_force_retaddr
25591 ret
25592
25593 CFI_RESTORE_STATE
25594diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25595index c9f2d9b..e7fd2c0 100644
25596--- a/arch/x86/lib/mmx_32.c
25597+++ b/arch/x86/lib/mmx_32.c
25598@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25599 {
25600 void *p;
25601 int i;
25602+ unsigned long cr0;
25603
25604 if (unlikely(in_interrupt()))
25605 return __memcpy(to, from, len);
25606@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25607 kernel_fpu_begin();
25608
25609 __asm__ __volatile__ (
25610- "1: prefetch (%0)\n" /* This set is 28 bytes */
25611- " prefetch 64(%0)\n"
25612- " prefetch 128(%0)\n"
25613- " prefetch 192(%0)\n"
25614- " prefetch 256(%0)\n"
25615+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25616+ " prefetch 64(%1)\n"
25617+ " prefetch 128(%1)\n"
25618+ " prefetch 192(%1)\n"
25619+ " prefetch 256(%1)\n"
25620 "2: \n"
25621 ".section .fixup, \"ax\"\n"
25622- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25623+ "3: \n"
25624+
25625+#ifdef CONFIG_PAX_KERNEXEC
25626+ " movl %%cr0, %0\n"
25627+ " movl %0, %%eax\n"
25628+ " andl $0xFFFEFFFF, %%eax\n"
25629+ " movl %%eax, %%cr0\n"
25630+#endif
25631+
25632+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25633+
25634+#ifdef CONFIG_PAX_KERNEXEC
25635+ " movl %0, %%cr0\n"
25636+#endif
25637+
25638 " jmp 2b\n"
25639 ".previous\n"
25640 _ASM_EXTABLE(1b, 3b)
25641- : : "r" (from));
25642+ : "=&r" (cr0) : "r" (from) : "ax");
25643
25644 for ( ; i > 5; i--) {
25645 __asm__ __volatile__ (
25646- "1: prefetch 320(%0)\n"
25647- "2: movq (%0), %%mm0\n"
25648- " movq 8(%0), %%mm1\n"
25649- " movq 16(%0), %%mm2\n"
25650- " movq 24(%0), %%mm3\n"
25651- " movq %%mm0, (%1)\n"
25652- " movq %%mm1, 8(%1)\n"
25653- " movq %%mm2, 16(%1)\n"
25654- " movq %%mm3, 24(%1)\n"
25655- " movq 32(%0), %%mm0\n"
25656- " movq 40(%0), %%mm1\n"
25657- " movq 48(%0), %%mm2\n"
25658- " movq 56(%0), %%mm3\n"
25659- " movq %%mm0, 32(%1)\n"
25660- " movq %%mm1, 40(%1)\n"
25661- " movq %%mm2, 48(%1)\n"
25662- " movq %%mm3, 56(%1)\n"
25663+ "1: prefetch 320(%1)\n"
25664+ "2: movq (%1), %%mm0\n"
25665+ " movq 8(%1), %%mm1\n"
25666+ " movq 16(%1), %%mm2\n"
25667+ " movq 24(%1), %%mm3\n"
25668+ " movq %%mm0, (%2)\n"
25669+ " movq %%mm1, 8(%2)\n"
25670+ " movq %%mm2, 16(%2)\n"
25671+ " movq %%mm3, 24(%2)\n"
25672+ " movq 32(%1), %%mm0\n"
25673+ " movq 40(%1), %%mm1\n"
25674+ " movq 48(%1), %%mm2\n"
25675+ " movq 56(%1), %%mm3\n"
25676+ " movq %%mm0, 32(%2)\n"
25677+ " movq %%mm1, 40(%2)\n"
25678+ " movq %%mm2, 48(%2)\n"
25679+ " movq %%mm3, 56(%2)\n"
25680 ".section .fixup, \"ax\"\n"
25681- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25682+ "3:\n"
25683+
25684+#ifdef CONFIG_PAX_KERNEXEC
25685+ " movl %%cr0, %0\n"
25686+ " movl %0, %%eax\n"
25687+ " andl $0xFFFEFFFF, %%eax\n"
25688+ " movl %%eax, %%cr0\n"
25689+#endif
25690+
25691+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25692+
25693+#ifdef CONFIG_PAX_KERNEXEC
25694+ " movl %0, %%cr0\n"
25695+#endif
25696+
25697 " jmp 2b\n"
25698 ".previous\n"
25699 _ASM_EXTABLE(1b, 3b)
25700- : : "r" (from), "r" (to) : "memory");
25701+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25702
25703 from += 64;
25704 to += 64;
25705@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25706 static void fast_copy_page(void *to, void *from)
25707 {
25708 int i;
25709+ unsigned long cr0;
25710
25711 kernel_fpu_begin();
25712
25713@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25714 * but that is for later. -AV
25715 */
25716 __asm__ __volatile__(
25717- "1: prefetch (%0)\n"
25718- " prefetch 64(%0)\n"
25719- " prefetch 128(%0)\n"
25720- " prefetch 192(%0)\n"
25721- " prefetch 256(%0)\n"
25722+ "1: prefetch (%1)\n"
25723+ " prefetch 64(%1)\n"
25724+ " prefetch 128(%1)\n"
25725+ " prefetch 192(%1)\n"
25726+ " prefetch 256(%1)\n"
25727 "2: \n"
25728 ".section .fixup, \"ax\"\n"
25729- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25730+ "3: \n"
25731+
25732+#ifdef CONFIG_PAX_KERNEXEC
25733+ " movl %%cr0, %0\n"
25734+ " movl %0, %%eax\n"
25735+ " andl $0xFFFEFFFF, %%eax\n"
25736+ " movl %%eax, %%cr0\n"
25737+#endif
25738+
25739+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25740+
25741+#ifdef CONFIG_PAX_KERNEXEC
25742+ " movl %0, %%cr0\n"
25743+#endif
25744+
25745 " jmp 2b\n"
25746 ".previous\n"
25747- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25748+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25749
25750 for (i = 0; i < (4096-320)/64; i++) {
25751 __asm__ __volatile__ (
25752- "1: prefetch 320(%0)\n"
25753- "2: movq (%0), %%mm0\n"
25754- " movntq %%mm0, (%1)\n"
25755- " movq 8(%0), %%mm1\n"
25756- " movntq %%mm1, 8(%1)\n"
25757- " movq 16(%0), %%mm2\n"
25758- " movntq %%mm2, 16(%1)\n"
25759- " movq 24(%0), %%mm3\n"
25760- " movntq %%mm3, 24(%1)\n"
25761- " movq 32(%0), %%mm4\n"
25762- " movntq %%mm4, 32(%1)\n"
25763- " movq 40(%0), %%mm5\n"
25764- " movntq %%mm5, 40(%1)\n"
25765- " movq 48(%0), %%mm6\n"
25766- " movntq %%mm6, 48(%1)\n"
25767- " movq 56(%0), %%mm7\n"
25768- " movntq %%mm7, 56(%1)\n"
25769+ "1: prefetch 320(%1)\n"
25770+ "2: movq (%1), %%mm0\n"
25771+ " movntq %%mm0, (%2)\n"
25772+ " movq 8(%1), %%mm1\n"
25773+ " movntq %%mm1, 8(%2)\n"
25774+ " movq 16(%1), %%mm2\n"
25775+ " movntq %%mm2, 16(%2)\n"
25776+ " movq 24(%1), %%mm3\n"
25777+ " movntq %%mm3, 24(%2)\n"
25778+ " movq 32(%1), %%mm4\n"
25779+ " movntq %%mm4, 32(%2)\n"
25780+ " movq 40(%1), %%mm5\n"
25781+ " movntq %%mm5, 40(%2)\n"
25782+ " movq 48(%1), %%mm6\n"
25783+ " movntq %%mm6, 48(%2)\n"
25784+ " movq 56(%1), %%mm7\n"
25785+ " movntq %%mm7, 56(%2)\n"
25786 ".section .fixup, \"ax\"\n"
25787- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25788+ "3:\n"
25789+
25790+#ifdef CONFIG_PAX_KERNEXEC
25791+ " movl %%cr0, %0\n"
25792+ " movl %0, %%eax\n"
25793+ " andl $0xFFFEFFFF, %%eax\n"
25794+ " movl %%eax, %%cr0\n"
25795+#endif
25796+
25797+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25798+
25799+#ifdef CONFIG_PAX_KERNEXEC
25800+ " movl %0, %%cr0\n"
25801+#endif
25802+
25803 " jmp 2b\n"
25804 ".previous\n"
25805- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25806+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25807
25808 from += 64;
25809 to += 64;
25810@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25811 static void fast_copy_page(void *to, void *from)
25812 {
25813 int i;
25814+ unsigned long cr0;
25815
25816 kernel_fpu_begin();
25817
25818 __asm__ __volatile__ (
25819- "1: prefetch (%0)\n"
25820- " prefetch 64(%0)\n"
25821- " prefetch 128(%0)\n"
25822- " prefetch 192(%0)\n"
25823- " prefetch 256(%0)\n"
25824+ "1: prefetch (%1)\n"
25825+ " prefetch 64(%1)\n"
25826+ " prefetch 128(%1)\n"
25827+ " prefetch 192(%1)\n"
25828+ " prefetch 256(%1)\n"
25829 "2: \n"
25830 ".section .fixup, \"ax\"\n"
25831- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25832+ "3: \n"
25833+
25834+#ifdef CONFIG_PAX_KERNEXEC
25835+ " movl %%cr0, %0\n"
25836+ " movl %0, %%eax\n"
25837+ " andl $0xFFFEFFFF, %%eax\n"
25838+ " movl %%eax, %%cr0\n"
25839+#endif
25840+
25841+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25842+
25843+#ifdef CONFIG_PAX_KERNEXEC
25844+ " movl %0, %%cr0\n"
25845+#endif
25846+
25847 " jmp 2b\n"
25848 ".previous\n"
25849- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25850+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25851
25852 for (i = 0; i < 4096/64; i++) {
25853 __asm__ __volatile__ (
25854- "1: prefetch 320(%0)\n"
25855- "2: movq (%0), %%mm0\n"
25856- " movq 8(%0), %%mm1\n"
25857- " movq 16(%0), %%mm2\n"
25858- " movq 24(%0), %%mm3\n"
25859- " movq %%mm0, (%1)\n"
25860- " movq %%mm1, 8(%1)\n"
25861- " movq %%mm2, 16(%1)\n"
25862- " movq %%mm3, 24(%1)\n"
25863- " movq 32(%0), %%mm0\n"
25864- " movq 40(%0), %%mm1\n"
25865- " movq 48(%0), %%mm2\n"
25866- " movq 56(%0), %%mm3\n"
25867- " movq %%mm0, 32(%1)\n"
25868- " movq %%mm1, 40(%1)\n"
25869- " movq %%mm2, 48(%1)\n"
25870- " movq %%mm3, 56(%1)\n"
25871+ "1: prefetch 320(%1)\n"
25872+ "2: movq (%1), %%mm0\n"
25873+ " movq 8(%1), %%mm1\n"
25874+ " movq 16(%1), %%mm2\n"
25875+ " movq 24(%1), %%mm3\n"
25876+ " movq %%mm0, (%2)\n"
25877+ " movq %%mm1, 8(%2)\n"
25878+ " movq %%mm2, 16(%2)\n"
25879+ " movq %%mm3, 24(%2)\n"
25880+ " movq 32(%1), %%mm0\n"
25881+ " movq 40(%1), %%mm1\n"
25882+ " movq 48(%1), %%mm2\n"
25883+ " movq 56(%1), %%mm3\n"
25884+ " movq %%mm0, 32(%2)\n"
25885+ " movq %%mm1, 40(%2)\n"
25886+ " movq %%mm2, 48(%2)\n"
25887+ " movq %%mm3, 56(%2)\n"
25888 ".section .fixup, \"ax\"\n"
25889- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25890+ "3:\n"
25891+
25892+#ifdef CONFIG_PAX_KERNEXEC
25893+ " movl %%cr0, %0\n"
25894+ " movl %0, %%eax\n"
25895+ " andl $0xFFFEFFFF, %%eax\n"
25896+ " movl %%eax, %%cr0\n"
25897+#endif
25898+
25899+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25900+
25901+#ifdef CONFIG_PAX_KERNEXEC
25902+ " movl %0, %%cr0\n"
25903+#endif
25904+
25905 " jmp 2b\n"
25906 ".previous\n"
25907 _ASM_EXTABLE(1b, 3b)
25908- : : "r" (from), "r" (to) : "memory");
25909+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25910
25911 from += 64;
25912 to += 64;
25913diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
25914index f6d13ee..aca5f0b 100644
25915--- a/arch/x86/lib/msr-reg.S
25916+++ b/arch/x86/lib/msr-reg.S
25917@@ -3,6 +3,7 @@
25918 #include <asm/dwarf2.h>
25919 #include <asm/asm.h>
25920 #include <asm/msr.h>
25921+#include <asm/alternative-asm.h>
25922
25923 #ifdef CONFIG_X86_64
25924 /*
25925@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
25926 CFI_STARTPROC
25927 pushq_cfi %rbx
25928 pushq_cfi %rbp
25929- movq %rdi, %r10 /* Save pointer */
25930+ movq %rdi, %r9 /* Save pointer */
25931 xorl %r11d, %r11d /* Return value */
25932 movl (%rdi), %eax
25933 movl 4(%rdi), %ecx
25934@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
25935 movl 28(%rdi), %edi
25936 CFI_REMEMBER_STATE
25937 1: \op
25938-2: movl %eax, (%r10)
25939+2: movl %eax, (%r9)
25940 movl %r11d, %eax /* Return value */
25941- movl %ecx, 4(%r10)
25942- movl %edx, 8(%r10)
25943- movl %ebx, 12(%r10)
25944- movl %ebp, 20(%r10)
25945- movl %esi, 24(%r10)
25946- movl %edi, 28(%r10)
25947+ movl %ecx, 4(%r9)
25948+ movl %edx, 8(%r9)
25949+ movl %ebx, 12(%r9)
25950+ movl %ebp, 20(%r9)
25951+ movl %esi, 24(%r9)
25952+ movl %edi, 28(%r9)
25953 popq_cfi %rbp
25954 popq_cfi %rbx
25955+ pax_force_retaddr
25956 ret
25957 3:
25958 CFI_RESTORE_STATE
25959diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
25960index fc6ba17..04471c5 100644
25961--- a/arch/x86/lib/putuser.S
25962+++ b/arch/x86/lib/putuser.S
25963@@ -16,7 +16,9 @@
25964 #include <asm/errno.h>
25965 #include <asm/asm.h>
25966 #include <asm/smap.h>
25967-
25968+#include <asm/segment.h>
25969+#include <asm/pgtable.h>
25970+#include <asm/alternative-asm.h>
25971
25972 /*
25973 * __put_user_X
25974@@ -30,57 +32,125 @@
25975 * as they get called from within inline assembly.
25976 */
25977
25978-#define ENTER CFI_STARTPROC ; \
25979- GET_THREAD_INFO(%_ASM_BX)
25980-#define EXIT ASM_CLAC ; \
25981- ret ; \
25982+#define ENTER CFI_STARTPROC
25983+#define EXIT ASM_CLAC ; \
25984+ pax_force_retaddr ; \
25985+ ret ; \
25986 CFI_ENDPROC
25987
25988+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25989+#define _DEST %_ASM_CX,%_ASM_BX
25990+#else
25991+#define _DEST %_ASM_CX
25992+#endif
25993+
25994+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25995+#define __copyuser_seg gs;
25996+#else
25997+#define __copyuser_seg
25998+#endif
25999+
26000 .text
26001 ENTRY(__put_user_1)
26002 ENTER
26003+
26004+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26005+ GET_THREAD_INFO(%_ASM_BX)
26006 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26007 jae bad_put_user
26008 ASM_STAC
26009-1: movb %al,(%_ASM_CX)
26010+
26011+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26012+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26013+ cmp %_ASM_BX,%_ASM_CX
26014+ jb 1234f
26015+ xor %ebx,%ebx
26016+1234:
26017+#endif
26018+
26019+#endif
26020+
26021+1: __copyuser_seg movb %al,(_DEST)
26022 xor %eax,%eax
26023 EXIT
26024 ENDPROC(__put_user_1)
26025
26026 ENTRY(__put_user_2)
26027 ENTER
26028+
26029+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26030+ GET_THREAD_INFO(%_ASM_BX)
26031 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26032 sub $1,%_ASM_BX
26033 cmp %_ASM_BX,%_ASM_CX
26034 jae bad_put_user
26035 ASM_STAC
26036-2: movw %ax,(%_ASM_CX)
26037+
26038+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26039+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26040+ cmp %_ASM_BX,%_ASM_CX
26041+ jb 1234f
26042+ xor %ebx,%ebx
26043+1234:
26044+#endif
26045+
26046+#endif
26047+
26048+2: __copyuser_seg movw %ax,(_DEST)
26049 xor %eax,%eax
26050 EXIT
26051 ENDPROC(__put_user_2)
26052
26053 ENTRY(__put_user_4)
26054 ENTER
26055+
26056+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26057+ GET_THREAD_INFO(%_ASM_BX)
26058 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26059 sub $3,%_ASM_BX
26060 cmp %_ASM_BX,%_ASM_CX
26061 jae bad_put_user
26062 ASM_STAC
26063-3: movl %eax,(%_ASM_CX)
26064+
26065+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26066+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26067+ cmp %_ASM_BX,%_ASM_CX
26068+ jb 1234f
26069+ xor %ebx,%ebx
26070+1234:
26071+#endif
26072+
26073+#endif
26074+
26075+3: __copyuser_seg movl %eax,(_DEST)
26076 xor %eax,%eax
26077 EXIT
26078 ENDPROC(__put_user_4)
26079
26080 ENTRY(__put_user_8)
26081 ENTER
26082+
26083+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26084+ GET_THREAD_INFO(%_ASM_BX)
26085 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26086 sub $7,%_ASM_BX
26087 cmp %_ASM_BX,%_ASM_CX
26088 jae bad_put_user
26089 ASM_STAC
26090-4: mov %_ASM_AX,(%_ASM_CX)
26091+
26092+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26093+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
26094+ cmp %_ASM_BX,%_ASM_CX
26095+ jb 1234f
26096+ xor %ebx,%ebx
26097+1234:
26098+#endif
26099+
26100+#endif
26101+
26102+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26103 #ifdef CONFIG_X86_32
26104-5: movl %edx,4(%_ASM_CX)
26105+5: __copyuser_seg movl %edx,4(_DEST)
26106 #endif
26107 xor %eax,%eax
26108 EXIT
26109diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26110index 1cad221..de671ee 100644
26111--- a/arch/x86/lib/rwlock.S
26112+++ b/arch/x86/lib/rwlock.S
26113@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26114 FRAME
26115 0: LOCK_PREFIX
26116 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26117+
26118+#ifdef CONFIG_PAX_REFCOUNT
26119+ jno 1234f
26120+ LOCK_PREFIX
26121+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26122+ int $4
26123+1234:
26124+ _ASM_EXTABLE(1234b, 1234b)
26125+#endif
26126+
26127 1: rep; nop
26128 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26129 jne 1b
26130 LOCK_PREFIX
26131 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26132+
26133+#ifdef CONFIG_PAX_REFCOUNT
26134+ jno 1234f
26135+ LOCK_PREFIX
26136+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26137+ int $4
26138+1234:
26139+ _ASM_EXTABLE(1234b, 1234b)
26140+#endif
26141+
26142 jnz 0b
26143 ENDFRAME
26144+ pax_force_retaddr
26145 ret
26146 CFI_ENDPROC
26147 END(__write_lock_failed)
26148@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26149 FRAME
26150 0: LOCK_PREFIX
26151 READ_LOCK_SIZE(inc) (%__lock_ptr)
26152+
26153+#ifdef CONFIG_PAX_REFCOUNT
26154+ jno 1234f
26155+ LOCK_PREFIX
26156+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26157+ int $4
26158+1234:
26159+ _ASM_EXTABLE(1234b, 1234b)
26160+#endif
26161+
26162 1: rep; nop
26163 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26164 js 1b
26165 LOCK_PREFIX
26166 READ_LOCK_SIZE(dec) (%__lock_ptr)
26167+
26168+#ifdef CONFIG_PAX_REFCOUNT
26169+ jno 1234f
26170+ LOCK_PREFIX
26171+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26172+ int $4
26173+1234:
26174+ _ASM_EXTABLE(1234b, 1234b)
26175+#endif
26176+
26177 js 0b
26178 ENDFRAME
26179+ pax_force_retaddr
26180 ret
26181 CFI_ENDPROC
26182 END(__read_lock_failed)
26183diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26184index 5dff5f0..cadebf4 100644
26185--- a/arch/x86/lib/rwsem.S
26186+++ b/arch/x86/lib/rwsem.S
26187@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26188 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26189 CFI_RESTORE __ASM_REG(dx)
26190 restore_common_regs
26191+ pax_force_retaddr
26192 ret
26193 CFI_ENDPROC
26194 ENDPROC(call_rwsem_down_read_failed)
26195@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26196 movq %rax,%rdi
26197 call rwsem_down_write_failed
26198 restore_common_regs
26199+ pax_force_retaddr
26200 ret
26201 CFI_ENDPROC
26202 ENDPROC(call_rwsem_down_write_failed)
26203@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26204 movq %rax,%rdi
26205 call rwsem_wake
26206 restore_common_regs
26207-1: ret
26208+1: pax_force_retaddr
26209+ ret
26210 CFI_ENDPROC
26211 ENDPROC(call_rwsem_wake)
26212
26213@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26214 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26215 CFI_RESTORE __ASM_REG(dx)
26216 restore_common_regs
26217+ pax_force_retaddr
26218 ret
26219 CFI_ENDPROC
26220 ENDPROC(call_rwsem_downgrade_wake)
26221diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26222index a63efd6..ccecad8 100644
26223--- a/arch/x86/lib/thunk_64.S
26224+++ b/arch/x86/lib/thunk_64.S
26225@@ -8,6 +8,7 @@
26226 #include <linux/linkage.h>
26227 #include <asm/dwarf2.h>
26228 #include <asm/calling.h>
26229+#include <asm/alternative-asm.h>
26230
26231 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26232 .macro THUNK name, func, put_ret_addr_in_rdi=0
26233@@ -41,5 +42,6 @@
26234 SAVE_ARGS
26235 restore:
26236 RESTORE_ARGS
26237+ pax_force_retaddr
26238 ret
26239 CFI_ENDPROC
26240diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26241index f0312d7..9c39d63 100644
26242--- a/arch/x86/lib/usercopy_32.c
26243+++ b/arch/x86/lib/usercopy_32.c
26244@@ -42,11 +42,13 @@ do { \
26245 int __d0; \
26246 might_fault(); \
26247 __asm__ __volatile__( \
26248+ __COPYUSER_SET_ES \
26249 ASM_STAC "\n" \
26250 "0: rep; stosl\n" \
26251 " movl %2,%0\n" \
26252 "1: rep; stosb\n" \
26253 "2: " ASM_CLAC "\n" \
26254+ __COPYUSER_RESTORE_ES \
26255 ".section .fixup,\"ax\"\n" \
26256 "3: lea 0(%2,%0,4),%0\n" \
26257 " jmp 2b\n" \
26258@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26259
26260 #ifdef CONFIG_X86_INTEL_USERCOPY
26261 static unsigned long
26262-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26263+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26264 {
26265 int d0, d1;
26266 __asm__ __volatile__(
26267@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26268 " .align 2,0x90\n"
26269 "3: movl 0(%4), %%eax\n"
26270 "4: movl 4(%4), %%edx\n"
26271- "5: movl %%eax, 0(%3)\n"
26272- "6: movl %%edx, 4(%3)\n"
26273+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26274+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26275 "7: movl 8(%4), %%eax\n"
26276 "8: movl 12(%4),%%edx\n"
26277- "9: movl %%eax, 8(%3)\n"
26278- "10: movl %%edx, 12(%3)\n"
26279+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26280+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26281 "11: movl 16(%4), %%eax\n"
26282 "12: movl 20(%4), %%edx\n"
26283- "13: movl %%eax, 16(%3)\n"
26284- "14: movl %%edx, 20(%3)\n"
26285+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26286+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26287 "15: movl 24(%4), %%eax\n"
26288 "16: movl 28(%4), %%edx\n"
26289- "17: movl %%eax, 24(%3)\n"
26290- "18: movl %%edx, 28(%3)\n"
26291+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26292+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26293 "19: movl 32(%4), %%eax\n"
26294 "20: movl 36(%4), %%edx\n"
26295- "21: movl %%eax, 32(%3)\n"
26296- "22: movl %%edx, 36(%3)\n"
26297+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26298+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26299 "23: movl 40(%4), %%eax\n"
26300 "24: movl 44(%4), %%edx\n"
26301- "25: movl %%eax, 40(%3)\n"
26302- "26: movl %%edx, 44(%3)\n"
26303+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26304+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26305 "27: movl 48(%4), %%eax\n"
26306 "28: movl 52(%4), %%edx\n"
26307- "29: movl %%eax, 48(%3)\n"
26308- "30: movl %%edx, 52(%3)\n"
26309+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26310+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26311 "31: movl 56(%4), %%eax\n"
26312 "32: movl 60(%4), %%edx\n"
26313- "33: movl %%eax, 56(%3)\n"
26314- "34: movl %%edx, 60(%3)\n"
26315+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26316+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26317 " addl $-64, %0\n"
26318 " addl $64, %4\n"
26319 " addl $64, %3\n"
26320@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26321 " shrl $2, %0\n"
26322 " andl $3, %%eax\n"
26323 " cld\n"
26324+ __COPYUSER_SET_ES
26325 "99: rep; movsl\n"
26326 "36: movl %%eax, %0\n"
26327 "37: rep; movsb\n"
26328 "100:\n"
26329+ __COPYUSER_RESTORE_ES
26330 ".section .fixup,\"ax\"\n"
26331 "101: lea 0(%%eax,%0,4),%0\n"
26332 " jmp 100b\n"
26333@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26334 }
26335
26336 static unsigned long
26337+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26338+{
26339+ int d0, d1;
26340+ __asm__ __volatile__(
26341+ " .align 2,0x90\n"
26342+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26343+ " cmpl $67, %0\n"
26344+ " jbe 3f\n"
26345+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26346+ " .align 2,0x90\n"
26347+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26348+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26349+ "5: movl %%eax, 0(%3)\n"
26350+ "6: movl %%edx, 4(%3)\n"
26351+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26352+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26353+ "9: movl %%eax, 8(%3)\n"
26354+ "10: movl %%edx, 12(%3)\n"
26355+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26356+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26357+ "13: movl %%eax, 16(%3)\n"
26358+ "14: movl %%edx, 20(%3)\n"
26359+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26360+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26361+ "17: movl %%eax, 24(%3)\n"
26362+ "18: movl %%edx, 28(%3)\n"
26363+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26364+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26365+ "21: movl %%eax, 32(%3)\n"
26366+ "22: movl %%edx, 36(%3)\n"
26367+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26368+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26369+ "25: movl %%eax, 40(%3)\n"
26370+ "26: movl %%edx, 44(%3)\n"
26371+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26372+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26373+ "29: movl %%eax, 48(%3)\n"
26374+ "30: movl %%edx, 52(%3)\n"
26375+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26376+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26377+ "33: movl %%eax, 56(%3)\n"
26378+ "34: movl %%edx, 60(%3)\n"
26379+ " addl $-64, %0\n"
26380+ " addl $64, %4\n"
26381+ " addl $64, %3\n"
26382+ " cmpl $63, %0\n"
26383+ " ja 1b\n"
26384+ "35: movl %0, %%eax\n"
26385+ " shrl $2, %0\n"
26386+ " andl $3, %%eax\n"
26387+ " cld\n"
26388+ "99: rep; "__copyuser_seg" movsl\n"
26389+ "36: movl %%eax, %0\n"
26390+ "37: rep; "__copyuser_seg" movsb\n"
26391+ "100:\n"
26392+ ".section .fixup,\"ax\"\n"
26393+ "101: lea 0(%%eax,%0,4),%0\n"
26394+ " jmp 100b\n"
26395+ ".previous\n"
26396+ _ASM_EXTABLE(1b,100b)
26397+ _ASM_EXTABLE(2b,100b)
26398+ _ASM_EXTABLE(3b,100b)
26399+ _ASM_EXTABLE(4b,100b)
26400+ _ASM_EXTABLE(5b,100b)
26401+ _ASM_EXTABLE(6b,100b)
26402+ _ASM_EXTABLE(7b,100b)
26403+ _ASM_EXTABLE(8b,100b)
26404+ _ASM_EXTABLE(9b,100b)
26405+ _ASM_EXTABLE(10b,100b)
26406+ _ASM_EXTABLE(11b,100b)
26407+ _ASM_EXTABLE(12b,100b)
26408+ _ASM_EXTABLE(13b,100b)
26409+ _ASM_EXTABLE(14b,100b)
26410+ _ASM_EXTABLE(15b,100b)
26411+ _ASM_EXTABLE(16b,100b)
26412+ _ASM_EXTABLE(17b,100b)
26413+ _ASM_EXTABLE(18b,100b)
26414+ _ASM_EXTABLE(19b,100b)
26415+ _ASM_EXTABLE(20b,100b)
26416+ _ASM_EXTABLE(21b,100b)
26417+ _ASM_EXTABLE(22b,100b)
26418+ _ASM_EXTABLE(23b,100b)
26419+ _ASM_EXTABLE(24b,100b)
26420+ _ASM_EXTABLE(25b,100b)
26421+ _ASM_EXTABLE(26b,100b)
26422+ _ASM_EXTABLE(27b,100b)
26423+ _ASM_EXTABLE(28b,100b)
26424+ _ASM_EXTABLE(29b,100b)
26425+ _ASM_EXTABLE(30b,100b)
26426+ _ASM_EXTABLE(31b,100b)
26427+ _ASM_EXTABLE(32b,100b)
26428+ _ASM_EXTABLE(33b,100b)
26429+ _ASM_EXTABLE(34b,100b)
26430+ _ASM_EXTABLE(35b,100b)
26431+ _ASM_EXTABLE(36b,100b)
26432+ _ASM_EXTABLE(37b,100b)
26433+ _ASM_EXTABLE(99b,101b)
26434+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26435+ : "1"(to), "2"(from), "0"(size)
26436+ : "eax", "edx", "memory");
26437+ return size;
26438+}
26439+
26440+static unsigned long __size_overflow(3)
26441 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26442 {
26443 int d0, d1;
26444 __asm__ __volatile__(
26445 " .align 2,0x90\n"
26446- "0: movl 32(%4), %%eax\n"
26447+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26448 " cmpl $67, %0\n"
26449 " jbe 2f\n"
26450- "1: movl 64(%4), %%eax\n"
26451+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26452 " .align 2,0x90\n"
26453- "2: movl 0(%4), %%eax\n"
26454- "21: movl 4(%4), %%edx\n"
26455+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26456+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26457 " movl %%eax, 0(%3)\n"
26458 " movl %%edx, 4(%3)\n"
26459- "3: movl 8(%4), %%eax\n"
26460- "31: movl 12(%4),%%edx\n"
26461+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26462+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26463 " movl %%eax, 8(%3)\n"
26464 " movl %%edx, 12(%3)\n"
26465- "4: movl 16(%4), %%eax\n"
26466- "41: movl 20(%4), %%edx\n"
26467+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26468+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26469 " movl %%eax, 16(%3)\n"
26470 " movl %%edx, 20(%3)\n"
26471- "10: movl 24(%4), %%eax\n"
26472- "51: movl 28(%4), %%edx\n"
26473+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26474+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26475 " movl %%eax, 24(%3)\n"
26476 " movl %%edx, 28(%3)\n"
26477- "11: movl 32(%4), %%eax\n"
26478- "61: movl 36(%4), %%edx\n"
26479+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26480+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26481 " movl %%eax, 32(%3)\n"
26482 " movl %%edx, 36(%3)\n"
26483- "12: movl 40(%4), %%eax\n"
26484- "71: movl 44(%4), %%edx\n"
26485+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26486+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26487 " movl %%eax, 40(%3)\n"
26488 " movl %%edx, 44(%3)\n"
26489- "13: movl 48(%4), %%eax\n"
26490- "81: movl 52(%4), %%edx\n"
26491+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26492+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26493 " movl %%eax, 48(%3)\n"
26494 " movl %%edx, 52(%3)\n"
26495- "14: movl 56(%4), %%eax\n"
26496- "91: movl 60(%4), %%edx\n"
26497+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26498+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26499 " movl %%eax, 56(%3)\n"
26500 " movl %%edx, 60(%3)\n"
26501 " addl $-64, %0\n"
26502@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26503 " shrl $2, %0\n"
26504 " andl $3, %%eax\n"
26505 " cld\n"
26506- "6: rep; movsl\n"
26507+ "6: rep; "__copyuser_seg" movsl\n"
26508 " movl %%eax,%0\n"
26509- "7: rep; movsb\n"
26510+ "7: rep; "__copyuser_seg" movsb\n"
26511 "8:\n"
26512 ".section .fixup,\"ax\"\n"
26513 "9: lea 0(%%eax,%0,4),%0\n"
26514@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26515 * hyoshiok@miraclelinux.com
26516 */
26517
26518-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26519+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26520 const void __user *from, unsigned long size)
26521 {
26522 int d0, d1;
26523
26524 __asm__ __volatile__(
26525 " .align 2,0x90\n"
26526- "0: movl 32(%4), %%eax\n"
26527+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26528 " cmpl $67, %0\n"
26529 " jbe 2f\n"
26530- "1: movl 64(%4), %%eax\n"
26531+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26532 " .align 2,0x90\n"
26533- "2: movl 0(%4), %%eax\n"
26534- "21: movl 4(%4), %%edx\n"
26535+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26536+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26537 " movnti %%eax, 0(%3)\n"
26538 " movnti %%edx, 4(%3)\n"
26539- "3: movl 8(%4), %%eax\n"
26540- "31: movl 12(%4),%%edx\n"
26541+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26542+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26543 " movnti %%eax, 8(%3)\n"
26544 " movnti %%edx, 12(%3)\n"
26545- "4: movl 16(%4), %%eax\n"
26546- "41: movl 20(%4), %%edx\n"
26547+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26548+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26549 " movnti %%eax, 16(%3)\n"
26550 " movnti %%edx, 20(%3)\n"
26551- "10: movl 24(%4), %%eax\n"
26552- "51: movl 28(%4), %%edx\n"
26553+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26554+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26555 " movnti %%eax, 24(%3)\n"
26556 " movnti %%edx, 28(%3)\n"
26557- "11: movl 32(%4), %%eax\n"
26558- "61: movl 36(%4), %%edx\n"
26559+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26560+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26561 " movnti %%eax, 32(%3)\n"
26562 " movnti %%edx, 36(%3)\n"
26563- "12: movl 40(%4), %%eax\n"
26564- "71: movl 44(%4), %%edx\n"
26565+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26566+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26567 " movnti %%eax, 40(%3)\n"
26568 " movnti %%edx, 44(%3)\n"
26569- "13: movl 48(%4), %%eax\n"
26570- "81: movl 52(%4), %%edx\n"
26571+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26572+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26573 " movnti %%eax, 48(%3)\n"
26574 " movnti %%edx, 52(%3)\n"
26575- "14: movl 56(%4), %%eax\n"
26576- "91: movl 60(%4), %%edx\n"
26577+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26578+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26579 " movnti %%eax, 56(%3)\n"
26580 " movnti %%edx, 60(%3)\n"
26581 " addl $-64, %0\n"
26582@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26583 " shrl $2, %0\n"
26584 " andl $3, %%eax\n"
26585 " cld\n"
26586- "6: rep; movsl\n"
26587+ "6: rep; "__copyuser_seg" movsl\n"
26588 " movl %%eax,%0\n"
26589- "7: rep; movsb\n"
26590+ "7: rep; "__copyuser_seg" movsb\n"
26591 "8:\n"
26592 ".section .fixup,\"ax\"\n"
26593 "9: lea 0(%%eax,%0,4),%0\n"
26594@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26595 return size;
26596 }
26597
26598-static unsigned long __copy_user_intel_nocache(void *to,
26599+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26600 const void __user *from, unsigned long size)
26601 {
26602 int d0, d1;
26603
26604 __asm__ __volatile__(
26605 " .align 2,0x90\n"
26606- "0: movl 32(%4), %%eax\n"
26607+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26608 " cmpl $67, %0\n"
26609 " jbe 2f\n"
26610- "1: movl 64(%4), %%eax\n"
26611+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26612 " .align 2,0x90\n"
26613- "2: movl 0(%4), %%eax\n"
26614- "21: movl 4(%4), %%edx\n"
26615+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26616+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26617 " movnti %%eax, 0(%3)\n"
26618 " movnti %%edx, 4(%3)\n"
26619- "3: movl 8(%4), %%eax\n"
26620- "31: movl 12(%4),%%edx\n"
26621+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26622+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26623 " movnti %%eax, 8(%3)\n"
26624 " movnti %%edx, 12(%3)\n"
26625- "4: movl 16(%4), %%eax\n"
26626- "41: movl 20(%4), %%edx\n"
26627+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26628+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26629 " movnti %%eax, 16(%3)\n"
26630 " movnti %%edx, 20(%3)\n"
26631- "10: movl 24(%4), %%eax\n"
26632- "51: movl 28(%4), %%edx\n"
26633+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26634+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26635 " movnti %%eax, 24(%3)\n"
26636 " movnti %%edx, 28(%3)\n"
26637- "11: movl 32(%4), %%eax\n"
26638- "61: movl 36(%4), %%edx\n"
26639+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26640+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26641 " movnti %%eax, 32(%3)\n"
26642 " movnti %%edx, 36(%3)\n"
26643- "12: movl 40(%4), %%eax\n"
26644- "71: movl 44(%4), %%edx\n"
26645+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26646+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26647 " movnti %%eax, 40(%3)\n"
26648 " movnti %%edx, 44(%3)\n"
26649- "13: movl 48(%4), %%eax\n"
26650- "81: movl 52(%4), %%edx\n"
26651+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26652+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26653 " movnti %%eax, 48(%3)\n"
26654 " movnti %%edx, 52(%3)\n"
26655- "14: movl 56(%4), %%eax\n"
26656- "91: movl 60(%4), %%edx\n"
26657+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26658+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26659 " movnti %%eax, 56(%3)\n"
26660 " movnti %%edx, 60(%3)\n"
26661 " addl $-64, %0\n"
26662@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26663 " shrl $2, %0\n"
26664 " andl $3, %%eax\n"
26665 " cld\n"
26666- "6: rep; movsl\n"
26667+ "6: rep; "__copyuser_seg" movsl\n"
26668 " movl %%eax,%0\n"
26669- "7: rep; movsb\n"
26670+ "7: rep; "__copyuser_seg" movsb\n"
26671 "8:\n"
26672 ".section .fixup,\"ax\"\n"
26673 "9: lea 0(%%eax,%0,4),%0\n"
26674@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26675 */
26676 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26677 unsigned long size);
26678-unsigned long __copy_user_intel(void __user *to, const void *from,
26679+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26680+ unsigned long size);
26681+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26682 unsigned long size);
26683 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26684 const void __user *from, unsigned long size);
26685 #endif /* CONFIG_X86_INTEL_USERCOPY */
26686
26687 /* Generic arbitrary sized copy. */
26688-#define __copy_user(to, from, size) \
26689+#define __copy_user(to, from, size, prefix, set, restore) \
26690 do { \
26691 int __d0, __d1, __d2; \
26692 __asm__ __volatile__( \
26693+ set \
26694 " cmp $7,%0\n" \
26695 " jbe 1f\n" \
26696 " movl %1,%0\n" \
26697 " negl %0\n" \
26698 " andl $7,%0\n" \
26699 " subl %0,%3\n" \
26700- "4: rep; movsb\n" \
26701+ "4: rep; "prefix"movsb\n" \
26702 " movl %3,%0\n" \
26703 " shrl $2,%0\n" \
26704 " andl $3,%3\n" \
26705 " .align 2,0x90\n" \
26706- "0: rep; movsl\n" \
26707+ "0: rep; "prefix"movsl\n" \
26708 " movl %3,%0\n" \
26709- "1: rep; movsb\n" \
26710+ "1: rep; "prefix"movsb\n" \
26711 "2:\n" \
26712+ restore \
26713 ".section .fixup,\"ax\"\n" \
26714 "5: addl %3,%0\n" \
26715 " jmp 2b\n" \
26716@@ -538,14 +650,14 @@ do { \
26717 " negl %0\n" \
26718 " andl $7,%0\n" \
26719 " subl %0,%3\n" \
26720- "4: rep; movsb\n" \
26721+ "4: rep; "__copyuser_seg"movsb\n" \
26722 " movl %3,%0\n" \
26723 " shrl $2,%0\n" \
26724 " andl $3,%3\n" \
26725 " .align 2,0x90\n" \
26726- "0: rep; movsl\n" \
26727+ "0: rep; "__copyuser_seg"movsl\n" \
26728 " movl %3,%0\n" \
26729- "1: rep; movsb\n" \
26730+ "1: rep; "__copyuser_seg"movsb\n" \
26731 "2:\n" \
26732 ".section .fixup,\"ax\"\n" \
26733 "5: addl %3,%0\n" \
26734@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26735 {
26736 stac();
26737 if (movsl_is_ok(to, from, n))
26738- __copy_user(to, from, n);
26739+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26740 else
26741- n = __copy_user_intel(to, from, n);
26742+ n = __generic_copy_to_user_intel(to, from, n);
26743 clac();
26744 return n;
26745 }
26746@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26747 {
26748 stac();
26749 if (movsl_is_ok(to, from, n))
26750- __copy_user(to, from, n);
26751+ __copy_user(to, from, n, __copyuser_seg, "", "");
26752 else
26753- n = __copy_user_intel((void __user *)to,
26754- (const void *)from, n);
26755+ n = __generic_copy_from_user_intel(to, from, n);
26756 clac();
26757 return n;
26758 }
26759@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26760 if (n > 64 && cpu_has_xmm2)
26761 n = __copy_user_intel_nocache(to, from, n);
26762 else
26763- __copy_user(to, from, n);
26764+ __copy_user(to, from, n, __copyuser_seg, "", "");
26765 #else
26766- __copy_user(to, from, n);
26767+ __copy_user(to, from, n, __copyuser_seg, "", "");
26768 #endif
26769 clac();
26770 return n;
26771 }
26772 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26773
26774-/**
26775- * copy_to_user: - Copy a block of data into user space.
26776- * @to: Destination address, in user space.
26777- * @from: Source address, in kernel space.
26778- * @n: Number of bytes to copy.
26779- *
26780- * Context: User context only. This function may sleep.
26781- *
26782- * Copy data from kernel space to user space.
26783- *
26784- * Returns number of bytes that could not be copied.
26785- * On success, this will be zero.
26786- */
26787-unsigned long
26788-copy_to_user(void __user *to, const void *from, unsigned long n)
26789-{
26790- if (access_ok(VERIFY_WRITE, to, n))
26791- n = __copy_to_user(to, from, n);
26792- return n;
26793-}
26794-EXPORT_SYMBOL(copy_to_user);
26795-
26796-/**
26797- * copy_from_user: - Copy a block of data from user space.
26798- * @to: Destination address, in kernel space.
26799- * @from: Source address, in user space.
26800- * @n: Number of bytes to copy.
26801- *
26802- * Context: User context only. This function may sleep.
26803- *
26804- * Copy data from user space to kernel space.
26805- *
26806- * Returns number of bytes that could not be copied.
26807- * On success, this will be zero.
26808- *
26809- * If some data could not be copied, this function will pad the copied
26810- * data to the requested size using zero bytes.
26811- */
26812-unsigned long
26813-_copy_from_user(void *to, const void __user *from, unsigned long n)
26814-{
26815- if (access_ok(VERIFY_READ, from, n))
26816- n = __copy_from_user(to, from, n);
26817- else
26818- memset(to, 0, n);
26819- return n;
26820-}
26821-EXPORT_SYMBOL(_copy_from_user);
26822-
26823 void copy_from_user_overflow(void)
26824 {
26825 WARN(1, "Buffer overflow detected!\n");
26826 }
26827 EXPORT_SYMBOL(copy_from_user_overflow);
26828+
26829+void copy_to_user_overflow(void)
26830+{
26831+ WARN(1, "Buffer overflow detected!\n");
26832+}
26833+EXPORT_SYMBOL(copy_to_user_overflow);
26834+
26835+#ifdef CONFIG_PAX_MEMORY_UDEREF
26836+void __set_fs(mm_segment_t x)
26837+{
26838+ switch (x.seg) {
26839+ case 0:
26840+ loadsegment(gs, 0);
26841+ break;
26842+ case TASK_SIZE_MAX:
26843+ loadsegment(gs, __USER_DS);
26844+ break;
26845+ case -1UL:
26846+ loadsegment(gs, __KERNEL_DS);
26847+ break;
26848+ default:
26849+ BUG();
26850+ }
26851+ return;
26852+}
26853+EXPORT_SYMBOL(__set_fs);
26854+
26855+void set_fs(mm_segment_t x)
26856+{
26857+ current_thread_info()->addr_limit = x;
26858+ __set_fs(x);
26859+}
26860+EXPORT_SYMBOL(set_fs);
26861+#endif
26862diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26863index 05928aa..b33dea1 100644
26864--- a/arch/x86/lib/usercopy_64.c
26865+++ b/arch/x86/lib/usercopy_64.c
26866@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26867 _ASM_EXTABLE(0b,3b)
26868 _ASM_EXTABLE(1b,2b)
26869 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26870- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26871+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26872 [zero] "r" (0UL), [eight] "r" (8UL));
26873 clac();
26874 return size;
26875@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26876 }
26877 EXPORT_SYMBOL(clear_user);
26878
26879-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26880+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26881 {
26882- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26883- return copy_user_generic((__force void *)to, (__force void *)from, len);
26884- }
26885- return len;
26886+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
26887+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
26888+ return len;
26889 }
26890 EXPORT_SYMBOL(copy_in_user);
26891
26892@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
26893 * it is not necessary to optimize tail handling.
26894 */
26895 unsigned long
26896-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26897+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
26898 {
26899 char c;
26900 unsigned zero_len;
26901@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26902 clac();
26903 return len;
26904 }
26905+
26906+void copy_from_user_overflow(void)
26907+{
26908+ WARN(1, "Buffer overflow detected!\n");
26909+}
26910+EXPORT_SYMBOL(copy_from_user_overflow);
26911+
26912+void copy_to_user_overflow(void)
26913+{
26914+ WARN(1, "Buffer overflow detected!\n");
26915+}
26916+EXPORT_SYMBOL(copy_to_user_overflow);
26917diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
26918index 903ec1e..c4166b2 100644
26919--- a/arch/x86/mm/extable.c
26920+++ b/arch/x86/mm/extable.c
26921@@ -6,12 +6,24 @@
26922 static inline unsigned long
26923 ex_insn_addr(const struct exception_table_entry *x)
26924 {
26925- return (unsigned long)&x->insn + x->insn;
26926+ unsigned long reloc = 0;
26927+
26928+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26929+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26930+#endif
26931+
26932+ return (unsigned long)&x->insn + x->insn + reloc;
26933 }
26934 static inline unsigned long
26935 ex_fixup_addr(const struct exception_table_entry *x)
26936 {
26937- return (unsigned long)&x->fixup + x->fixup;
26938+ unsigned long reloc = 0;
26939+
26940+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26941+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26942+#endif
26943+
26944+ return (unsigned long)&x->fixup + x->fixup + reloc;
26945 }
26946
26947 int fixup_exception(struct pt_regs *regs)
26948@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
26949 unsigned long new_ip;
26950
26951 #ifdef CONFIG_PNPBIOS
26952- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
26953+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
26954 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
26955 extern u32 pnp_bios_is_utter_crap;
26956 pnp_bios_is_utter_crap = 1;
26957@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
26958 i += 4;
26959 p->fixup -= i;
26960 i += 4;
26961+
26962+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26963+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
26964+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26965+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26966+#endif
26967+
26968 }
26969 }
26970
26971diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
26972index fb674fd..1be28b9 100644
26973--- a/arch/x86/mm/fault.c
26974+++ b/arch/x86/mm/fault.c
26975@@ -13,12 +13,19 @@
26976 #include <linux/perf_event.h> /* perf_sw_event */
26977 #include <linux/hugetlb.h> /* hstate_index_to_shift */
26978 #include <linux/prefetch.h> /* prefetchw */
26979+#include <linux/unistd.h>
26980+#include <linux/compiler.h>
26981
26982 #include <asm/traps.h> /* dotraplinkage, ... */
26983 #include <asm/pgalloc.h> /* pgd_*(), ... */
26984 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
26985 #include <asm/fixmap.h> /* VSYSCALL_START */
26986 #include <asm/context_tracking.h> /* exception_enter(), ... */
26987+#include <asm/tlbflush.h>
26988+
26989+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26990+#include <asm/stacktrace.h>
26991+#endif
26992
26993 /*
26994 * Page fault error code bits:
26995@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
26996 int ret = 0;
26997
26998 /* kprobe_running() needs smp_processor_id() */
26999- if (kprobes_built_in() && !user_mode_vm(regs)) {
27000+ if (kprobes_built_in() && !user_mode(regs)) {
27001 preempt_disable();
27002 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27003 ret = 1;
27004@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27005 return !instr_lo || (instr_lo>>1) == 1;
27006 case 0x00:
27007 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27008- if (probe_kernel_address(instr, opcode))
27009+ if (user_mode(regs)) {
27010+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27011+ return 0;
27012+ } else if (probe_kernel_address(instr, opcode))
27013 return 0;
27014
27015 *prefetch = (instr_lo == 0xF) &&
27016@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27017 while (instr < max_instr) {
27018 unsigned char opcode;
27019
27020- if (probe_kernel_address(instr, opcode))
27021+ if (user_mode(regs)) {
27022+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27023+ break;
27024+ } else if (probe_kernel_address(instr, opcode))
27025 break;
27026
27027 instr++;
27028@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27029 force_sig_info(si_signo, &info, tsk);
27030 }
27031
27032+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27033+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27034+#endif
27035+
27036+#ifdef CONFIG_PAX_EMUTRAMP
27037+static int pax_handle_fetch_fault(struct pt_regs *regs);
27038+#endif
27039+
27040+#ifdef CONFIG_PAX_PAGEEXEC
27041+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27042+{
27043+ pgd_t *pgd;
27044+ pud_t *pud;
27045+ pmd_t *pmd;
27046+
27047+ pgd = pgd_offset(mm, address);
27048+ if (!pgd_present(*pgd))
27049+ return NULL;
27050+ pud = pud_offset(pgd, address);
27051+ if (!pud_present(*pud))
27052+ return NULL;
27053+ pmd = pmd_offset(pud, address);
27054+ if (!pmd_present(*pmd))
27055+ return NULL;
27056+ return pmd;
27057+}
27058+#endif
27059+
27060 DEFINE_SPINLOCK(pgd_lock);
27061 LIST_HEAD(pgd_list);
27062
27063@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27064 for (address = VMALLOC_START & PMD_MASK;
27065 address >= TASK_SIZE && address < FIXADDR_TOP;
27066 address += PMD_SIZE) {
27067+
27068+#ifdef CONFIG_PAX_PER_CPU_PGD
27069+ unsigned long cpu;
27070+#else
27071 struct page *page;
27072+#endif
27073
27074 spin_lock(&pgd_lock);
27075+
27076+#ifdef CONFIG_PAX_PER_CPU_PGD
27077+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27078+ pgd_t *pgd = get_cpu_pgd(cpu);
27079+ pmd_t *ret;
27080+#else
27081 list_for_each_entry(page, &pgd_list, lru) {
27082+ pgd_t *pgd = page_address(page);
27083 spinlock_t *pgt_lock;
27084 pmd_t *ret;
27085
27086@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
27087 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27088
27089 spin_lock(pgt_lock);
27090- ret = vmalloc_sync_one(page_address(page), address);
27091+#endif
27092+
27093+ ret = vmalloc_sync_one(pgd, address);
27094+
27095+#ifndef CONFIG_PAX_PER_CPU_PGD
27096 spin_unlock(pgt_lock);
27097+#endif
27098
27099 if (!ret)
27100 break;
27101@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27102 * an interrupt in the middle of a task switch..
27103 */
27104 pgd_paddr = read_cr3();
27105+
27106+#ifdef CONFIG_PAX_PER_CPU_PGD
27107+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27108+#endif
27109+
27110 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27111 if (!pmd_k)
27112 return -1;
27113@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27114 * happen within a race in page table update. In the later
27115 * case just flush:
27116 */
27117+
27118+#ifdef CONFIG_PAX_PER_CPU_PGD
27119+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27120+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27121+#else
27122 pgd = pgd_offset(current->active_mm, address);
27123+#endif
27124+
27125 pgd_ref = pgd_offset_k(address);
27126 if (pgd_none(*pgd_ref))
27127 return -1;
27128@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27129 static int is_errata100(struct pt_regs *regs, unsigned long address)
27130 {
27131 #ifdef CONFIG_X86_64
27132- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27133+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27134 return 1;
27135 #endif
27136 return 0;
27137@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27138 }
27139
27140 static const char nx_warning[] = KERN_CRIT
27141-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27142+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27143
27144 static void
27145 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27146@@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27147 if (!oops_may_print())
27148 return;
27149
27150- if (error_code & PF_INSTR) {
27151+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27152 unsigned int level;
27153
27154 pte_t *pte = lookup_address(address, &level);
27155
27156 if (pte && pte_present(*pte) && !pte_exec(*pte))
27157- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27158+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27159 }
27160
27161+#ifdef CONFIG_PAX_KERNEXEC
27162+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27163+ if (current->signal->curr_ip)
27164+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27165+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27166+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27167+ else
27168+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27169+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27170+ }
27171+#endif
27172+
27173 printk(KERN_ALERT "BUG: unable to handle kernel ");
27174 if (address < PAGE_SIZE)
27175 printk(KERN_CONT "NULL pointer dereference");
27176@@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27177 return;
27178 }
27179 #endif
27180+
27181+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27182+ if (pax_is_fetch_fault(regs, error_code, address)) {
27183+
27184+#ifdef CONFIG_PAX_EMUTRAMP
27185+ switch (pax_handle_fetch_fault(regs)) {
27186+ case 2:
27187+ return;
27188+ }
27189+#endif
27190+
27191+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27192+ do_group_exit(SIGKILL);
27193+ }
27194+#endif
27195+
27196 /* Kernel addresses are always protection faults: */
27197 if (address >= TASK_SIZE)
27198 error_code |= PF_PROT;
27199@@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27200 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27201 printk(KERN_ERR
27202 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27203- tsk->comm, tsk->pid, address);
27204+ tsk->comm, task_pid_nr(tsk), address);
27205 code = BUS_MCEERR_AR;
27206 }
27207 #endif
27208@@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27209 return 1;
27210 }
27211
27212+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27213+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27214+{
27215+ pte_t *pte;
27216+ pmd_t *pmd;
27217+ spinlock_t *ptl;
27218+ unsigned char pte_mask;
27219+
27220+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27221+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27222+ return 0;
27223+
27224+ /* PaX: it's our fault, let's handle it if we can */
27225+
27226+ /* PaX: take a look at read faults before acquiring any locks */
27227+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27228+ /* instruction fetch attempt from a protected page in user mode */
27229+ up_read(&mm->mmap_sem);
27230+
27231+#ifdef CONFIG_PAX_EMUTRAMP
27232+ switch (pax_handle_fetch_fault(regs)) {
27233+ case 2:
27234+ return 1;
27235+ }
27236+#endif
27237+
27238+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27239+ do_group_exit(SIGKILL);
27240+ }
27241+
27242+ pmd = pax_get_pmd(mm, address);
27243+ if (unlikely(!pmd))
27244+ return 0;
27245+
27246+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27247+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27248+ pte_unmap_unlock(pte, ptl);
27249+ return 0;
27250+ }
27251+
27252+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27253+ /* write attempt to a protected page in user mode */
27254+ pte_unmap_unlock(pte, ptl);
27255+ return 0;
27256+ }
27257+
27258+#ifdef CONFIG_SMP
27259+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27260+#else
27261+ if (likely(address > get_limit(regs->cs)))
27262+#endif
27263+ {
27264+ set_pte(pte, pte_mkread(*pte));
27265+ __flush_tlb_one(address);
27266+ pte_unmap_unlock(pte, ptl);
27267+ up_read(&mm->mmap_sem);
27268+ return 1;
27269+ }
27270+
27271+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27272+
27273+ /*
27274+ * PaX: fill DTLB with user rights and retry
27275+ */
27276+ __asm__ __volatile__ (
27277+ "orb %2,(%1)\n"
27278+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27279+/*
27280+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27281+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27282+ * page fault when examined during a TLB load attempt. this is true not only
27283+ * for PTEs holding a non-present entry but also present entries that will
27284+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27285+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27286+ * for our target pages since their PTEs are simply not in the TLBs at all.
27287+
27288+ * the best thing in omitting it is that we gain around 15-20% speed in the
27289+ * fast path of the page fault handler and can get rid of tracing since we
27290+ * can no longer flush unintended entries.
27291+ */
27292+ "invlpg (%0)\n"
27293+#endif
27294+ __copyuser_seg"testb $0,(%0)\n"
27295+ "xorb %3,(%1)\n"
27296+ :
27297+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27298+ : "memory", "cc");
27299+ pte_unmap_unlock(pte, ptl);
27300+ up_read(&mm->mmap_sem);
27301+ return 1;
27302+}
27303+#endif
27304+
27305 /*
27306 * Handle a spurious fault caused by a stale TLB entry.
27307 *
27308@@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
27309 static inline int
27310 access_error(unsigned long error_code, struct vm_area_struct *vma)
27311 {
27312+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27313+ return 1;
27314+
27315 if (error_code & PF_WRITE) {
27316 /* write, present and write, not present: */
27317 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27318@@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27319 if (error_code & PF_USER)
27320 return false;
27321
27322- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27323+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27324 return false;
27325
27326 return true;
27327@@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27328 {
27329 struct vm_area_struct *vma;
27330 struct task_struct *tsk;
27331- unsigned long address;
27332 struct mm_struct *mm;
27333 int fault;
27334 int write = error_code & PF_WRITE;
27335 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27336 (write ? FAULT_FLAG_WRITE : 0);
27337
27338- tsk = current;
27339- mm = tsk->mm;
27340-
27341 /* Get the faulting address: */
27342- address = read_cr2();
27343+ unsigned long address = read_cr2();
27344+
27345+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27346+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
27347+ if (!search_exception_tables(regs->ip)) {
27348+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27349+ bad_area_nosemaphore(regs, error_code, address);
27350+ return;
27351+ }
27352+ if (address < PAX_USER_SHADOW_BASE) {
27353+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27354+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27355+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27356+ } else
27357+ address -= PAX_USER_SHADOW_BASE;
27358+ }
27359+#endif
27360+
27361+ tsk = current;
27362+ mm = tsk->mm;
27363
27364 /*
27365 * Detect and handle instructions that would cause a page fault for
27366@@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27367 * User-mode registers count as a user access even for any
27368 * potential system fault or CPU buglet:
27369 */
27370- if (user_mode_vm(regs)) {
27371+ if (user_mode(regs)) {
27372 local_irq_enable();
27373 error_code |= PF_USER;
27374 } else {
27375@@ -1146,6 +1355,11 @@ retry:
27376 might_sleep();
27377 }
27378
27379+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27380+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27381+ return;
27382+#endif
27383+
27384 vma = find_vma(mm, address);
27385 if (unlikely(!vma)) {
27386 bad_area(regs, error_code, address);
27387@@ -1157,18 +1371,24 @@ retry:
27388 bad_area(regs, error_code, address);
27389 return;
27390 }
27391- if (error_code & PF_USER) {
27392- /*
27393- * Accessing the stack below %sp is always a bug.
27394- * The large cushion allows instructions like enter
27395- * and pusha to work. ("enter $65535, $31" pushes
27396- * 32 pointers and then decrements %sp by 65535.)
27397- */
27398- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27399- bad_area(regs, error_code, address);
27400- return;
27401- }
27402+ /*
27403+ * Accessing the stack below %sp is always a bug.
27404+ * The large cushion allows instructions like enter
27405+ * and pusha to work. ("enter $65535, $31" pushes
27406+ * 32 pointers and then decrements %sp by 65535.)
27407+ */
27408+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27409+ bad_area(regs, error_code, address);
27410+ return;
27411 }
27412+
27413+#ifdef CONFIG_PAX_SEGMEXEC
27414+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27415+ bad_area(regs, error_code, address);
27416+ return;
27417+ }
27418+#endif
27419+
27420 if (unlikely(expand_stack(vma, address))) {
27421 bad_area(regs, error_code, address);
27422 return;
27423@@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27424 __do_page_fault(regs, error_code);
27425 exception_exit(regs);
27426 }
27427+
27428+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27429+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27430+{
27431+ struct mm_struct *mm = current->mm;
27432+ unsigned long ip = regs->ip;
27433+
27434+ if (v8086_mode(regs))
27435+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27436+
27437+#ifdef CONFIG_PAX_PAGEEXEC
27438+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27439+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27440+ return true;
27441+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27442+ return true;
27443+ return false;
27444+ }
27445+#endif
27446+
27447+#ifdef CONFIG_PAX_SEGMEXEC
27448+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27449+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27450+ return true;
27451+ return false;
27452+ }
27453+#endif
27454+
27455+ return false;
27456+}
27457+#endif
27458+
27459+#ifdef CONFIG_PAX_EMUTRAMP
27460+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27461+{
27462+ int err;
27463+
27464+ do { /* PaX: libffi trampoline emulation */
27465+ unsigned char mov, jmp;
27466+ unsigned int addr1, addr2;
27467+
27468+#ifdef CONFIG_X86_64
27469+ if ((regs->ip + 9) >> 32)
27470+ break;
27471+#endif
27472+
27473+ err = get_user(mov, (unsigned char __user *)regs->ip);
27474+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27475+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27476+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27477+
27478+ if (err)
27479+ break;
27480+
27481+ if (mov == 0xB8 && jmp == 0xE9) {
27482+ regs->ax = addr1;
27483+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27484+ return 2;
27485+ }
27486+ } while (0);
27487+
27488+ do { /* PaX: gcc trampoline emulation #1 */
27489+ unsigned char mov1, mov2;
27490+ unsigned short jmp;
27491+ unsigned int addr1, addr2;
27492+
27493+#ifdef CONFIG_X86_64
27494+ if ((regs->ip + 11) >> 32)
27495+ break;
27496+#endif
27497+
27498+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27499+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27500+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27501+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27502+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27503+
27504+ if (err)
27505+ break;
27506+
27507+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27508+ regs->cx = addr1;
27509+ regs->ax = addr2;
27510+ regs->ip = addr2;
27511+ return 2;
27512+ }
27513+ } while (0);
27514+
27515+ do { /* PaX: gcc trampoline emulation #2 */
27516+ unsigned char mov, jmp;
27517+ unsigned int addr1, addr2;
27518+
27519+#ifdef CONFIG_X86_64
27520+ if ((regs->ip + 9) >> 32)
27521+ break;
27522+#endif
27523+
27524+ err = get_user(mov, (unsigned char __user *)regs->ip);
27525+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27526+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27527+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27528+
27529+ if (err)
27530+ break;
27531+
27532+ if (mov == 0xB9 && jmp == 0xE9) {
27533+ regs->cx = addr1;
27534+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27535+ return 2;
27536+ }
27537+ } while (0);
27538+
27539+ return 1; /* PaX in action */
27540+}
27541+
27542+#ifdef CONFIG_X86_64
27543+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27544+{
27545+ int err;
27546+
27547+ do { /* PaX: libffi trampoline emulation */
27548+ unsigned short mov1, mov2, jmp1;
27549+ unsigned char stcclc, jmp2;
27550+ unsigned long addr1, addr2;
27551+
27552+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27553+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27554+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27555+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27556+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27557+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27558+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27559+
27560+ if (err)
27561+ break;
27562+
27563+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27564+ regs->r11 = addr1;
27565+ regs->r10 = addr2;
27566+ if (stcclc == 0xF8)
27567+ regs->flags &= ~X86_EFLAGS_CF;
27568+ else
27569+ regs->flags |= X86_EFLAGS_CF;
27570+ regs->ip = addr1;
27571+ return 2;
27572+ }
27573+ } while (0);
27574+
27575+ do { /* PaX: gcc trampoline emulation #1 */
27576+ unsigned short mov1, mov2, jmp1;
27577+ unsigned char jmp2;
27578+ unsigned int addr1;
27579+ unsigned long addr2;
27580+
27581+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27582+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27583+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27584+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27585+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27586+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27587+
27588+ if (err)
27589+ break;
27590+
27591+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27592+ regs->r11 = addr1;
27593+ regs->r10 = addr2;
27594+ regs->ip = addr1;
27595+ return 2;
27596+ }
27597+ } while (0);
27598+
27599+ do { /* PaX: gcc trampoline emulation #2 */
27600+ unsigned short mov1, mov2, jmp1;
27601+ unsigned char jmp2;
27602+ unsigned long addr1, addr2;
27603+
27604+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27605+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27606+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27607+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27608+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27609+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27610+
27611+ if (err)
27612+ break;
27613+
27614+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27615+ regs->r11 = addr1;
27616+ regs->r10 = addr2;
27617+ regs->ip = addr1;
27618+ return 2;
27619+ }
27620+ } while (0);
27621+
27622+ return 1; /* PaX in action */
27623+}
27624+#endif
27625+
27626+/*
27627+ * PaX: decide what to do with offenders (regs->ip = fault address)
27628+ *
27629+ * returns 1 when task should be killed
27630+ * 2 when gcc trampoline was detected
27631+ */
27632+static int pax_handle_fetch_fault(struct pt_regs *regs)
27633+{
27634+ if (v8086_mode(regs))
27635+ return 1;
27636+
27637+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27638+ return 1;
27639+
27640+#ifdef CONFIG_X86_32
27641+ return pax_handle_fetch_fault_32(regs);
27642+#else
27643+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27644+ return pax_handle_fetch_fault_32(regs);
27645+ else
27646+ return pax_handle_fetch_fault_64(regs);
27647+#endif
27648+}
27649+#endif
27650+
27651+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27652+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27653+{
27654+ long i;
27655+
27656+ printk(KERN_ERR "PAX: bytes at PC: ");
27657+ for (i = 0; i < 20; i++) {
27658+ unsigned char c;
27659+ if (get_user(c, (unsigned char __force_user *)pc+i))
27660+ printk(KERN_CONT "?? ");
27661+ else
27662+ printk(KERN_CONT "%02x ", c);
27663+ }
27664+ printk("\n");
27665+
27666+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27667+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27668+ unsigned long c;
27669+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27670+#ifdef CONFIG_X86_32
27671+ printk(KERN_CONT "???????? ");
27672+#else
27673+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27674+ printk(KERN_CONT "???????? ???????? ");
27675+ else
27676+ printk(KERN_CONT "???????????????? ");
27677+#endif
27678+ } else {
27679+#ifdef CONFIG_X86_64
27680+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27681+ printk(KERN_CONT "%08x ", (unsigned int)c);
27682+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27683+ } else
27684+#endif
27685+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27686+ }
27687+ }
27688+ printk("\n");
27689+}
27690+#endif
27691+
27692+/**
27693+ * probe_kernel_write(): safely attempt to write to a location
27694+ * @dst: address to write to
27695+ * @src: pointer to the data that shall be written
27696+ * @size: size of the data chunk
27697+ *
27698+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27699+ * happens, handle that and return -EFAULT.
27700+ */
27701+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27702+{
27703+ long ret;
27704+ mm_segment_t old_fs = get_fs();
27705+
27706+ set_fs(KERNEL_DS);
27707+ pagefault_disable();
27708+ pax_open_kernel();
27709+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27710+ pax_close_kernel();
27711+ pagefault_enable();
27712+ set_fs(old_fs);
27713+
27714+ return ret ? -EFAULT : 0;
27715+}
27716diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27717index dd74e46..7d26398 100644
27718--- a/arch/x86/mm/gup.c
27719+++ b/arch/x86/mm/gup.c
27720@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27721 addr = start;
27722 len = (unsigned long) nr_pages << PAGE_SHIFT;
27723 end = start + len;
27724- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27725+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27726 (void __user *)start, len)))
27727 return 0;
27728
27729diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27730index 6f31ee5..8ee4164 100644
27731--- a/arch/x86/mm/highmem_32.c
27732+++ b/arch/x86/mm/highmem_32.c
27733@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27734 idx = type + KM_TYPE_NR*smp_processor_id();
27735 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27736 BUG_ON(!pte_none(*(kmap_pte-idx)));
27737+
27738+ pax_open_kernel();
27739 set_pte(kmap_pte-idx, mk_pte(page, prot));
27740+ pax_close_kernel();
27741+
27742 arch_flush_lazy_mmu_mode();
27743
27744 return (void *)vaddr;
27745diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27746index ae1aa71..56316db 100644
27747--- a/arch/x86/mm/hugetlbpage.c
27748+++ b/arch/x86/mm/hugetlbpage.c
27749@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27750 info.flags = 0;
27751 info.length = len;
27752 info.low_limit = TASK_UNMAPPED_BASE;
27753+
27754+#ifdef CONFIG_PAX_RANDMMAP
27755+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27756+ info.low_limit += current->mm->delta_mmap;
27757+#endif
27758+
27759 info.high_limit = TASK_SIZE;
27760 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27761 info.align_offset = 0;
27762@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27763 VM_BUG_ON(addr != -ENOMEM);
27764 info.flags = 0;
27765 info.low_limit = TASK_UNMAPPED_BASE;
27766+
27767+#ifdef CONFIG_PAX_RANDMMAP
27768+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27769+ info.low_limit += current->mm->delta_mmap;
27770+#endif
27771+
27772 info.high_limit = TASK_SIZE;
27773 addr = vm_unmapped_area(&info);
27774 }
27775@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27776 struct hstate *h = hstate_file(file);
27777 struct mm_struct *mm = current->mm;
27778 struct vm_area_struct *vma;
27779+ unsigned long pax_task_size = TASK_SIZE;
27780+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27781
27782 if (len & ~huge_page_mask(h))
27783 return -EINVAL;
27784- if (len > TASK_SIZE)
27785+
27786+#ifdef CONFIG_PAX_SEGMEXEC
27787+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27788+ pax_task_size = SEGMEXEC_TASK_SIZE;
27789+#endif
27790+
27791+ pax_task_size -= PAGE_SIZE;
27792+
27793+ if (len > pax_task_size)
27794 return -ENOMEM;
27795
27796 if (flags & MAP_FIXED) {
27797@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27798 return addr;
27799 }
27800
27801+#ifdef CONFIG_PAX_RANDMMAP
27802+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27803+#endif
27804+
27805 if (addr) {
27806 addr = ALIGN(addr, huge_page_size(h));
27807 vma = find_vma(mm, addr);
27808- if (TASK_SIZE - len >= addr &&
27809- (!vma || addr + len <= vma->vm_start))
27810+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27811 return addr;
27812 }
27813 if (mm->get_unmapped_area == arch_get_unmapped_area)
27814diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27815index d7aea41..0fc945b 100644
27816--- a/arch/x86/mm/init.c
27817+++ b/arch/x86/mm/init.c
27818@@ -4,6 +4,7 @@
27819 #include <linux/swap.h>
27820 #include <linux/memblock.h>
27821 #include <linux/bootmem.h> /* for max_low_pfn */
27822+#include <linux/tboot.h>
27823
27824 #include <asm/cacheflush.h>
27825 #include <asm/e820.h>
27826@@ -16,6 +17,8 @@
27827 #include <asm/tlb.h>
27828 #include <asm/proto.h>
27829 #include <asm/dma.h> /* for MAX_DMA_PFN */
27830+#include <asm/desc.h>
27831+#include <asm/bios_ebda.h>
27832
27833 unsigned long __initdata pgt_buf_start;
27834 unsigned long __meminitdata pgt_buf_end;
27835@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27836 {
27837 int i;
27838 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27839- unsigned long start = 0, good_end;
27840+ unsigned long start = 0x100000, good_end;
27841 phys_addr_t base;
27842
27843 for (i = 0; i < nr_range; i++) {
27844@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27845 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27846 * mmio resources as well as potential bios/acpi data regions.
27847 */
27848+
27849+#ifdef CONFIG_GRKERNSEC_KMEM
27850+static unsigned int ebda_start __read_only;
27851+static unsigned int ebda_end __read_only;
27852+#endif
27853+
27854 int devmem_is_allowed(unsigned long pagenr)
27855 {
27856- if (pagenr < 256)
27857+#ifdef CONFIG_GRKERNSEC_KMEM
27858+ /* allow BDA */
27859+ if (!pagenr)
27860 return 1;
27861+ /* allow EBDA */
27862+ if (pagenr >= ebda_start && pagenr < ebda_end)
27863+ return 1;
27864+ /* if tboot is in use, allow access to its hardcoded serial log range */
27865+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27866+ return 1;
27867+#else
27868+ if (!pagenr)
27869+ return 1;
27870+#ifdef CONFIG_VM86
27871+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27872+ return 1;
27873+#endif
27874+#endif
27875+
27876+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27877+ return 1;
27878+#ifdef CONFIG_GRKERNSEC_KMEM
27879+ /* throw out everything else below 1MB */
27880+ if (pagenr <= 256)
27881+ return 0;
27882+#endif
27883 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
27884 return 0;
27885 if (!page_is_ram(pagenr))
27886@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
27887 #endif
27888 }
27889
27890+#ifdef CONFIG_GRKERNSEC_KMEM
27891+static inline void gr_init_ebda(void)
27892+{
27893+ unsigned int ebda_addr;
27894+ unsigned int ebda_size = 0;
27895+
27896+ ebda_addr = get_bios_ebda();
27897+ if (ebda_addr) {
27898+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
27899+ ebda_size <<= 10;
27900+ }
27901+ if (ebda_addr && ebda_size) {
27902+ ebda_start = ebda_addr >> PAGE_SHIFT;
27903+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
27904+ } else {
27905+ ebda_start = 0x9f000 >> PAGE_SHIFT;
27906+ ebda_end = 0xa0000 >> PAGE_SHIFT;
27907+ }
27908+}
27909+#else
27910+static inline void gr_init_ebda(void) { }
27911+#endif
27912+
27913 void free_initmem(void)
27914 {
27915+#ifdef CONFIG_PAX_KERNEXEC
27916+#ifdef CONFIG_X86_32
27917+ /* PaX: limit KERNEL_CS to actual size */
27918+ unsigned long addr, limit;
27919+ struct desc_struct d;
27920+ int cpu;
27921+#else
27922+ pgd_t *pgd;
27923+ pud_t *pud;
27924+ pmd_t *pmd;
27925+ unsigned long addr, end;
27926+#endif
27927+#endif
27928+
27929+ gr_init_ebda();
27930+
27931+#ifdef CONFIG_PAX_KERNEXEC
27932+#ifdef CONFIG_X86_32
27933+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
27934+ limit = (limit - 1UL) >> PAGE_SHIFT;
27935+
27936+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
27937+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27938+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
27939+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
27940+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
27941+ }
27942+
27943+ /* PaX: make KERNEL_CS read-only */
27944+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
27945+ if (!paravirt_enabled())
27946+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
27947+/*
27948+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
27949+ pgd = pgd_offset_k(addr);
27950+ pud = pud_offset(pgd, addr);
27951+ pmd = pmd_offset(pud, addr);
27952+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27953+ }
27954+*/
27955+#ifdef CONFIG_X86_PAE
27956+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
27957+/*
27958+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
27959+ pgd = pgd_offset_k(addr);
27960+ pud = pud_offset(pgd, addr);
27961+ pmd = pmd_offset(pud, addr);
27962+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27963+ }
27964+*/
27965+#endif
27966+
27967+#ifdef CONFIG_MODULES
27968+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
27969+#endif
27970+
27971+#else
27972+ /* PaX: make kernel code/rodata read-only, rest non-executable */
27973+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
27974+ pgd = pgd_offset_k(addr);
27975+ pud = pud_offset(pgd, addr);
27976+ pmd = pmd_offset(pud, addr);
27977+ if (!pmd_present(*pmd))
27978+ continue;
27979+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
27980+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27981+ else
27982+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27983+ }
27984+
27985+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
27986+ end = addr + KERNEL_IMAGE_SIZE;
27987+ for (; addr < end; addr += PMD_SIZE) {
27988+ pgd = pgd_offset_k(addr);
27989+ pud = pud_offset(pgd, addr);
27990+ pmd = pmd_offset(pud, addr);
27991+ if (!pmd_present(*pmd))
27992+ continue;
27993+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
27994+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27995+ }
27996+#endif
27997+
27998+ flush_tlb_all();
27999+#endif
28000+
28001 free_init_pages("unused kernel memory",
28002 (unsigned long)(&__init_begin),
28003 (unsigned long)(&__init_end));
28004diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28005index 745d66b..56bf568 100644
28006--- a/arch/x86/mm/init_32.c
28007+++ b/arch/x86/mm/init_32.c
28008@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
28009 }
28010
28011 /*
28012- * Creates a middle page table and puts a pointer to it in the
28013- * given global directory entry. This only returns the gd entry
28014- * in non-PAE compilation mode, since the middle layer is folded.
28015- */
28016-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28017-{
28018- pud_t *pud;
28019- pmd_t *pmd_table;
28020-
28021-#ifdef CONFIG_X86_PAE
28022- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28023- if (after_bootmem)
28024- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
28025- else
28026- pmd_table = (pmd_t *)alloc_low_page();
28027- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28028- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28029- pud = pud_offset(pgd, 0);
28030- BUG_ON(pmd_table != pmd_offset(pud, 0));
28031-
28032- return pmd_table;
28033- }
28034-#endif
28035- pud = pud_offset(pgd, 0);
28036- pmd_table = pmd_offset(pud, 0);
28037-
28038- return pmd_table;
28039-}
28040-
28041-/*
28042 * Create a page table and place a pointer to it in a middle page
28043 * directory entry:
28044 */
28045@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28046 page_table = (pte_t *)alloc_low_page();
28047
28048 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28049+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28050+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28051+#else
28052 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28053+#endif
28054 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28055 }
28056
28057 return pte_offset_kernel(pmd, 0);
28058 }
28059
28060+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28061+{
28062+ pud_t *pud;
28063+ pmd_t *pmd_table;
28064+
28065+ pud = pud_offset(pgd, 0);
28066+ pmd_table = pmd_offset(pud, 0);
28067+
28068+ return pmd_table;
28069+}
28070+
28071 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28072 {
28073 int pgd_idx = pgd_index(vaddr);
28074@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28075 int pgd_idx, pmd_idx;
28076 unsigned long vaddr;
28077 pgd_t *pgd;
28078+ pud_t *pud;
28079 pmd_t *pmd;
28080 pte_t *pte = NULL;
28081
28082@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28083 pgd = pgd_base + pgd_idx;
28084
28085 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28086- pmd = one_md_table_init(pgd);
28087- pmd = pmd + pmd_index(vaddr);
28088+ pud = pud_offset(pgd, vaddr);
28089+ pmd = pmd_offset(pud, vaddr);
28090+
28091+#ifdef CONFIG_X86_PAE
28092+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28093+#endif
28094+
28095 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28096 pmd++, pmd_idx++) {
28097 pte = page_table_kmap_check(one_page_table_init(pmd),
28098@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28099 }
28100 }
28101
28102-static inline int is_kernel_text(unsigned long addr)
28103+static inline int is_kernel_text(unsigned long start, unsigned long end)
28104 {
28105- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28106- return 1;
28107- return 0;
28108+ if ((start > ktla_ktva((unsigned long)_etext) ||
28109+ end <= ktla_ktva((unsigned long)_stext)) &&
28110+ (start > ktla_ktva((unsigned long)_einittext) ||
28111+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28112+
28113+#ifdef CONFIG_ACPI_SLEEP
28114+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28115+#endif
28116+
28117+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28118+ return 0;
28119+ return 1;
28120 }
28121
28122 /*
28123@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
28124 unsigned long last_map_addr = end;
28125 unsigned long start_pfn, end_pfn;
28126 pgd_t *pgd_base = swapper_pg_dir;
28127- int pgd_idx, pmd_idx, pte_ofs;
28128+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28129 unsigned long pfn;
28130 pgd_t *pgd;
28131+ pud_t *pud;
28132 pmd_t *pmd;
28133 pte_t *pte;
28134 unsigned pages_2m, pages_4k;
28135@@ -280,8 +281,13 @@ repeat:
28136 pfn = start_pfn;
28137 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28138 pgd = pgd_base + pgd_idx;
28139- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28140- pmd = one_md_table_init(pgd);
28141+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28142+ pud = pud_offset(pgd, 0);
28143+ pmd = pmd_offset(pud, 0);
28144+
28145+#ifdef CONFIG_X86_PAE
28146+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28147+#endif
28148
28149 if (pfn >= end_pfn)
28150 continue;
28151@@ -293,14 +299,13 @@ repeat:
28152 #endif
28153 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28154 pmd++, pmd_idx++) {
28155- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28156+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28157
28158 /*
28159 * Map with big pages if possible, otherwise
28160 * create normal page tables:
28161 */
28162 if (use_pse) {
28163- unsigned int addr2;
28164 pgprot_t prot = PAGE_KERNEL_LARGE;
28165 /*
28166 * first pass will use the same initial
28167@@ -310,11 +315,7 @@ repeat:
28168 __pgprot(PTE_IDENT_ATTR |
28169 _PAGE_PSE);
28170
28171- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28172- PAGE_OFFSET + PAGE_SIZE-1;
28173-
28174- if (is_kernel_text(addr) ||
28175- is_kernel_text(addr2))
28176+ if (is_kernel_text(address, address + PMD_SIZE))
28177 prot = PAGE_KERNEL_LARGE_EXEC;
28178
28179 pages_2m++;
28180@@ -331,7 +332,7 @@ repeat:
28181 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28182 pte += pte_ofs;
28183 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28184- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28185+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28186 pgprot_t prot = PAGE_KERNEL;
28187 /*
28188 * first pass will use the same initial
28189@@ -339,7 +340,7 @@ repeat:
28190 */
28191 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28192
28193- if (is_kernel_text(addr))
28194+ if (is_kernel_text(address, address + PAGE_SIZE))
28195 prot = PAGE_KERNEL_EXEC;
28196
28197 pages_4k++;
28198@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
28199
28200 pud = pud_offset(pgd, va);
28201 pmd = pmd_offset(pud, va);
28202- if (!pmd_present(*pmd))
28203+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
28204 break;
28205
28206 pte = pte_offset_kernel(pmd, va);
28207@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
28208
28209 static void __init pagetable_init(void)
28210 {
28211- pgd_t *pgd_base = swapper_pg_dir;
28212-
28213- permanent_kmaps_init(pgd_base);
28214+ permanent_kmaps_init(swapper_pg_dir);
28215 }
28216
28217-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28218+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28219 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28220
28221 /* user-defined highmem size */
28222@@ -728,6 +727,12 @@ void __init mem_init(void)
28223
28224 pci_iommu_alloc();
28225
28226+#ifdef CONFIG_PAX_PER_CPU_PGD
28227+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28228+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28229+ KERNEL_PGD_PTRS);
28230+#endif
28231+
28232 #ifdef CONFIG_FLATMEM
28233 BUG_ON(!mem_map);
28234 #endif
28235@@ -754,7 +759,7 @@ void __init mem_init(void)
28236 reservedpages++;
28237
28238 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28239- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28240+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28241 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28242
28243 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28244@@ -795,10 +800,10 @@ void __init mem_init(void)
28245 ((unsigned long)&__init_end -
28246 (unsigned long)&__init_begin) >> 10,
28247
28248- (unsigned long)&_etext, (unsigned long)&_edata,
28249- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28250+ (unsigned long)&_sdata, (unsigned long)&_edata,
28251+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28252
28253- (unsigned long)&_text, (unsigned long)&_etext,
28254+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28255 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28256
28257 /*
28258@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
28259 if (!kernel_set_to_readonly)
28260 return;
28261
28262+ start = ktla_ktva(start);
28263 pr_debug("Set kernel text: %lx - %lx for read write\n",
28264 start, start+size);
28265
28266@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
28267 if (!kernel_set_to_readonly)
28268 return;
28269
28270+ start = ktla_ktva(start);
28271 pr_debug("Set kernel text: %lx - %lx for read only\n",
28272 start, start+size);
28273
28274@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
28275 unsigned long start = PFN_ALIGN(_text);
28276 unsigned long size = PFN_ALIGN(_etext) - start;
28277
28278+ start = ktla_ktva(start);
28279 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28280 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28281 size >> 10);
28282diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28283index 75c9a6a..498d677 100644
28284--- a/arch/x86/mm/init_64.c
28285+++ b/arch/x86/mm/init_64.c
28286@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28287 * around without checking the pgd every time.
28288 */
28289
28290-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28291+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28292 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28293
28294 int force_personality32;
28295@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28296
28297 for (address = start; address <= end; address += PGDIR_SIZE) {
28298 const pgd_t *pgd_ref = pgd_offset_k(address);
28299+
28300+#ifdef CONFIG_PAX_PER_CPU_PGD
28301+ unsigned long cpu;
28302+#else
28303 struct page *page;
28304+#endif
28305
28306 if (pgd_none(*pgd_ref))
28307 continue;
28308
28309 spin_lock(&pgd_lock);
28310+
28311+#ifdef CONFIG_PAX_PER_CPU_PGD
28312+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28313+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28314+#else
28315 list_for_each_entry(page, &pgd_list, lru) {
28316 pgd_t *pgd;
28317 spinlock_t *pgt_lock;
28318@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28319 /* the pgt_lock only for Xen */
28320 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28321 spin_lock(pgt_lock);
28322+#endif
28323
28324 if (pgd_none(*pgd))
28325 set_pgd(pgd, *pgd_ref);
28326@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28327 BUG_ON(pgd_page_vaddr(*pgd)
28328 != pgd_page_vaddr(*pgd_ref));
28329
28330+#ifndef CONFIG_PAX_PER_CPU_PGD
28331 spin_unlock(pgt_lock);
28332+#endif
28333+
28334 }
28335 spin_unlock(&pgd_lock);
28336 }
28337@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28338 {
28339 if (pgd_none(*pgd)) {
28340 pud_t *pud = (pud_t *)spp_getpage();
28341- pgd_populate(&init_mm, pgd, pud);
28342+ pgd_populate_kernel(&init_mm, pgd, pud);
28343 if (pud != pud_offset(pgd, 0))
28344 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28345 pud, pud_offset(pgd, 0));
28346@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28347 {
28348 if (pud_none(*pud)) {
28349 pmd_t *pmd = (pmd_t *) spp_getpage();
28350- pud_populate(&init_mm, pud, pmd);
28351+ pud_populate_kernel(&init_mm, pud, pmd);
28352 if (pmd != pmd_offset(pud, 0))
28353 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28354 pmd, pmd_offset(pud, 0));
28355@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28356 pmd = fill_pmd(pud, vaddr);
28357 pte = fill_pte(pmd, vaddr);
28358
28359+ pax_open_kernel();
28360 set_pte(pte, new_pte);
28361+ pax_close_kernel();
28362
28363 /*
28364 * It's enough to flush this one mapping.
28365@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28366 pgd = pgd_offset_k((unsigned long)__va(phys));
28367 if (pgd_none(*pgd)) {
28368 pud = (pud_t *) spp_getpage();
28369- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28370- _PAGE_USER));
28371+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28372 }
28373 pud = pud_offset(pgd, (unsigned long)__va(phys));
28374 if (pud_none(*pud)) {
28375 pmd = (pmd_t *) spp_getpage();
28376- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28377- _PAGE_USER));
28378+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28379 }
28380 pmd = pmd_offset(pud, phys);
28381 BUG_ON(!pmd_none(*pmd));
28382@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28383 if (pfn >= pgt_buf_top)
28384 panic("alloc_low_page: ran out of memory");
28385
28386- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28387+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28388 clear_page(adr);
28389 *phys = pfn * PAGE_SIZE;
28390 return adr;
28391@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28392
28393 phys = __pa(virt);
28394 left = phys & (PAGE_SIZE - 1);
28395- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28396+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28397 adr = (void *)(((unsigned long)adr) | left);
28398
28399 return adr;
28400@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28401 unmap_low_page(pmd);
28402
28403 spin_lock(&init_mm.page_table_lock);
28404- pud_populate(&init_mm, pud, __va(pmd_phys));
28405+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28406 spin_unlock(&init_mm.page_table_lock);
28407 }
28408 __flush_tlb_all();
28409@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28410 unmap_low_page(pud);
28411
28412 spin_lock(&init_mm.page_table_lock);
28413- pgd_populate(&init_mm, pgd, __va(pud_phys));
28414+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28415 spin_unlock(&init_mm.page_table_lock);
28416 pgd_changed = true;
28417 }
28418@@ -693,6 +707,12 @@ void __init mem_init(void)
28419
28420 pci_iommu_alloc();
28421
28422+#ifdef CONFIG_PAX_PER_CPU_PGD
28423+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28424+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28425+ KERNEL_PGD_PTRS);
28426+#endif
28427+
28428 /* clear_bss() already clear the empty_zero_page */
28429
28430 reservedpages = 0;
28431@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28432 static struct vm_area_struct gate_vma = {
28433 .vm_start = VSYSCALL_START,
28434 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28435- .vm_page_prot = PAGE_READONLY_EXEC,
28436- .vm_flags = VM_READ | VM_EXEC
28437+ .vm_page_prot = PAGE_READONLY,
28438+ .vm_flags = VM_READ
28439 };
28440
28441 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28442@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28443
28444 const char *arch_vma_name(struct vm_area_struct *vma)
28445 {
28446- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28447+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28448 return "[vdso]";
28449 if (vma == &gate_vma)
28450 return "[vsyscall]";
28451diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28452index 7b179b4..6bd1777 100644
28453--- a/arch/x86/mm/iomap_32.c
28454+++ b/arch/x86/mm/iomap_32.c
28455@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28456 type = kmap_atomic_idx_push();
28457 idx = type + KM_TYPE_NR * smp_processor_id();
28458 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28459+
28460+ pax_open_kernel();
28461 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28462+ pax_close_kernel();
28463+
28464 arch_flush_lazy_mmu_mode();
28465
28466 return (void *)vaddr;
28467diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28468index 78fe3f1..2f9433c 100644
28469--- a/arch/x86/mm/ioremap.c
28470+++ b/arch/x86/mm/ioremap.c
28471@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28472 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28473 int is_ram = page_is_ram(pfn);
28474
28475- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28476+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28477 return NULL;
28478 WARN_ON_ONCE(is_ram);
28479 }
28480@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28481 *
28482 * Caller must ensure there is only one unmapping for the same pointer.
28483 */
28484-void iounmap(volatile void __iomem *addr)
28485+void iounmap(const volatile void __iomem *addr)
28486 {
28487 struct vm_struct *p, *o;
28488
28489@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28490
28491 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28492 if (page_is_ram(start >> PAGE_SHIFT))
28493+#ifdef CONFIG_HIGHMEM
28494+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28495+#endif
28496 return __va(phys);
28497
28498 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28499@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
28500 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28501
28502 static __initdata int after_paging_init;
28503-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28504+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28505
28506 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28507 {
28508@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
28509 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28510
28511 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28512- memset(bm_pte, 0, sizeof(bm_pte));
28513- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28514+ pmd_populate_user(&init_mm, pmd, bm_pte);
28515
28516 /*
28517 * The boot-ioremap range spans multiple pmds, for which
28518diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28519index d87dd6d..bf3fa66 100644
28520--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28521+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28522@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28523 * memory (e.g. tracked pages)? For now, we need this to avoid
28524 * invoking kmemcheck for PnP BIOS calls.
28525 */
28526- if (regs->flags & X86_VM_MASK)
28527+ if (v8086_mode(regs))
28528 return false;
28529- if (regs->cs != __KERNEL_CS)
28530+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28531 return false;
28532
28533 pte = kmemcheck_pte_lookup(address);
28534diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28535index 845df68..1d8d29f 100644
28536--- a/arch/x86/mm/mmap.c
28537+++ b/arch/x86/mm/mmap.c
28538@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28539 * Leave an at least ~128 MB hole with possible stack randomization.
28540 */
28541 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28542-#define MAX_GAP (TASK_SIZE/6*5)
28543+#define MAX_GAP (pax_task_size/6*5)
28544
28545 static int mmap_is_legacy(void)
28546 {
28547@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28548 return rnd << PAGE_SHIFT;
28549 }
28550
28551-static unsigned long mmap_base(void)
28552+static unsigned long mmap_base(struct mm_struct *mm)
28553 {
28554 unsigned long gap = rlimit(RLIMIT_STACK);
28555+ unsigned long pax_task_size = TASK_SIZE;
28556+
28557+#ifdef CONFIG_PAX_SEGMEXEC
28558+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28559+ pax_task_size = SEGMEXEC_TASK_SIZE;
28560+#endif
28561
28562 if (gap < MIN_GAP)
28563 gap = MIN_GAP;
28564 else if (gap > MAX_GAP)
28565 gap = MAX_GAP;
28566
28567- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28568+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28569 }
28570
28571 /*
28572 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28573 * does, but not when emulating X86_32
28574 */
28575-static unsigned long mmap_legacy_base(void)
28576+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28577 {
28578- if (mmap_is_ia32())
28579+ if (mmap_is_ia32()) {
28580+
28581+#ifdef CONFIG_PAX_SEGMEXEC
28582+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28583+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28584+ else
28585+#endif
28586+
28587 return TASK_UNMAPPED_BASE;
28588- else
28589+ } else
28590 return TASK_UNMAPPED_BASE + mmap_rnd();
28591 }
28592
28593@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28594 void arch_pick_mmap_layout(struct mm_struct *mm)
28595 {
28596 if (mmap_is_legacy()) {
28597- mm->mmap_base = mmap_legacy_base();
28598+ mm->mmap_base = mmap_legacy_base(mm);
28599+
28600+#ifdef CONFIG_PAX_RANDMMAP
28601+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28602+ mm->mmap_base += mm->delta_mmap;
28603+#endif
28604+
28605 mm->get_unmapped_area = arch_get_unmapped_area;
28606 mm->unmap_area = arch_unmap_area;
28607 } else {
28608- mm->mmap_base = mmap_base();
28609+ mm->mmap_base = mmap_base(mm);
28610+
28611+#ifdef CONFIG_PAX_RANDMMAP
28612+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28613+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28614+#endif
28615+
28616 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28617 mm->unmap_area = arch_unmap_area_topdown;
28618 }
28619diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28620index dc0b727..f612039 100644
28621--- a/arch/x86/mm/mmio-mod.c
28622+++ b/arch/x86/mm/mmio-mod.c
28623@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28624 break;
28625 default:
28626 {
28627- unsigned char *ip = (unsigned char *)instptr;
28628+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28629 my_trace->opcode = MMIO_UNKNOWN_OP;
28630 my_trace->width = 0;
28631 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28632@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28633 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28634 void __iomem *addr)
28635 {
28636- static atomic_t next_id;
28637+ static atomic_unchecked_t next_id;
28638 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28639 /* These are page-unaligned. */
28640 struct mmiotrace_map map = {
28641@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28642 .private = trace
28643 },
28644 .phys = offset,
28645- .id = atomic_inc_return(&next_id)
28646+ .id = atomic_inc_return_unchecked(&next_id)
28647 };
28648 map.map_id = trace->id;
28649
28650@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28651 ioremap_trace_core(offset, size, addr);
28652 }
28653
28654-static void iounmap_trace_core(volatile void __iomem *addr)
28655+static void iounmap_trace_core(const volatile void __iomem *addr)
28656 {
28657 struct mmiotrace_map map = {
28658 .phys = 0,
28659@@ -328,7 +328,7 @@ not_enabled:
28660 }
28661 }
28662
28663-void mmiotrace_iounmap(volatile void __iomem *addr)
28664+void mmiotrace_iounmap(const volatile void __iomem *addr)
28665 {
28666 might_sleep();
28667 if (is_enabled()) /* recheck and proper locking in *_core() */
28668diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28669index 8504f36..5fc68f2 100644
28670--- a/arch/x86/mm/numa.c
28671+++ b/arch/x86/mm/numa.c
28672@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
28673 return true;
28674 }
28675
28676-static int __init numa_register_memblks(struct numa_meminfo *mi)
28677+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
28678 {
28679 unsigned long uninitialized_var(pfn_align);
28680 int i, nid;
28681diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28682index b008656..773eac2 100644
28683--- a/arch/x86/mm/pageattr-test.c
28684+++ b/arch/x86/mm/pageattr-test.c
28685@@ -36,7 +36,7 @@ enum {
28686
28687 static int pte_testbit(pte_t pte)
28688 {
28689- return pte_flags(pte) & _PAGE_UNUSED1;
28690+ return pte_flags(pte) & _PAGE_CPA_TEST;
28691 }
28692
28693 struct split_state {
28694diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28695index a718e0d..77419bc 100644
28696--- a/arch/x86/mm/pageattr.c
28697+++ b/arch/x86/mm/pageattr.c
28698@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28699 */
28700 #ifdef CONFIG_PCI_BIOS
28701 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28702- pgprot_val(forbidden) |= _PAGE_NX;
28703+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28704 #endif
28705
28706 /*
28707@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28708 * Does not cover __inittext since that is gone later on. On
28709 * 64bit we do not enforce !NX on the low mapping
28710 */
28711- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28712- pgprot_val(forbidden) |= _PAGE_NX;
28713+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28714+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28715
28716+#ifdef CONFIG_DEBUG_RODATA
28717 /*
28718 * The .rodata section needs to be read-only. Using the pfn
28719 * catches all aliases.
28720@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28721 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28722 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28723 pgprot_val(forbidden) |= _PAGE_RW;
28724+#endif
28725
28726 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28727 /*
28728@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28729 }
28730 #endif
28731
28732+#ifdef CONFIG_PAX_KERNEXEC
28733+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28734+ pgprot_val(forbidden) |= _PAGE_RW;
28735+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28736+ }
28737+#endif
28738+
28739 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28740
28741 return prot;
28742@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28743 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28744 {
28745 /* change init_mm */
28746+ pax_open_kernel();
28747 set_pte_atomic(kpte, pte);
28748+
28749 #ifdef CONFIG_X86_32
28750 if (!SHARED_KERNEL_PMD) {
28751+
28752+#ifdef CONFIG_PAX_PER_CPU_PGD
28753+ unsigned long cpu;
28754+#else
28755 struct page *page;
28756+#endif
28757
28758+#ifdef CONFIG_PAX_PER_CPU_PGD
28759+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28760+ pgd_t *pgd = get_cpu_pgd(cpu);
28761+#else
28762 list_for_each_entry(page, &pgd_list, lru) {
28763- pgd_t *pgd;
28764+ pgd_t *pgd = (pgd_t *)page_address(page);
28765+#endif
28766+
28767 pud_t *pud;
28768 pmd_t *pmd;
28769
28770- pgd = (pgd_t *)page_address(page) + pgd_index(address);
28771+ pgd += pgd_index(address);
28772 pud = pud_offset(pgd, address);
28773 pmd = pmd_offset(pud, address);
28774 set_pte_atomic((pte_t *)pmd, pte);
28775 }
28776 }
28777 #endif
28778+ pax_close_kernel();
28779 }
28780
28781 static int
28782diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28783index 0eb572e..92f5c1e 100644
28784--- a/arch/x86/mm/pat.c
28785+++ b/arch/x86/mm/pat.c
28786@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28787
28788 if (!entry) {
28789 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28790- current->comm, current->pid, start, end - 1);
28791+ current->comm, task_pid_nr(current), start, end - 1);
28792 return -EINVAL;
28793 }
28794
28795@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28796
28797 while (cursor < to) {
28798 if (!devmem_is_allowed(pfn)) {
28799- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28800- current->comm, from, to - 1);
28801+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28802+ current->comm, from, to - 1, cursor);
28803 return 0;
28804 }
28805 cursor += PAGE_SIZE;
28806@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28807 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28808 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28809 "for [mem %#010Lx-%#010Lx]\n",
28810- current->comm, current->pid,
28811+ current->comm, task_pid_nr(current),
28812 cattr_name(flags),
28813 base, (unsigned long long)(base + size-1));
28814 return -EINVAL;
28815@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28816 flags = lookup_memtype(paddr);
28817 if (want_flags != flags) {
28818 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28819- current->comm, current->pid,
28820+ current->comm, task_pid_nr(current),
28821 cattr_name(want_flags),
28822 (unsigned long long)paddr,
28823 (unsigned long long)(paddr + size - 1),
28824@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28825 free_memtype(paddr, paddr + size);
28826 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28827 " for [mem %#010Lx-%#010Lx], got %s\n",
28828- current->comm, current->pid,
28829+ current->comm, task_pid_nr(current),
28830 cattr_name(want_flags),
28831 (unsigned long long)paddr,
28832 (unsigned long long)(paddr + size - 1),
28833diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28834index 9f0614d..92ae64a 100644
28835--- a/arch/x86/mm/pf_in.c
28836+++ b/arch/x86/mm/pf_in.c
28837@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28838 int i;
28839 enum reason_type rv = OTHERS;
28840
28841- p = (unsigned char *)ins_addr;
28842+ p = (unsigned char *)ktla_ktva(ins_addr);
28843 p += skip_prefix(p, &prf);
28844 p += get_opcode(p, &opcode);
28845
28846@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28847 struct prefix_bits prf;
28848 int i;
28849
28850- p = (unsigned char *)ins_addr;
28851+ p = (unsigned char *)ktla_ktva(ins_addr);
28852 p += skip_prefix(p, &prf);
28853 p += get_opcode(p, &opcode);
28854
28855@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28856 struct prefix_bits prf;
28857 int i;
28858
28859- p = (unsigned char *)ins_addr;
28860+ p = (unsigned char *)ktla_ktva(ins_addr);
28861 p += skip_prefix(p, &prf);
28862 p += get_opcode(p, &opcode);
28863
28864@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28865 struct prefix_bits prf;
28866 int i;
28867
28868- p = (unsigned char *)ins_addr;
28869+ p = (unsigned char *)ktla_ktva(ins_addr);
28870 p += skip_prefix(p, &prf);
28871 p += get_opcode(p, &opcode);
28872 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28873@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28874 struct prefix_bits prf;
28875 int i;
28876
28877- p = (unsigned char *)ins_addr;
28878+ p = (unsigned char *)ktla_ktva(ins_addr);
28879 p += skip_prefix(p, &prf);
28880 p += get_opcode(p, &opcode);
28881 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
28882diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28883index e27fbf8..8b56dc9 100644
28884--- a/arch/x86/mm/pgtable.c
28885+++ b/arch/x86/mm/pgtable.c
28886@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
28887 list_del(&page->lru);
28888 }
28889
28890-#define UNSHARED_PTRS_PER_PGD \
28891- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28892+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28893+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
28894
28895+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
28896+{
28897+ unsigned int count = USER_PGD_PTRS;
28898
28899+ while (count--)
28900+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
28901+}
28902+#endif
28903+
28904+#ifdef CONFIG_PAX_PER_CPU_PGD
28905+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
28906+{
28907+ unsigned int count = USER_PGD_PTRS;
28908+
28909+ while (count--) {
28910+ pgd_t pgd;
28911+
28912+#ifdef CONFIG_X86_64
28913+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
28914+#else
28915+ pgd = *src++;
28916+#endif
28917+
28918+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28919+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
28920+#endif
28921+
28922+ *dst++ = pgd;
28923+ }
28924+
28925+}
28926+#endif
28927+
28928+#ifdef CONFIG_X86_64
28929+#define pxd_t pud_t
28930+#define pyd_t pgd_t
28931+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
28932+#define pxd_free(mm, pud) pud_free((mm), (pud))
28933+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
28934+#define pyd_offset(mm, address) pgd_offset((mm), (address))
28935+#define PYD_SIZE PGDIR_SIZE
28936+#else
28937+#define pxd_t pmd_t
28938+#define pyd_t pud_t
28939+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
28940+#define pxd_free(mm, pud) pmd_free((mm), (pud))
28941+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
28942+#define pyd_offset(mm, address) pud_offset((mm), (address))
28943+#define PYD_SIZE PUD_SIZE
28944+#endif
28945+
28946+#ifdef CONFIG_PAX_PER_CPU_PGD
28947+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
28948+static inline void pgd_dtor(pgd_t *pgd) {}
28949+#else
28950 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
28951 {
28952 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
28953@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
28954 pgd_list_del(pgd);
28955 spin_unlock(&pgd_lock);
28956 }
28957+#endif
28958
28959 /*
28960 * List of all pgd's needed for non-PAE so it can invalidate entries
28961@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
28962 * -- nyc
28963 */
28964
28965-#ifdef CONFIG_X86_PAE
28966+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
28967 /*
28968 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
28969 * updating the top-level pagetable entries to guarantee the
28970@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
28971 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
28972 * and initialize the kernel pmds here.
28973 */
28974-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
28975+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28976
28977 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28978 {
28979@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28980 */
28981 flush_tlb_mm(mm);
28982 }
28983+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
28984+#define PREALLOCATED_PXDS USER_PGD_PTRS
28985 #else /* !CONFIG_X86_PAE */
28986
28987 /* No need to prepopulate any pagetable entries in non-PAE modes. */
28988-#define PREALLOCATED_PMDS 0
28989+#define PREALLOCATED_PXDS 0
28990
28991 #endif /* CONFIG_X86_PAE */
28992
28993-static void free_pmds(pmd_t *pmds[])
28994+static void free_pxds(pxd_t *pxds[])
28995 {
28996 int i;
28997
28998- for(i = 0; i < PREALLOCATED_PMDS; i++)
28999- if (pmds[i])
29000- free_page((unsigned long)pmds[i]);
29001+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29002+ if (pxds[i])
29003+ free_page((unsigned long)pxds[i]);
29004 }
29005
29006-static int preallocate_pmds(pmd_t *pmds[])
29007+static int preallocate_pxds(pxd_t *pxds[])
29008 {
29009 int i;
29010 bool failed = false;
29011
29012- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29013- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29014- if (pmd == NULL)
29015+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29016+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29017+ if (pxd == NULL)
29018 failed = true;
29019- pmds[i] = pmd;
29020+ pxds[i] = pxd;
29021 }
29022
29023 if (failed) {
29024- free_pmds(pmds);
29025+ free_pxds(pxds);
29026 return -ENOMEM;
29027 }
29028
29029@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29030 * preallocate which never got a corresponding vma will need to be
29031 * freed manually.
29032 */
29033-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29034+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29035 {
29036 int i;
29037
29038- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29039+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29040 pgd_t pgd = pgdp[i];
29041
29042 if (pgd_val(pgd) != 0) {
29043- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29044+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29045
29046- pgdp[i] = native_make_pgd(0);
29047+ set_pgd(pgdp + i, native_make_pgd(0));
29048
29049- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29050- pmd_free(mm, pmd);
29051+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29052+ pxd_free(mm, pxd);
29053 }
29054 }
29055 }
29056
29057-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29058+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29059 {
29060- pud_t *pud;
29061+ pyd_t *pyd;
29062 unsigned long addr;
29063 int i;
29064
29065- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29066+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29067 return;
29068
29069- pud = pud_offset(pgd, 0);
29070+#ifdef CONFIG_X86_64
29071+ pyd = pyd_offset(mm, 0L);
29072+#else
29073+ pyd = pyd_offset(pgd, 0L);
29074+#endif
29075
29076- for (addr = i = 0; i < PREALLOCATED_PMDS;
29077- i++, pud++, addr += PUD_SIZE) {
29078- pmd_t *pmd = pmds[i];
29079+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29080+ i++, pyd++, addr += PYD_SIZE) {
29081+ pxd_t *pxd = pxds[i];
29082
29083 if (i >= KERNEL_PGD_BOUNDARY)
29084- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29085- sizeof(pmd_t) * PTRS_PER_PMD);
29086+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29087+ sizeof(pxd_t) * PTRS_PER_PMD);
29088
29089- pud_populate(mm, pud, pmd);
29090+ pyd_populate(mm, pyd, pxd);
29091 }
29092 }
29093
29094 pgd_t *pgd_alloc(struct mm_struct *mm)
29095 {
29096 pgd_t *pgd;
29097- pmd_t *pmds[PREALLOCATED_PMDS];
29098+ pxd_t *pxds[PREALLOCATED_PXDS];
29099
29100 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29101
29102@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29103
29104 mm->pgd = pgd;
29105
29106- if (preallocate_pmds(pmds) != 0)
29107+ if (preallocate_pxds(pxds) != 0)
29108 goto out_free_pgd;
29109
29110 if (paravirt_pgd_alloc(mm) != 0)
29111- goto out_free_pmds;
29112+ goto out_free_pxds;
29113
29114 /*
29115 * Make sure that pre-populating the pmds is atomic with
29116@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29117 spin_lock(&pgd_lock);
29118
29119 pgd_ctor(mm, pgd);
29120- pgd_prepopulate_pmd(mm, pgd, pmds);
29121+ pgd_prepopulate_pxd(mm, pgd, pxds);
29122
29123 spin_unlock(&pgd_lock);
29124
29125 return pgd;
29126
29127-out_free_pmds:
29128- free_pmds(pmds);
29129+out_free_pxds:
29130+ free_pxds(pxds);
29131 out_free_pgd:
29132 free_page((unsigned long)pgd);
29133 out:
29134@@ -295,7 +356,7 @@ out:
29135
29136 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29137 {
29138- pgd_mop_up_pmds(mm, pgd);
29139+ pgd_mop_up_pxds(mm, pgd);
29140 pgd_dtor(pgd);
29141 paravirt_pgd_free(mm, pgd);
29142 free_page((unsigned long)pgd);
29143diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29144index a69bcb8..19068ab 100644
29145--- a/arch/x86/mm/pgtable_32.c
29146+++ b/arch/x86/mm/pgtable_32.c
29147@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29148 return;
29149 }
29150 pte = pte_offset_kernel(pmd, vaddr);
29151+
29152+ pax_open_kernel();
29153 if (pte_val(pteval))
29154 set_pte_at(&init_mm, vaddr, pte, pteval);
29155 else
29156 pte_clear(&init_mm, vaddr, pte);
29157+ pax_close_kernel();
29158
29159 /*
29160 * It's enough to flush this one mapping.
29161diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29162index d2e2735..5c6586f 100644
29163--- a/arch/x86/mm/physaddr.c
29164+++ b/arch/x86/mm/physaddr.c
29165@@ -8,7 +8,7 @@
29166
29167 #ifdef CONFIG_X86_64
29168
29169-unsigned long __phys_addr(unsigned long x)
29170+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29171 {
29172 if (x >= __START_KERNEL_map) {
29173 x -= __START_KERNEL_map;
29174@@ -45,7 +45,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29175 #else
29176
29177 #ifdef CONFIG_DEBUG_VIRTUAL
29178-unsigned long __phys_addr(unsigned long x)
29179+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29180 {
29181 /* VMALLOC_* aren't constants */
29182 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
29183diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29184index 410531d..0f16030 100644
29185--- a/arch/x86/mm/setup_nx.c
29186+++ b/arch/x86/mm/setup_nx.c
29187@@ -5,8 +5,10 @@
29188 #include <asm/pgtable.h>
29189 #include <asm/proto.h>
29190
29191+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29192 static int disable_nx __cpuinitdata;
29193
29194+#ifndef CONFIG_PAX_PAGEEXEC
29195 /*
29196 * noexec = on|off
29197 *
29198@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29199 return 0;
29200 }
29201 early_param("noexec", noexec_setup);
29202+#endif
29203+
29204+#endif
29205
29206 void __cpuinit x86_configure_nx(void)
29207 {
29208+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29209 if (cpu_has_nx && !disable_nx)
29210 __supported_pte_mask |= _PAGE_NX;
29211 else
29212+#endif
29213 __supported_pte_mask &= ~_PAGE_NX;
29214 }
29215
29216diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29217index 13a6b29..c2fff23 100644
29218--- a/arch/x86/mm/tlb.c
29219+++ b/arch/x86/mm/tlb.c
29220@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29221 BUG();
29222 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29223 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29224+
29225+#ifndef CONFIG_PAX_PER_CPU_PGD
29226 load_cr3(swapper_pg_dir);
29227+#endif
29228+
29229 }
29230 }
29231 EXPORT_SYMBOL_GPL(leave_mm);
29232diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29233index 877b9a1..a8ecf42 100644
29234--- a/arch/x86/net/bpf_jit.S
29235+++ b/arch/x86/net/bpf_jit.S
29236@@ -9,6 +9,7 @@
29237 */
29238 #include <linux/linkage.h>
29239 #include <asm/dwarf2.h>
29240+#include <asm/alternative-asm.h>
29241
29242 /*
29243 * Calling convention :
29244@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29245 jle bpf_slow_path_word
29246 mov (SKBDATA,%rsi),%eax
29247 bswap %eax /* ntohl() */
29248+ pax_force_retaddr
29249 ret
29250
29251 sk_load_half:
29252@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29253 jle bpf_slow_path_half
29254 movzwl (SKBDATA,%rsi),%eax
29255 rol $8,%ax # ntohs()
29256+ pax_force_retaddr
29257 ret
29258
29259 sk_load_byte:
29260@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29261 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29262 jle bpf_slow_path_byte
29263 movzbl (SKBDATA,%rsi),%eax
29264+ pax_force_retaddr
29265 ret
29266
29267 /**
29268@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29269 movzbl (SKBDATA,%rsi),%ebx
29270 and $15,%bl
29271 shl $2,%bl
29272+ pax_force_retaddr
29273 ret
29274
29275 /* rsi contains offset and can be scratched */
29276@@ -109,6 +114,7 @@ bpf_slow_path_word:
29277 js bpf_error
29278 mov -12(%rbp),%eax
29279 bswap %eax
29280+ pax_force_retaddr
29281 ret
29282
29283 bpf_slow_path_half:
29284@@ -117,12 +123,14 @@ bpf_slow_path_half:
29285 mov -12(%rbp),%ax
29286 rol $8,%ax
29287 movzwl %ax,%eax
29288+ pax_force_retaddr
29289 ret
29290
29291 bpf_slow_path_byte:
29292 bpf_slow_path_common(1)
29293 js bpf_error
29294 movzbl -12(%rbp),%eax
29295+ pax_force_retaddr
29296 ret
29297
29298 bpf_slow_path_byte_msh:
29299@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29300 and $15,%al
29301 shl $2,%al
29302 xchg %eax,%ebx
29303+ pax_force_retaddr
29304 ret
29305
29306 #define sk_negative_common(SIZE) \
29307@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29308 sk_negative_common(4)
29309 mov (%rax), %eax
29310 bswap %eax
29311+ pax_force_retaddr
29312 ret
29313
29314 bpf_slow_path_half_neg:
29315@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29316 mov (%rax),%ax
29317 rol $8,%ax
29318 movzwl %ax,%eax
29319+ pax_force_retaddr
29320 ret
29321
29322 bpf_slow_path_byte_neg:
29323@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29324 .globl sk_load_byte_negative_offset
29325 sk_negative_common(1)
29326 movzbl (%rax), %eax
29327+ pax_force_retaddr
29328 ret
29329
29330 bpf_slow_path_byte_msh_neg:
29331@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29332 and $15,%al
29333 shl $2,%al
29334 xchg %eax,%ebx
29335+ pax_force_retaddr
29336 ret
29337
29338 bpf_error:
29339@@ -197,4 +210,5 @@ bpf_error:
29340 xor %eax,%eax
29341 mov -8(%rbp),%rbx
29342 leaveq
29343+ pax_force_retaddr
29344 ret
29345diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29346index d11a470..3f9adff3 100644
29347--- a/arch/x86/net/bpf_jit_comp.c
29348+++ b/arch/x86/net/bpf_jit_comp.c
29349@@ -12,6 +12,7 @@
29350 #include <linux/netdevice.h>
29351 #include <linux/filter.h>
29352 #include <linux/if_vlan.h>
29353+#include <linux/random.h>
29354
29355 /*
29356 * Conventions :
29357@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29358 return ptr + len;
29359 }
29360
29361+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29362+#define MAX_INSTR_CODE_SIZE 96
29363+#else
29364+#define MAX_INSTR_CODE_SIZE 64
29365+#endif
29366+
29367 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29368
29369 #define EMIT1(b1) EMIT(b1, 1)
29370 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29371 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29372 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29373+
29374+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29375+/* original constant will appear in ecx */
29376+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29377+do { \
29378+ /* mov ecx, randkey */ \
29379+ EMIT1(0xb9); \
29380+ EMIT(_key, 4); \
29381+ /* xor ecx, randkey ^ off */ \
29382+ EMIT2(0x81, 0xf1); \
29383+ EMIT((_key) ^ (_off), 4); \
29384+} while (0)
29385+
29386+#define EMIT1_off32(b1, _off) \
29387+do { \
29388+ switch (b1) { \
29389+ case 0x05: /* add eax, imm32 */ \
29390+ case 0x2d: /* sub eax, imm32 */ \
29391+ case 0x25: /* and eax, imm32 */ \
29392+ case 0x0d: /* or eax, imm32 */ \
29393+ case 0xb8: /* mov eax, imm32 */ \
29394+ case 0x3d: /* cmp eax, imm32 */ \
29395+ case 0xa9: /* test eax, imm32 */ \
29396+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29397+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29398+ break; \
29399+ case 0xbb: /* mov ebx, imm32 */ \
29400+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29401+ /* mov ebx, ecx */ \
29402+ EMIT2(0x89, 0xcb); \
29403+ break; \
29404+ case 0xbe: /* mov esi, imm32 */ \
29405+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29406+ /* mov esi, ecx */ \
29407+ EMIT2(0x89, 0xce); \
29408+ break; \
29409+ case 0xe9: /* jmp rel imm32 */ \
29410+ EMIT1(b1); \
29411+ EMIT(_off, 4); \
29412+ /* prevent fall-through, we're not called if off = 0 */ \
29413+ EMIT(0xcccccccc, 4); \
29414+ EMIT(0xcccccccc, 4); \
29415+ break; \
29416+ default: \
29417+ EMIT1(b1); \
29418+ EMIT(_off, 4); \
29419+ } \
29420+} while (0)
29421+
29422+#define EMIT2_off32(b1, b2, _off) \
29423+do { \
29424+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29425+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29426+ EMIT(randkey, 4); \
29427+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29428+ EMIT((_off) - randkey, 4); \
29429+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29430+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29431+ /* imul eax, ecx */ \
29432+ EMIT3(0x0f, 0xaf, 0xc1); \
29433+ } else { \
29434+ EMIT2(b1, b2); \
29435+ EMIT(_off, 4); \
29436+ } \
29437+} while (0)
29438+#else
29439 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29440+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29441+#endif
29442
29443 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29444 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29445@@ -90,6 +165,24 @@ do { \
29446 #define X86_JBE 0x76
29447 #define X86_JA 0x77
29448
29449+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29450+#define APPEND_FLOW_VERIFY() \
29451+do { \
29452+ /* mov ecx, randkey */ \
29453+ EMIT1(0xb9); \
29454+ EMIT(randkey, 4); \
29455+ /* cmp ecx, randkey */ \
29456+ EMIT2(0x81, 0xf9); \
29457+ EMIT(randkey, 4); \
29458+ /* jz after 8 int 3s */ \
29459+ EMIT2(0x74, 0x08); \
29460+ EMIT(0xcccccccc, 4); \
29461+ EMIT(0xcccccccc, 4); \
29462+} while (0)
29463+#else
29464+#define APPEND_FLOW_VERIFY() do { } while (0)
29465+#endif
29466+
29467 #define EMIT_COND_JMP(op, offset) \
29468 do { \
29469 if (is_near(offset)) \
29470@@ -97,6 +190,7 @@ do { \
29471 else { \
29472 EMIT2(0x0f, op + 0x10); \
29473 EMIT(offset, 4); /* jxx .+off32 */ \
29474+ APPEND_FLOW_VERIFY(); \
29475 } \
29476 } while (0)
29477
29478@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
29479 set_fs(old_fs);
29480 }
29481
29482+struct bpf_jit_work {
29483+ struct work_struct work;
29484+ void *image;
29485+};
29486+
29487 #define CHOOSE_LOAD_FUNC(K, func) \
29488 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29489
29490 void bpf_jit_compile(struct sk_filter *fp)
29491 {
29492- u8 temp[64];
29493+ u8 temp[MAX_INSTR_CODE_SIZE];
29494 u8 *prog;
29495 unsigned int proglen, oldproglen = 0;
29496 int ilen, i;
29497@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29498 unsigned int *addrs;
29499 const struct sock_filter *filter = fp->insns;
29500 int flen = fp->len;
29501+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29502+ unsigned int randkey;
29503+#endif
29504
29505 if (!bpf_jit_enable)
29506 return;
29507@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29508 if (addrs == NULL)
29509 return;
29510
29511+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29512+ if (!fp->work)
29513+ goto out;
29514+
29515+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29516+ randkey = get_random_int();
29517+#endif
29518+
29519 /* Before first pass, make a rough estimation of addrs[]
29520- * each bpf instruction is translated to less than 64 bytes
29521+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29522 */
29523 for (proglen = 0, i = 0; i < flen; i++) {
29524- proglen += 64;
29525+ proglen += MAX_INSTR_CODE_SIZE;
29526 addrs[i] = proglen;
29527 }
29528 cleanup_addr = proglen; /* epilogue address */
29529@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29530 case BPF_S_ALU_MUL_K: /* A *= K */
29531 if (is_imm8(K))
29532 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29533- else {
29534- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29535- EMIT(K, 4);
29536- }
29537+ else
29538+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29539 break;
29540 case BPF_S_ALU_DIV_X: /* A /= X; */
29541 seen |= SEEN_XREG;
29542@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29543 break;
29544 case BPF_S_ALU_MOD_K: /* A %= K; */
29545 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29546+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29547+ DILUTE_CONST_SEQUENCE(K, randkey);
29548+#else
29549 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29550+#endif
29551 EMIT2(0xf7, 0xf1); /* div %ecx */
29552 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29553 break;
29554 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29555+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29556+ DILUTE_CONST_SEQUENCE(K, randkey);
29557+ // imul rax, rcx
29558+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29559+#else
29560 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29561 EMIT(K, 4);
29562+#endif
29563 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29564 break;
29565 case BPF_S_ALU_AND_X:
29566@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29567 if (is_imm8(K)) {
29568 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29569 } else {
29570- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29571- EMIT(K, 4);
29572+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29573 }
29574 } else {
29575 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29576@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29577 break;
29578 default:
29579 /* hmm, too complex filter, give up with jit compiler */
29580- goto out;
29581+ goto error;
29582 }
29583 ilen = prog - temp;
29584 if (image) {
29585 if (unlikely(proglen + ilen > oldproglen)) {
29586 pr_err("bpb_jit_compile fatal error\n");
29587- kfree(addrs);
29588- module_free(NULL, image);
29589- return;
29590+ module_free_exec(NULL, image);
29591+ goto error;
29592 }
29593+ pax_open_kernel();
29594 memcpy(image + proglen, temp, ilen);
29595+ pax_close_kernel();
29596 }
29597 proglen += ilen;
29598 addrs[i] = proglen;
29599@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29600 break;
29601 }
29602 if (proglen == oldproglen) {
29603- image = module_alloc(max_t(unsigned int,
29604- proglen,
29605- sizeof(struct work_struct)));
29606+ image = module_alloc_exec(proglen);
29607 if (!image)
29608- goto out;
29609+ goto error;
29610 }
29611 oldproglen = proglen;
29612 }
29613@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29614 bpf_flush_icache(image, image + proglen);
29615
29616 fp->bpf_func = (void *)image;
29617- }
29618+ } else
29619+error:
29620+ kfree(fp->work);
29621+
29622 out:
29623 kfree(addrs);
29624 return;
29625@@ -707,18 +826,20 @@ out:
29626
29627 static void jit_free_defer(struct work_struct *arg)
29628 {
29629- module_free(NULL, arg);
29630+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29631+ kfree(arg);
29632 }
29633
29634 /* run from softirq, we must use a work_struct to call
29635- * module_free() from process context
29636+ * module_free_exec() from process context
29637 */
29638 void bpf_jit_free(struct sk_filter *fp)
29639 {
29640 if (fp->bpf_func != sk_run_filter) {
29641- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29642+ struct work_struct *work = &fp->work->work;
29643
29644 INIT_WORK(work, jit_free_defer);
29645+ fp->work->image = fp->bpf_func;
29646 schedule_work(work);
29647 }
29648 }
29649diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29650index d6aa6e8..266395a 100644
29651--- a/arch/x86/oprofile/backtrace.c
29652+++ b/arch/x86/oprofile/backtrace.c
29653@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29654 struct stack_frame_ia32 *fp;
29655 unsigned long bytes;
29656
29657- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29658+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29659 if (bytes != sizeof(bufhead))
29660 return NULL;
29661
29662- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29663+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29664
29665 oprofile_add_trace(bufhead[0].return_address);
29666
29667@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29668 struct stack_frame bufhead[2];
29669 unsigned long bytes;
29670
29671- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29672+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29673 if (bytes != sizeof(bufhead))
29674 return NULL;
29675
29676@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29677 {
29678 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29679
29680- if (!user_mode_vm(regs)) {
29681+ if (!user_mode(regs)) {
29682 unsigned long stack = kernel_stack_pointer(regs);
29683 if (depth)
29684 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29685diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29686index 48768df..ba9143c 100644
29687--- a/arch/x86/oprofile/nmi_int.c
29688+++ b/arch/x86/oprofile/nmi_int.c
29689@@ -23,6 +23,7 @@
29690 #include <asm/nmi.h>
29691 #include <asm/msr.h>
29692 #include <asm/apic.h>
29693+#include <asm/pgtable.h>
29694
29695 #include "op_counter.h"
29696 #include "op_x86_model.h"
29697@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29698 if (ret)
29699 return ret;
29700
29701- if (!model->num_virt_counters)
29702- model->num_virt_counters = model->num_counters;
29703+ if (!model->num_virt_counters) {
29704+ pax_open_kernel();
29705+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
29706+ pax_close_kernel();
29707+ }
29708
29709 mux_init(ops);
29710
29711diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29712index b2b9443..be58856 100644
29713--- a/arch/x86/oprofile/op_model_amd.c
29714+++ b/arch/x86/oprofile/op_model_amd.c
29715@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29716 num_counters = AMD64_NUM_COUNTERS;
29717 }
29718
29719- op_amd_spec.num_counters = num_counters;
29720- op_amd_spec.num_controls = num_counters;
29721- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29722+ pax_open_kernel();
29723+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29724+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29725+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29726+ pax_close_kernel();
29727
29728 return 0;
29729 }
29730diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29731index d90528e..0127e2b 100644
29732--- a/arch/x86/oprofile/op_model_ppro.c
29733+++ b/arch/x86/oprofile/op_model_ppro.c
29734@@ -19,6 +19,7 @@
29735 #include <asm/msr.h>
29736 #include <asm/apic.h>
29737 #include <asm/nmi.h>
29738+#include <asm/pgtable.h>
29739
29740 #include "op_x86_model.h"
29741 #include "op_counter.h"
29742@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
29743
29744 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
29745
29746- op_arch_perfmon_spec.num_counters = num_counters;
29747- op_arch_perfmon_spec.num_controls = num_counters;
29748+ pax_open_kernel();
29749+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
29750+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
29751+ pax_close_kernel();
29752 }
29753
29754 static int arch_perfmon_init(struct oprofile_operations *ignore)
29755diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
29756index 71e8a67..6a313bb 100644
29757--- a/arch/x86/oprofile/op_x86_model.h
29758+++ b/arch/x86/oprofile/op_x86_model.h
29759@@ -52,7 +52,7 @@ struct op_x86_model_spec {
29760 void (*switch_ctrl)(struct op_x86_model_spec const *model,
29761 struct op_msrs const * const msrs);
29762 #endif
29763-};
29764+} __do_const;
29765
29766 struct op_counter_config;
29767
29768diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29769index e9e6ed5..e47ae67 100644
29770--- a/arch/x86/pci/amd_bus.c
29771+++ b/arch/x86/pci/amd_bus.c
29772@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29773 return NOTIFY_OK;
29774 }
29775
29776-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29777+static struct notifier_block amd_cpu_notifier = {
29778 .notifier_call = amd_cpu_notify,
29779 };
29780
29781diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
29782index 372e9b8..e775a6c 100644
29783--- a/arch/x86/pci/irq.c
29784+++ b/arch/x86/pci/irq.c
29785@@ -50,7 +50,7 @@ struct irq_router {
29786 struct irq_router_handler {
29787 u16 vendor;
29788 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
29789-};
29790+} __do_const;
29791
29792 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
29793 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
29794@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
29795 return 0;
29796 }
29797
29798-static __initdata struct irq_router_handler pirq_routers[] = {
29799+static __initconst const struct irq_router_handler pirq_routers[] = {
29800 { PCI_VENDOR_ID_INTEL, intel_router_probe },
29801 { PCI_VENDOR_ID_AL, ali_router_probe },
29802 { PCI_VENDOR_ID_ITE, ite_router_probe },
29803@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
29804 static void __init pirq_find_router(struct irq_router *r)
29805 {
29806 struct irq_routing_table *rt = pirq_table;
29807- struct irq_router_handler *h;
29808+ const struct irq_router_handler *h;
29809
29810 #ifdef CONFIG_PCI_BIOS
29811 if (!rt->signature) {
29812@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
29813 return 0;
29814 }
29815
29816-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
29817+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
29818 {
29819 .callback = fix_broken_hp_bios_irq9,
29820 .ident = "HP Pavilion N5400 Series Laptop",
29821diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29822index 6eb18c4..20d83de 100644
29823--- a/arch/x86/pci/mrst.c
29824+++ b/arch/x86/pci/mrst.c
29825@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29826 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29827 pci_mmcfg_late_init();
29828 pcibios_enable_irq = mrst_pci_irq_enable;
29829- pci_root_ops = pci_mrst_ops;
29830+ pax_open_kernel();
29831+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29832+ pax_close_kernel();
29833 pci_soc_mode = 1;
29834 /* Continue with standard init */
29835 return 1;
29836diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29837index c77b24a..c979855 100644
29838--- a/arch/x86/pci/pcbios.c
29839+++ b/arch/x86/pci/pcbios.c
29840@@ -79,7 +79,7 @@ union bios32 {
29841 static struct {
29842 unsigned long address;
29843 unsigned short segment;
29844-} bios32_indirect = { 0, __KERNEL_CS };
29845+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29846
29847 /*
29848 * Returns the entry point for the given service, NULL on error
29849@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29850 unsigned long length; /* %ecx */
29851 unsigned long entry; /* %edx */
29852 unsigned long flags;
29853+ struct desc_struct d, *gdt;
29854
29855 local_irq_save(flags);
29856- __asm__("lcall *(%%edi); cld"
29857+
29858+ gdt = get_cpu_gdt_table(smp_processor_id());
29859+
29860+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29861+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29862+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29863+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29864+
29865+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29866 : "=a" (return_code),
29867 "=b" (address),
29868 "=c" (length),
29869 "=d" (entry)
29870 : "0" (service),
29871 "1" (0),
29872- "D" (&bios32_indirect));
29873+ "D" (&bios32_indirect),
29874+ "r"(__PCIBIOS_DS)
29875+ : "memory");
29876+
29877+ pax_open_kernel();
29878+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29879+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29880+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29881+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29882+ pax_close_kernel();
29883+
29884 local_irq_restore(flags);
29885
29886 switch (return_code) {
29887- case 0:
29888- return address + entry;
29889- case 0x80: /* Not present */
29890- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29891- return 0;
29892- default: /* Shouldn't happen */
29893- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29894- service, return_code);
29895+ case 0: {
29896+ int cpu;
29897+ unsigned char flags;
29898+
29899+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
29900+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
29901+ printk(KERN_WARNING "bios32_service: not valid\n");
29902 return 0;
29903+ }
29904+ address = address + PAGE_OFFSET;
29905+ length += 16UL; /* some BIOSs underreport this... */
29906+ flags = 4;
29907+ if (length >= 64*1024*1024) {
29908+ length >>= PAGE_SHIFT;
29909+ flags |= 8;
29910+ }
29911+
29912+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29913+ gdt = get_cpu_gdt_table(cpu);
29914+ pack_descriptor(&d, address, length, 0x9b, flags);
29915+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29916+ pack_descriptor(&d, address, length, 0x93, flags);
29917+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29918+ }
29919+ return entry;
29920+ }
29921+ case 0x80: /* Not present */
29922+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29923+ return 0;
29924+ default: /* Shouldn't happen */
29925+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29926+ service, return_code);
29927+ return 0;
29928 }
29929 }
29930
29931 static struct {
29932 unsigned long address;
29933 unsigned short segment;
29934-} pci_indirect = { 0, __KERNEL_CS };
29935+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
29936
29937-static int pci_bios_present;
29938+static int pci_bios_present __read_only;
29939
29940 static int check_pcibios(void)
29941 {
29942@@ -131,11 +174,13 @@ static int check_pcibios(void)
29943 unsigned long flags, pcibios_entry;
29944
29945 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
29946- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
29947+ pci_indirect.address = pcibios_entry;
29948
29949 local_irq_save(flags);
29950- __asm__(
29951- "lcall *(%%edi); cld\n\t"
29952+ __asm__("movw %w6, %%ds\n\t"
29953+ "lcall *%%ss:(%%edi); cld\n\t"
29954+ "push %%ss\n\t"
29955+ "pop %%ds\n\t"
29956 "jc 1f\n\t"
29957 "xor %%ah, %%ah\n"
29958 "1:"
29959@@ -144,7 +189,8 @@ static int check_pcibios(void)
29960 "=b" (ebx),
29961 "=c" (ecx)
29962 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
29963- "D" (&pci_indirect)
29964+ "D" (&pci_indirect),
29965+ "r" (__PCIBIOS_DS)
29966 : "memory");
29967 local_irq_restore(flags);
29968
29969@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29970
29971 switch (len) {
29972 case 1:
29973- __asm__("lcall *(%%esi); cld\n\t"
29974+ __asm__("movw %w6, %%ds\n\t"
29975+ "lcall *%%ss:(%%esi); cld\n\t"
29976+ "push %%ss\n\t"
29977+ "pop %%ds\n\t"
29978 "jc 1f\n\t"
29979 "xor %%ah, %%ah\n"
29980 "1:"
29981@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29982 : "1" (PCIBIOS_READ_CONFIG_BYTE),
29983 "b" (bx),
29984 "D" ((long)reg),
29985- "S" (&pci_indirect));
29986+ "S" (&pci_indirect),
29987+ "r" (__PCIBIOS_DS));
29988 /*
29989 * Zero-extend the result beyond 8 bits, do not trust the
29990 * BIOS having done it:
29991@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29992 *value &= 0xff;
29993 break;
29994 case 2:
29995- __asm__("lcall *(%%esi); cld\n\t"
29996+ __asm__("movw %w6, %%ds\n\t"
29997+ "lcall *%%ss:(%%esi); cld\n\t"
29998+ "push %%ss\n\t"
29999+ "pop %%ds\n\t"
30000 "jc 1f\n\t"
30001 "xor %%ah, %%ah\n"
30002 "1:"
30003@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30004 : "1" (PCIBIOS_READ_CONFIG_WORD),
30005 "b" (bx),
30006 "D" ((long)reg),
30007- "S" (&pci_indirect));
30008+ "S" (&pci_indirect),
30009+ "r" (__PCIBIOS_DS));
30010 /*
30011 * Zero-extend the result beyond 16 bits, do not trust the
30012 * BIOS having done it:
30013@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30014 *value &= 0xffff;
30015 break;
30016 case 4:
30017- __asm__("lcall *(%%esi); cld\n\t"
30018+ __asm__("movw %w6, %%ds\n\t"
30019+ "lcall *%%ss:(%%esi); cld\n\t"
30020+ "push %%ss\n\t"
30021+ "pop %%ds\n\t"
30022 "jc 1f\n\t"
30023 "xor %%ah, %%ah\n"
30024 "1:"
30025@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30026 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30027 "b" (bx),
30028 "D" ((long)reg),
30029- "S" (&pci_indirect));
30030+ "S" (&pci_indirect),
30031+ "r" (__PCIBIOS_DS));
30032 break;
30033 }
30034
30035@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30036
30037 switch (len) {
30038 case 1:
30039- __asm__("lcall *(%%esi); cld\n\t"
30040+ __asm__("movw %w6, %%ds\n\t"
30041+ "lcall *%%ss:(%%esi); cld\n\t"
30042+ "push %%ss\n\t"
30043+ "pop %%ds\n\t"
30044 "jc 1f\n\t"
30045 "xor %%ah, %%ah\n"
30046 "1:"
30047@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30048 "c" (value),
30049 "b" (bx),
30050 "D" ((long)reg),
30051- "S" (&pci_indirect));
30052+ "S" (&pci_indirect),
30053+ "r" (__PCIBIOS_DS));
30054 break;
30055 case 2:
30056- __asm__("lcall *(%%esi); cld\n\t"
30057+ __asm__("movw %w6, %%ds\n\t"
30058+ "lcall *%%ss:(%%esi); cld\n\t"
30059+ "push %%ss\n\t"
30060+ "pop %%ds\n\t"
30061 "jc 1f\n\t"
30062 "xor %%ah, %%ah\n"
30063 "1:"
30064@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30065 "c" (value),
30066 "b" (bx),
30067 "D" ((long)reg),
30068- "S" (&pci_indirect));
30069+ "S" (&pci_indirect),
30070+ "r" (__PCIBIOS_DS));
30071 break;
30072 case 4:
30073- __asm__("lcall *(%%esi); cld\n\t"
30074+ __asm__("movw %w6, %%ds\n\t"
30075+ "lcall *%%ss:(%%esi); cld\n\t"
30076+ "push %%ss\n\t"
30077+ "pop %%ds\n\t"
30078 "jc 1f\n\t"
30079 "xor %%ah, %%ah\n"
30080 "1:"
30081@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30082 "c" (value),
30083 "b" (bx),
30084 "D" ((long)reg),
30085- "S" (&pci_indirect));
30086+ "S" (&pci_indirect),
30087+ "r" (__PCIBIOS_DS));
30088 break;
30089 }
30090
30091@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30092
30093 DBG("PCI: Fetching IRQ routing table... ");
30094 __asm__("push %%es\n\t"
30095+ "movw %w8, %%ds\n\t"
30096 "push %%ds\n\t"
30097 "pop %%es\n\t"
30098- "lcall *(%%esi); cld\n\t"
30099+ "lcall *%%ss:(%%esi); cld\n\t"
30100 "pop %%es\n\t"
30101+ "push %%ss\n\t"
30102+ "pop %%ds\n"
30103 "jc 1f\n\t"
30104 "xor %%ah, %%ah\n"
30105 "1:"
30106@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30107 "1" (0),
30108 "D" ((long) &opt),
30109 "S" (&pci_indirect),
30110- "m" (opt)
30111+ "m" (opt),
30112+ "r" (__PCIBIOS_DS)
30113 : "memory");
30114 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30115 if (ret & 0xff00)
30116@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30117 {
30118 int ret;
30119
30120- __asm__("lcall *(%%esi); cld\n\t"
30121+ __asm__("movw %w5, %%ds\n\t"
30122+ "lcall *%%ss:(%%esi); cld\n\t"
30123+ "push %%ss\n\t"
30124+ "pop %%ds\n"
30125 "jc 1f\n\t"
30126 "xor %%ah, %%ah\n"
30127 "1:"
30128@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30129 : "0" (PCIBIOS_SET_PCI_HW_INT),
30130 "b" ((dev->bus->number << 8) | dev->devfn),
30131 "c" ((irq << 8) | (pin + 10)),
30132- "S" (&pci_indirect));
30133+ "S" (&pci_indirect),
30134+ "r" (__PCIBIOS_DS));
30135 return !(ret & 0xff00);
30136 }
30137 EXPORT_SYMBOL(pcibios_set_irq_routing);
30138diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30139index 40e4469..1ab536e 100644
30140--- a/arch/x86/platform/efi/efi_32.c
30141+++ b/arch/x86/platform/efi/efi_32.c
30142@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30143 {
30144 struct desc_ptr gdt_descr;
30145
30146+#ifdef CONFIG_PAX_KERNEXEC
30147+ struct desc_struct d;
30148+#endif
30149+
30150 local_irq_save(efi_rt_eflags);
30151
30152 load_cr3(initial_page_table);
30153 __flush_tlb_all();
30154
30155+#ifdef CONFIG_PAX_KERNEXEC
30156+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30157+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30158+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30159+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30160+#endif
30161+
30162 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30163 gdt_descr.size = GDT_SIZE - 1;
30164 load_gdt(&gdt_descr);
30165@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
30166 {
30167 struct desc_ptr gdt_descr;
30168
30169+#ifdef CONFIG_PAX_KERNEXEC
30170+ struct desc_struct d;
30171+
30172+ memset(&d, 0, sizeof d);
30173+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30174+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30175+#endif
30176+
30177 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30178 gdt_descr.size = GDT_SIZE - 1;
30179 load_gdt(&gdt_descr);
30180diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30181index fbe66e6..eae5e38 100644
30182--- a/arch/x86/platform/efi/efi_stub_32.S
30183+++ b/arch/x86/platform/efi/efi_stub_32.S
30184@@ -6,7 +6,9 @@
30185 */
30186
30187 #include <linux/linkage.h>
30188+#include <linux/init.h>
30189 #include <asm/page_types.h>
30190+#include <asm/segment.h>
30191
30192 /*
30193 * efi_call_phys(void *, ...) is a function with variable parameters.
30194@@ -20,7 +22,7 @@
30195 * service functions will comply with gcc calling convention, too.
30196 */
30197
30198-.text
30199+__INIT
30200 ENTRY(efi_call_phys)
30201 /*
30202 * 0. The function can only be called in Linux kernel. So CS has been
30203@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30204 * The mapping of lower virtual memory has been created in prelog and
30205 * epilog.
30206 */
30207- movl $1f, %edx
30208- subl $__PAGE_OFFSET, %edx
30209- jmp *%edx
30210+#ifdef CONFIG_PAX_KERNEXEC
30211+ movl $(__KERNEXEC_EFI_DS), %edx
30212+ mov %edx, %ds
30213+ mov %edx, %es
30214+ mov %edx, %ss
30215+ addl $2f,(1f)
30216+ ljmp *(1f)
30217+
30218+__INITDATA
30219+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30220+.previous
30221+
30222+2:
30223+ subl $2b,(1b)
30224+#else
30225+ jmp 1f-__PAGE_OFFSET
30226 1:
30227+#endif
30228
30229 /*
30230 * 2. Now on the top of stack is the return
30231@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30232 * parameter 2, ..., param n. To make things easy, we save the return
30233 * address of efi_call_phys in a global variable.
30234 */
30235- popl %edx
30236- movl %edx, saved_return_addr
30237- /* get the function pointer into ECX*/
30238- popl %ecx
30239- movl %ecx, efi_rt_function_ptr
30240- movl $2f, %edx
30241- subl $__PAGE_OFFSET, %edx
30242- pushl %edx
30243+ popl (saved_return_addr)
30244+ popl (efi_rt_function_ptr)
30245
30246 /*
30247 * 3. Clear PG bit in %CR0.
30248@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30249 /*
30250 * 5. Call the physical function.
30251 */
30252- jmp *%ecx
30253+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30254
30255-2:
30256 /*
30257 * 6. After EFI runtime service returns, control will return to
30258 * following instruction. We'd better readjust stack pointer first.
30259@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30260 movl %cr0, %edx
30261 orl $0x80000000, %edx
30262 movl %edx, %cr0
30263- jmp 1f
30264-1:
30265+
30266 /*
30267 * 8. Now restore the virtual mode from flat mode by
30268 * adding EIP with PAGE_OFFSET.
30269 */
30270- movl $1f, %edx
30271- jmp *%edx
30272+#ifdef CONFIG_PAX_KERNEXEC
30273+ movl $(__KERNEL_DS), %edx
30274+ mov %edx, %ds
30275+ mov %edx, %es
30276+ mov %edx, %ss
30277+ ljmp $(__KERNEL_CS),$1f
30278+#else
30279+ jmp 1f+__PAGE_OFFSET
30280+#endif
30281 1:
30282
30283 /*
30284 * 9. Balance the stack. And because EAX contain the return value,
30285 * we'd better not clobber it.
30286 */
30287- leal efi_rt_function_ptr, %edx
30288- movl (%edx), %ecx
30289- pushl %ecx
30290+ pushl (efi_rt_function_ptr)
30291
30292 /*
30293- * 10. Push the saved return address onto the stack and return.
30294+ * 10. Return to the saved return address.
30295 */
30296- leal saved_return_addr, %edx
30297- movl (%edx), %ecx
30298- pushl %ecx
30299- ret
30300+ jmpl *(saved_return_addr)
30301 ENDPROC(efi_call_phys)
30302 .previous
30303
30304-.data
30305+__INITDATA
30306 saved_return_addr:
30307 .long 0
30308 efi_rt_function_ptr:
30309diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30310index 4c07cca..2c8427d 100644
30311--- a/arch/x86/platform/efi/efi_stub_64.S
30312+++ b/arch/x86/platform/efi/efi_stub_64.S
30313@@ -7,6 +7,7 @@
30314 */
30315
30316 #include <linux/linkage.h>
30317+#include <asm/alternative-asm.h>
30318
30319 #define SAVE_XMM \
30320 mov %rsp, %rax; \
30321@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30322 call *%rdi
30323 addq $32, %rsp
30324 RESTORE_XMM
30325+ pax_force_retaddr 0, 1
30326 ret
30327 ENDPROC(efi_call0)
30328
30329@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30330 call *%rdi
30331 addq $32, %rsp
30332 RESTORE_XMM
30333+ pax_force_retaddr 0, 1
30334 ret
30335 ENDPROC(efi_call1)
30336
30337@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30338 call *%rdi
30339 addq $32, %rsp
30340 RESTORE_XMM
30341+ pax_force_retaddr 0, 1
30342 ret
30343 ENDPROC(efi_call2)
30344
30345@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30346 call *%rdi
30347 addq $32, %rsp
30348 RESTORE_XMM
30349+ pax_force_retaddr 0, 1
30350 ret
30351 ENDPROC(efi_call3)
30352
30353@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30354 call *%rdi
30355 addq $32, %rsp
30356 RESTORE_XMM
30357+ pax_force_retaddr 0, 1
30358 ret
30359 ENDPROC(efi_call4)
30360
30361@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30362 call *%rdi
30363 addq $48, %rsp
30364 RESTORE_XMM
30365+ pax_force_retaddr 0, 1
30366 ret
30367 ENDPROC(efi_call5)
30368
30369@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30370 call *%rdi
30371 addq $48, %rsp
30372 RESTORE_XMM
30373+ pax_force_retaddr 0, 1
30374 ret
30375 ENDPROC(efi_call6)
30376diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30377index e31bcd8..f12dc46 100644
30378--- a/arch/x86/platform/mrst/mrst.c
30379+++ b/arch/x86/platform/mrst/mrst.c
30380@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30381 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30382 int sfi_mrtc_num;
30383
30384-static void mrst_power_off(void)
30385+static __noreturn void mrst_power_off(void)
30386 {
30387+ BUG();
30388 }
30389
30390-static void mrst_reboot(void)
30391+static __noreturn void mrst_reboot(void)
30392 {
30393 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30394+ BUG();
30395 }
30396
30397 /* parse all the mtimer info to a static mtimer array */
30398diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30399index d6ee929..3637cb5 100644
30400--- a/arch/x86/platform/olpc/olpc_dt.c
30401+++ b/arch/x86/platform/olpc/olpc_dt.c
30402@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30403 return res;
30404 }
30405
30406-static struct of_pdt_ops prom_olpc_ops __initdata = {
30407+static struct of_pdt_ops prom_olpc_ops __initconst = {
30408 .nextprop = olpc_dt_nextprop,
30409 .getproplen = olpc_dt_getproplen,
30410 .getproperty = olpc_dt_getproperty,
30411diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30412index 120cee1..b2db75a 100644
30413--- a/arch/x86/power/cpu.c
30414+++ b/arch/x86/power/cpu.c
30415@@ -133,7 +133,7 @@ static void do_fpu_end(void)
30416 static void fix_processor_context(void)
30417 {
30418 int cpu = smp_processor_id();
30419- struct tss_struct *t = &per_cpu(init_tss, cpu);
30420+ struct tss_struct *t = init_tss + cpu;
30421
30422 set_tss_desc(cpu, t); /*
30423 * This just modifies memory; should not be
30424@@ -143,8 +143,6 @@ static void fix_processor_context(void)
30425 */
30426
30427 #ifdef CONFIG_X86_64
30428- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30429-
30430 syscall_init(); /* This sets MSR_*STAR and related */
30431 #endif
30432 load_TR_desc(); /* This does ltr */
30433diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30434index cbca565..bae7133 100644
30435--- a/arch/x86/realmode/init.c
30436+++ b/arch/x86/realmode/init.c
30437@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
30438 __va(real_mode_header->trampoline_header);
30439
30440 #ifdef CONFIG_X86_32
30441- trampoline_header->start = __pa(startup_32_smp);
30442+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
30443+
30444+#ifdef CONFIG_PAX_KERNEXEC
30445+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30446+#endif
30447+
30448+ trampoline_header->boot_cs = __BOOT_CS;
30449 trampoline_header->gdt_limit = __BOOT_DS + 7;
30450 trampoline_header->gdt_base = __pa(boot_gdt);
30451 #else
30452diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30453index 8869287..d577672 100644
30454--- a/arch/x86/realmode/rm/Makefile
30455+++ b/arch/x86/realmode/rm/Makefile
30456@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30457 $(call cc-option, -fno-unit-at-a-time)) \
30458 $(call cc-option, -fno-stack-protector) \
30459 $(call cc-option, -mpreferred-stack-boundary=2)
30460+ifdef CONSTIFY_PLUGIN
30461+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30462+endif
30463 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30464 GCOV_PROFILE := n
30465diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30466index a28221d..93c40f1 100644
30467--- a/arch/x86/realmode/rm/header.S
30468+++ b/arch/x86/realmode/rm/header.S
30469@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30470 #endif
30471 /* APM/BIOS reboot */
30472 .long pa_machine_real_restart_asm
30473-#ifdef CONFIG_X86_64
30474+#ifdef CONFIG_X86_32
30475+ .long __KERNEL_CS
30476+#else
30477 .long __KERNEL32_CS
30478 #endif
30479 END(real_mode_header)
30480diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30481index c1b2791..f9e31c7 100644
30482--- a/arch/x86/realmode/rm/trampoline_32.S
30483+++ b/arch/x86/realmode/rm/trampoline_32.S
30484@@ -25,6 +25,12 @@
30485 #include <asm/page_types.h>
30486 #include "realmode.h"
30487
30488+#ifdef CONFIG_PAX_KERNEXEC
30489+#define ta(X) (X)
30490+#else
30491+#define ta(X) (pa_ ## X)
30492+#endif
30493+
30494 .text
30495 .code16
30496
30497@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30498
30499 cli # We should be safe anyway
30500
30501- movl tr_start, %eax # where we need to go
30502-
30503 movl $0xA5A5A5A5, trampoline_status
30504 # write marker for master knows we're running
30505
30506@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30507 movw $1, %dx # protected mode (PE) bit
30508 lmsw %dx # into protected mode
30509
30510- ljmpl $__BOOT_CS, $pa_startup_32
30511+ ljmpl *(trampoline_header)
30512
30513 .section ".text32","ax"
30514 .code32
30515@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30516 .balign 8
30517 GLOBAL(trampoline_header)
30518 tr_start: .space 4
30519- tr_gdt_pad: .space 2
30520+ tr_boot_cs: .space 2
30521 tr_gdt: .space 6
30522 END(trampoline_header)
30523
30524diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30525index bb360dc..3e5945f 100644
30526--- a/arch/x86/realmode/rm/trampoline_64.S
30527+++ b/arch/x86/realmode/rm/trampoline_64.S
30528@@ -107,7 +107,7 @@ ENTRY(startup_32)
30529 wrmsr
30530
30531 # Enable paging and in turn activate Long Mode
30532- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30533+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30534 movl %eax, %cr0
30535
30536 /*
30537diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30538index 79d67bd..c7e1b90 100644
30539--- a/arch/x86/tools/relocs.c
30540+++ b/arch/x86/tools/relocs.c
30541@@ -12,10 +12,13 @@
30542 #include <regex.h>
30543 #include <tools/le_byteshift.h>
30544
30545+#include "../../../include/generated/autoconf.h"
30546+
30547 static void die(char *fmt, ...);
30548
30549 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30550 static Elf32_Ehdr ehdr;
30551+static Elf32_Phdr *phdr;
30552 static unsigned long reloc_count, reloc_idx;
30553 static unsigned long *relocs;
30554 static unsigned long reloc16_count, reloc16_idx;
30555@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30556 }
30557 }
30558
30559+static void read_phdrs(FILE *fp)
30560+{
30561+ unsigned int i;
30562+
30563+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30564+ if (!phdr) {
30565+ die("Unable to allocate %d program headers\n",
30566+ ehdr.e_phnum);
30567+ }
30568+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30569+ die("Seek to %d failed: %s\n",
30570+ ehdr.e_phoff, strerror(errno));
30571+ }
30572+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30573+ die("Cannot read ELF program headers: %s\n",
30574+ strerror(errno));
30575+ }
30576+ for(i = 0; i < ehdr.e_phnum; i++) {
30577+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30578+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30579+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30580+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30581+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30582+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30583+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30584+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30585+ }
30586+
30587+}
30588+
30589 static void read_shdrs(FILE *fp)
30590 {
30591- int i;
30592+ unsigned int i;
30593 Elf32_Shdr shdr;
30594
30595 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30596@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30597
30598 static void read_strtabs(FILE *fp)
30599 {
30600- int i;
30601+ unsigned int i;
30602 for (i = 0; i < ehdr.e_shnum; i++) {
30603 struct section *sec = &secs[i];
30604 if (sec->shdr.sh_type != SHT_STRTAB) {
30605@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30606
30607 static void read_symtabs(FILE *fp)
30608 {
30609- int i,j;
30610+ unsigned int i,j;
30611 for (i = 0; i < ehdr.e_shnum; i++) {
30612 struct section *sec = &secs[i];
30613 if (sec->shdr.sh_type != SHT_SYMTAB) {
30614@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30615 }
30616
30617
30618-static void read_relocs(FILE *fp)
30619+static void read_relocs(FILE *fp, int use_real_mode)
30620 {
30621- int i,j;
30622+ unsigned int i,j;
30623+ uint32_t base;
30624+
30625 for (i = 0; i < ehdr.e_shnum; i++) {
30626 struct section *sec = &secs[i];
30627 if (sec->shdr.sh_type != SHT_REL) {
30628@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
30629 die("Cannot read symbol table: %s\n",
30630 strerror(errno));
30631 }
30632+ base = 0;
30633+
30634+#ifdef CONFIG_X86_32
30635+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30636+ if (phdr[j].p_type != PT_LOAD )
30637+ continue;
30638+ 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)
30639+ continue;
30640+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30641+ break;
30642+ }
30643+#endif
30644+
30645 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
30646 Elf32_Rel *rel = &sec->reltab[j];
30647- rel->r_offset = elf32_to_cpu(rel->r_offset);
30648+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
30649 rel->r_info = elf32_to_cpu(rel->r_info);
30650 }
30651 }
30652@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
30653
30654 static void print_absolute_symbols(void)
30655 {
30656- int i;
30657+ unsigned int i;
30658 printf("Absolute symbols\n");
30659 printf(" Num: Value Size Type Bind Visibility Name\n");
30660 for (i = 0; i < ehdr.e_shnum; i++) {
30661 struct section *sec = &secs[i];
30662 char *sym_strtab;
30663- int j;
30664+ unsigned int j;
30665
30666 if (sec->shdr.sh_type != SHT_SYMTAB) {
30667 continue;
30668@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
30669
30670 static void print_absolute_relocs(void)
30671 {
30672- int i, printed = 0;
30673+ unsigned int i, printed = 0;
30674
30675 for (i = 0; i < ehdr.e_shnum; i++) {
30676 struct section *sec = &secs[i];
30677 struct section *sec_applies, *sec_symtab;
30678 char *sym_strtab;
30679 Elf32_Sym *sh_symtab;
30680- int j;
30681+ unsigned int j;
30682 if (sec->shdr.sh_type != SHT_REL) {
30683 continue;
30684 }
30685@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
30686 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30687 int use_real_mode)
30688 {
30689- int i;
30690+ unsigned int i;
30691 /* Walk through the relocations */
30692 for (i = 0; i < ehdr.e_shnum; i++) {
30693 char *sym_strtab;
30694 Elf32_Sym *sh_symtab;
30695 struct section *sec_applies, *sec_symtab;
30696- int j;
30697+ unsigned int j;
30698 struct section *sec = &secs[i];
30699
30700 if (sec->shdr.sh_type != SHT_REL) {
30701@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30702 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
30703 r_type = ELF32_R_TYPE(rel->r_info);
30704
30705+ if (!use_real_mode) {
30706+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
30707+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
30708+ continue;
30709+
30710+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
30711+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
30712+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
30713+ continue;
30714+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
30715+ continue;
30716+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
30717+ continue;
30718+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
30719+ continue;
30720+#endif
30721+ }
30722+
30723 shn_abs = sym->st_shndx == SHN_ABS;
30724
30725 switch (r_type) {
30726@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30727
30728 static void emit_relocs(int as_text, int use_real_mode)
30729 {
30730- int i;
30731+ unsigned int i;
30732 /* Count how many relocations I have and allocate space for them. */
30733 reloc_count = 0;
30734 walk_relocs(count_reloc, use_real_mode);
30735@@ -808,10 +874,11 @@ int main(int argc, char **argv)
30736 fname, strerror(errno));
30737 }
30738 read_ehdr(fp);
30739+ read_phdrs(fp);
30740 read_shdrs(fp);
30741 read_strtabs(fp);
30742 read_symtabs(fp);
30743- read_relocs(fp);
30744+ read_relocs(fp, use_real_mode);
30745 if (show_absolute_syms) {
30746 print_absolute_symbols();
30747 goto out;
30748diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
30749index fd14be1..e3c79c0 100644
30750--- a/arch/x86/vdso/Makefile
30751+++ b/arch/x86/vdso/Makefile
30752@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
30753 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
30754 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
30755
30756-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30757+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30758 GCOV_PROFILE := n
30759
30760 #
30761diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
30762index 0faad64..39ef157 100644
30763--- a/arch/x86/vdso/vdso32-setup.c
30764+++ b/arch/x86/vdso/vdso32-setup.c
30765@@ -25,6 +25,7 @@
30766 #include <asm/tlbflush.h>
30767 #include <asm/vdso.h>
30768 #include <asm/proto.h>
30769+#include <asm/mman.h>
30770
30771 enum {
30772 VDSO_DISABLED = 0,
30773@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
30774 void enable_sep_cpu(void)
30775 {
30776 int cpu = get_cpu();
30777- struct tss_struct *tss = &per_cpu(init_tss, cpu);
30778+ struct tss_struct *tss = init_tss + cpu;
30779
30780 if (!boot_cpu_has(X86_FEATURE_SEP)) {
30781 put_cpu();
30782@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
30783 gate_vma.vm_start = FIXADDR_USER_START;
30784 gate_vma.vm_end = FIXADDR_USER_END;
30785 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
30786- gate_vma.vm_page_prot = __P101;
30787+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
30788
30789 return 0;
30790 }
30791@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30792 if (compat)
30793 addr = VDSO_HIGH_BASE;
30794 else {
30795- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
30796+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
30797 if (IS_ERR_VALUE(addr)) {
30798 ret = addr;
30799 goto up_fail;
30800 }
30801 }
30802
30803- current->mm->context.vdso = (void *)addr;
30804+ current->mm->context.vdso = addr;
30805
30806 if (compat_uses_vma || !compat) {
30807 /*
30808@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30809 }
30810
30811 current_thread_info()->sysenter_return =
30812- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30813+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30814
30815 up_fail:
30816 if (ret)
30817- current->mm->context.vdso = NULL;
30818+ current->mm->context.vdso = 0;
30819
30820 up_write(&mm->mmap_sem);
30821
30822@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30823
30824 const char *arch_vma_name(struct vm_area_struct *vma)
30825 {
30826- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30827+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30828 return "[vdso]";
30829+
30830+#ifdef CONFIG_PAX_SEGMEXEC
30831+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30832+ return "[vdso]";
30833+#endif
30834+
30835 return NULL;
30836 }
30837
30838@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30839 * Check to see if the corresponding task was created in compat vdso
30840 * mode.
30841 */
30842- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30843+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30844 return &gate_vma;
30845 return NULL;
30846 }
30847diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30848index 431e875..cbb23f3 100644
30849--- a/arch/x86/vdso/vma.c
30850+++ b/arch/x86/vdso/vma.c
30851@@ -16,8 +16,6 @@
30852 #include <asm/vdso.h>
30853 #include <asm/page.h>
30854
30855-unsigned int __read_mostly vdso_enabled = 1;
30856-
30857 extern char vdso_start[], vdso_end[];
30858 extern unsigned short vdso_sync_cpuid;
30859
30860@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30861 * unaligned here as a result of stack start randomization.
30862 */
30863 addr = PAGE_ALIGN(addr);
30864- addr = align_vdso_addr(addr);
30865
30866 return addr;
30867 }
30868@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30869 unsigned size)
30870 {
30871 struct mm_struct *mm = current->mm;
30872- unsigned long addr;
30873+ unsigned long addr = 0;
30874 int ret;
30875
30876- if (!vdso_enabled)
30877- return 0;
30878-
30879 down_write(&mm->mmap_sem);
30880+
30881+#ifdef CONFIG_PAX_RANDMMAP
30882+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30883+#endif
30884+
30885 addr = vdso_addr(mm->start_stack, size);
30886+ addr = align_vdso_addr(addr);
30887 addr = get_unmapped_area(NULL, addr, size, 0, 0);
30888 if (IS_ERR_VALUE(addr)) {
30889 ret = addr;
30890 goto up_fail;
30891 }
30892
30893- current->mm->context.vdso = (void *)addr;
30894+ mm->context.vdso = addr;
30895
30896 ret = install_special_mapping(mm, addr, size,
30897 VM_READ|VM_EXEC|
30898 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
30899 pages);
30900- if (ret) {
30901- current->mm->context.vdso = NULL;
30902- goto up_fail;
30903- }
30904+ if (ret)
30905+ mm->context.vdso = 0;
30906
30907 up_fail:
30908 up_write(&mm->mmap_sem);
30909@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30910 vdsox32_size);
30911 }
30912 #endif
30913-
30914-static __init int vdso_setup(char *s)
30915-{
30916- vdso_enabled = simple_strtoul(s, NULL, 0);
30917- return 0;
30918-}
30919-__setup("vdso=", vdso_setup);
30920diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
30921index 2262003..f229ced 100644
30922--- a/arch/x86/xen/enlighten.c
30923+++ b/arch/x86/xen/enlighten.c
30924@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
30925
30926 struct shared_info xen_dummy_shared_info;
30927
30928-void *xen_initial_gdt;
30929-
30930 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
30931 __read_mostly int xen_have_vector_callback;
30932 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
30933@@ -496,8 +494,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
30934 {
30935 unsigned long va = dtr->address;
30936 unsigned int size = dtr->size + 1;
30937- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30938- unsigned long frames[pages];
30939+ unsigned long frames[65536 / PAGE_SIZE];
30940 int f;
30941
30942 /*
30943@@ -545,8 +542,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
30944 {
30945 unsigned long va = dtr->address;
30946 unsigned int size = dtr->size + 1;
30947- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30948- unsigned long frames[pages];
30949+ unsigned long frames[65536 / PAGE_SIZE];
30950 int f;
30951
30952 /*
30953@@ -939,7 +935,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
30954 return 0;
30955 }
30956
30957-static void set_xen_basic_apic_ops(void)
30958+static void __init set_xen_basic_apic_ops(void)
30959 {
30960 apic->read = xen_apic_read;
30961 apic->write = xen_apic_write;
30962@@ -1245,30 +1241,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
30963 #endif
30964 };
30965
30966-static void xen_reboot(int reason)
30967+static __noreturn void xen_reboot(int reason)
30968 {
30969 struct sched_shutdown r = { .reason = reason };
30970
30971- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
30972- BUG();
30973+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
30974+ BUG();
30975 }
30976
30977-static void xen_restart(char *msg)
30978+static __noreturn void xen_restart(char *msg)
30979 {
30980 xen_reboot(SHUTDOWN_reboot);
30981 }
30982
30983-static void xen_emergency_restart(void)
30984+static __noreturn void xen_emergency_restart(void)
30985 {
30986 xen_reboot(SHUTDOWN_reboot);
30987 }
30988
30989-static void xen_machine_halt(void)
30990+static __noreturn void xen_machine_halt(void)
30991 {
30992 xen_reboot(SHUTDOWN_poweroff);
30993 }
30994
30995-static void xen_machine_power_off(void)
30996+static __noreturn void xen_machine_power_off(void)
30997 {
30998 if (pm_power_off)
30999 pm_power_off();
31000@@ -1370,7 +1366,17 @@ asmlinkage void __init xen_start_kernel(void)
31001 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31002
31003 /* Work out if we support NX */
31004- x86_configure_nx();
31005+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31006+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31007+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31008+ unsigned l, h;
31009+
31010+ __supported_pte_mask |= _PAGE_NX;
31011+ rdmsr(MSR_EFER, l, h);
31012+ l |= EFER_NX;
31013+ wrmsr(MSR_EFER, l, h);
31014+ }
31015+#endif
31016
31017 xen_setup_features();
31018
31019@@ -1399,14 +1405,7 @@ asmlinkage void __init xen_start_kernel(void)
31020 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
31021 }
31022
31023- machine_ops = xen_machine_ops;
31024-
31025- /*
31026- * The only reliable way to retain the initial address of the
31027- * percpu gdt_page is to remember it here, so we can go and
31028- * mark it RW later, when the initial percpu area is freed.
31029- */
31030- xen_initial_gdt = &per_cpu(gdt_page, 0);
31031+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
31032
31033 xen_smp_init();
31034
31035@@ -1598,7 +1597,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31036 return NOTIFY_OK;
31037 }
31038
31039-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31040+static struct notifier_block xen_hvm_cpu_notifier = {
31041 .notifier_call = xen_hvm_cpu_notify,
31042 };
31043
31044diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31045index 01de35c..0bda07b 100644
31046--- a/arch/x86/xen/mmu.c
31047+++ b/arch/x86/xen/mmu.c
31048@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31049 /* L3_k[510] -> level2_kernel_pgt
31050 * L3_i[511] -> level2_fixmap_pgt */
31051 convert_pfn_mfn(level3_kernel_pgt);
31052+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31053+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31054+ convert_pfn_mfn(level3_vmemmap_pgt);
31055
31056 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31057 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31058@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31059 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31060 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31061 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31062+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31063+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31064+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31065 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31066 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31067+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31068 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31069 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31070
31071@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
31072 pv_mmu_ops.set_pud = xen_set_pud;
31073 #if PAGETABLE_LEVELS == 4
31074 pv_mmu_ops.set_pgd = xen_set_pgd;
31075+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31076 #endif
31077
31078 /* This will work as long as patching hasn't happened yet
31079@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31080 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31081 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31082 .set_pgd = xen_set_pgd_hyper,
31083+ .set_pgd_batched = xen_set_pgd_hyper,
31084
31085 .alloc_pud = xen_alloc_pmd_init,
31086 .release_pud = xen_release_pmd_init,
31087diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31088index 34bc4ce..c34aa24 100644
31089--- a/arch/x86/xen/smp.c
31090+++ b/arch/x86/xen/smp.c
31091@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31092 {
31093 BUG_ON(smp_processor_id() != 0);
31094 native_smp_prepare_boot_cpu();
31095-
31096- /* We've switched to the "real" per-cpu gdt, so make sure the
31097- old memory can be recycled */
31098- make_lowmem_page_readwrite(xen_initial_gdt);
31099-
31100 xen_filter_cpu_maps();
31101 xen_setup_vcpu_info_placement();
31102 }
31103@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31104 gdt = get_cpu_gdt_table(cpu);
31105
31106 ctxt->flags = VGCF_IN_KERNEL;
31107- ctxt->user_regs.ds = __USER_DS;
31108- ctxt->user_regs.es = __USER_DS;
31109+ ctxt->user_regs.ds = __KERNEL_DS;
31110+ ctxt->user_regs.es = __KERNEL_DS;
31111 ctxt->user_regs.ss = __KERNEL_DS;
31112 #ifdef CONFIG_X86_32
31113 ctxt->user_regs.fs = __KERNEL_PERCPU;
31114- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31115+ savesegment(gs, ctxt->user_regs.gs);
31116 #else
31117 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31118 #endif
31119@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31120 int rc;
31121
31122 per_cpu(current_task, cpu) = idle;
31123+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31124 #ifdef CONFIG_X86_32
31125 irq_ctx_init(cpu);
31126 #else
31127 clear_tsk_thread_flag(idle, TIF_FORK);
31128- per_cpu(kernel_stack, cpu) =
31129- (unsigned long)task_stack_page(idle) -
31130- KERNEL_STACK_OFFSET + THREAD_SIZE;
31131+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31132 #endif
31133 xen_setup_runstate_info(cpu);
31134 xen_setup_timer(cpu);
31135@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31136
31137 void __init xen_smp_init(void)
31138 {
31139- smp_ops = xen_smp_ops;
31140+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31141 xen_fill_possible_map();
31142 xen_init_spinlocks();
31143 }
31144diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31145index 33ca6e4..0ded929 100644
31146--- a/arch/x86/xen/xen-asm_32.S
31147+++ b/arch/x86/xen/xen-asm_32.S
31148@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31149 ESP_OFFSET=4 # bytes pushed onto stack
31150
31151 /*
31152- * Store vcpu_info pointer for easy access. Do it this way to
31153- * avoid having to reload %fs
31154+ * Store vcpu_info pointer for easy access.
31155 */
31156 #ifdef CONFIG_SMP
31157- GET_THREAD_INFO(%eax)
31158- movl %ss:TI_cpu(%eax), %eax
31159- movl %ss:__per_cpu_offset(,%eax,4), %eax
31160- mov %ss:xen_vcpu(%eax), %eax
31161+ push %fs
31162+ mov $(__KERNEL_PERCPU), %eax
31163+ mov %eax, %fs
31164+ mov PER_CPU_VAR(xen_vcpu), %eax
31165+ pop %fs
31166 #else
31167 movl %ss:xen_vcpu, %eax
31168 #endif
31169diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31170index 7faed58..ba4427c 100644
31171--- a/arch/x86/xen/xen-head.S
31172+++ b/arch/x86/xen/xen-head.S
31173@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31174 #ifdef CONFIG_X86_32
31175 mov %esi,xen_start_info
31176 mov $init_thread_union+THREAD_SIZE,%esp
31177+#ifdef CONFIG_SMP
31178+ movl $cpu_gdt_table,%edi
31179+ movl $__per_cpu_load,%eax
31180+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31181+ rorl $16,%eax
31182+ movb %al,__KERNEL_PERCPU + 4(%edi)
31183+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31184+ movl $__per_cpu_end - 1,%eax
31185+ subl $__per_cpu_start,%eax
31186+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31187+#endif
31188 #else
31189 mov %rsi,xen_start_info
31190 mov $init_thread_union+THREAD_SIZE,%rsp
31191diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31192index a95b417..b6dbd0b 100644
31193--- a/arch/x86/xen/xen-ops.h
31194+++ b/arch/x86/xen/xen-ops.h
31195@@ -10,8 +10,6 @@
31196 extern const char xen_hypervisor_callback[];
31197 extern const char xen_failsafe_callback[];
31198
31199-extern void *xen_initial_gdt;
31200-
31201 struct trap_info;
31202 void xen_copy_trap_info(struct trap_info *traps);
31203
31204diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31205index 525bd3d..ef888b1 100644
31206--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31207+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31208@@ -119,9 +119,9 @@
31209 ----------------------------------------------------------------------*/
31210
31211 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31212-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31213 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31214 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31215+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31216
31217 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31218 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31219diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31220index 2f33760..835e50a 100644
31221--- a/arch/xtensa/variants/fsf/include/variant/core.h
31222+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31223@@ -11,6 +11,7 @@
31224 #ifndef _XTENSA_CORE_H
31225 #define _XTENSA_CORE_H
31226
31227+#include <linux/const.h>
31228
31229 /****************************************************************************
31230 Parameters Useful for Any Code, USER or PRIVILEGED
31231@@ -112,9 +113,9 @@
31232 ----------------------------------------------------------------------*/
31233
31234 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31235-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31236 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31237 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31238+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31239
31240 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31241 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31242diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31243index af00795..2bb8105 100644
31244--- a/arch/xtensa/variants/s6000/include/variant/core.h
31245+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31246@@ -11,6 +11,7 @@
31247 #ifndef _XTENSA_CORE_CONFIGURATION_H
31248 #define _XTENSA_CORE_CONFIGURATION_H
31249
31250+#include <linux/const.h>
31251
31252 /****************************************************************************
31253 Parameters Useful for Any Code, USER or PRIVILEGED
31254@@ -118,9 +119,9 @@
31255 ----------------------------------------------------------------------*/
31256
31257 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31258-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31259 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31260 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31261+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31262
31263 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31264 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31265diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31266index 58916af..eb9dbcf6 100644
31267--- a/block/blk-iopoll.c
31268+++ b/block/blk-iopoll.c
31269@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31270 }
31271 EXPORT_SYMBOL(blk_iopoll_complete);
31272
31273-static void blk_iopoll_softirq(struct softirq_action *h)
31274+static void blk_iopoll_softirq(void)
31275 {
31276 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31277 int rearm = 0, budget = blk_iopoll_budget;
31278@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31279 return NOTIFY_OK;
31280 }
31281
31282-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31283+static struct notifier_block blk_iopoll_cpu_notifier = {
31284 .notifier_call = blk_iopoll_cpu_notify,
31285 };
31286
31287diff --git a/block/blk-map.c b/block/blk-map.c
31288index 623e1cd..ca1e109 100644
31289--- a/block/blk-map.c
31290+++ b/block/blk-map.c
31291@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31292 if (!len || !kbuf)
31293 return -EINVAL;
31294
31295- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31296+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31297 if (do_copy)
31298 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31299 else
31300diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31301index 467c8de..f3628c5 100644
31302--- a/block/blk-softirq.c
31303+++ b/block/blk-softirq.c
31304@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31305 * Softirq action handler - move entries to local list and loop over them
31306 * while passing them to the queue registered handler.
31307 */
31308-static void blk_done_softirq(struct softirq_action *h)
31309+static void blk_done_softirq(void)
31310 {
31311 struct list_head *cpu_list, local_list;
31312
31313@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31314 return NOTIFY_OK;
31315 }
31316
31317-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31318+static struct notifier_block blk_cpu_notifier = {
31319 .notifier_call = blk_cpu_notify,
31320 };
31321
31322diff --git a/block/bsg.c b/block/bsg.c
31323index ff64ae3..593560c 100644
31324--- a/block/bsg.c
31325+++ b/block/bsg.c
31326@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31327 struct sg_io_v4 *hdr, struct bsg_device *bd,
31328 fmode_t has_write_perm)
31329 {
31330+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31331+ unsigned char *cmdptr;
31332+
31333 if (hdr->request_len > BLK_MAX_CDB) {
31334 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31335 if (!rq->cmd)
31336 return -ENOMEM;
31337- }
31338+ cmdptr = rq->cmd;
31339+ } else
31340+ cmdptr = tmpcmd;
31341
31342- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31343+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31344 hdr->request_len))
31345 return -EFAULT;
31346
31347+ if (cmdptr != rq->cmd)
31348+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31349+
31350 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31351 if (blk_verify_command(rq->cmd, has_write_perm))
31352 return -EPERM;
31353diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31354index 7c668c8..db3521c 100644
31355--- a/block/compat_ioctl.c
31356+++ b/block/compat_ioctl.c
31357@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31358 err |= __get_user(f->spec1, &uf->spec1);
31359 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31360 err |= __get_user(name, &uf->name);
31361- f->name = compat_ptr(name);
31362+ f->name = (void __force_kernel *)compat_ptr(name);
31363 if (err) {
31364 err = -EFAULT;
31365 goto out;
31366diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31367index b62fb88..bdab4c4 100644
31368--- a/block/partitions/efi.c
31369+++ b/block/partitions/efi.c
31370@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31371 if (!gpt)
31372 return NULL;
31373
31374+ if (!le32_to_cpu(gpt->num_partition_entries))
31375+ return NULL;
31376+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31377+ if (!pte)
31378+ return NULL;
31379+
31380 count = le32_to_cpu(gpt->num_partition_entries) *
31381 le32_to_cpu(gpt->sizeof_partition_entry);
31382- if (!count)
31383- return NULL;
31384- pte = kzalloc(count, GFP_KERNEL);
31385- if (!pte)
31386- return NULL;
31387-
31388 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31389 (u8 *) pte,
31390 count) < count) {
31391diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31392index 9a87daa..fb17486 100644
31393--- a/block/scsi_ioctl.c
31394+++ b/block/scsi_ioctl.c
31395@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31396 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31397 struct sg_io_hdr *hdr, fmode_t mode)
31398 {
31399- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31400+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31401+ unsigned char *cmdptr;
31402+
31403+ if (rq->cmd != rq->__cmd)
31404+ cmdptr = rq->cmd;
31405+ else
31406+ cmdptr = tmpcmd;
31407+
31408+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31409 return -EFAULT;
31410+
31411+ if (cmdptr != rq->cmd)
31412+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31413+
31414 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31415 return -EPERM;
31416
31417@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31418 int err;
31419 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31420 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31421+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31422+ unsigned char *cmdptr;
31423
31424 if (!sic)
31425 return -EINVAL;
31426@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31427 */
31428 err = -EFAULT;
31429 rq->cmd_len = cmdlen;
31430- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31431+
31432+ if (rq->cmd != rq->__cmd)
31433+ cmdptr = rq->cmd;
31434+ else
31435+ cmdptr = tmpcmd;
31436+
31437+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31438 goto error;
31439
31440+ if (rq->cmd != cmdptr)
31441+ memcpy(rq->cmd, cmdptr, cmdlen);
31442+
31443 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31444 goto error;
31445
31446diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31447index 7bdd61b..afec999 100644
31448--- a/crypto/cryptd.c
31449+++ b/crypto/cryptd.c
31450@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31451
31452 struct cryptd_blkcipher_request_ctx {
31453 crypto_completion_t complete;
31454-};
31455+} __no_const;
31456
31457 struct cryptd_hash_ctx {
31458 struct crypto_shash *child;
31459@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31460
31461 struct cryptd_aead_request_ctx {
31462 crypto_completion_t complete;
31463-};
31464+} __no_const;
31465
31466 static void cryptd_queue_worker(struct work_struct *work);
31467
31468diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
31469index f6d9baf..dfd511f 100644
31470--- a/crypto/crypto_user.c
31471+++ b/crypto/crypto_user.c
31472@@ -30,6 +30,8 @@
31473
31474 #include "internal.h"
31475
31476+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
31477+
31478 static DEFINE_MUTEX(crypto_cfg_mutex);
31479
31480 /* The crypto netlink socket */
31481@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
31482 struct crypto_dump_info info;
31483 int err;
31484
31485- if (!p->cru_driver_name)
31486+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31487+ return -EINVAL;
31488+
31489+ if (!p->cru_driver_name[0])
31490 return -EINVAL;
31491
31492 alg = crypto_alg_match(p, 1);
31493@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31494 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31495 LIST_HEAD(list);
31496
31497+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31498+ return -EINVAL;
31499+
31500 if (priority && !strlen(p->cru_driver_name))
31501 return -EINVAL;
31502
31503@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31504 struct crypto_alg *alg;
31505 struct crypto_user_alg *p = nlmsg_data(nlh);
31506
31507+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31508+ return -EINVAL;
31509+
31510 alg = crypto_alg_match(p, 1);
31511 if (!alg)
31512 return -ENOENT;
31513@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31514 struct crypto_user_alg *p = nlmsg_data(nlh);
31515 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31516
31517+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31518+ return -EINVAL;
31519+
31520 if (strlen(p->cru_driver_name))
31521 exact = 1;
31522
31523diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31524index f220d64..d359ad6 100644
31525--- a/drivers/acpi/apei/apei-internal.h
31526+++ b/drivers/acpi/apei/apei-internal.h
31527@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31528 struct apei_exec_ins_type {
31529 u32 flags;
31530 apei_exec_ins_func_t run;
31531-};
31532+} __do_const;
31533
31534 struct apei_exec_context {
31535 u32 ip;
31536diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31537index e6defd8..c26a225 100644
31538--- a/drivers/acpi/apei/cper.c
31539+++ b/drivers/acpi/apei/cper.c
31540@@ -38,12 +38,12 @@
31541 */
31542 u64 cper_next_record_id(void)
31543 {
31544- static atomic64_t seq;
31545+ static atomic64_unchecked_t seq;
31546
31547- if (!atomic64_read(&seq))
31548- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31549+ if (!atomic64_read_unchecked(&seq))
31550+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31551
31552- return atomic64_inc_return(&seq);
31553+ return atomic64_inc_return_unchecked(&seq);
31554 }
31555 EXPORT_SYMBOL_GPL(cper_next_record_id);
31556
31557diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31558index be60399..778b33e8 100644
31559--- a/drivers/acpi/bgrt.c
31560+++ b/drivers/acpi/bgrt.c
31561@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31562 return -ENODEV;
31563
31564 sysfs_bin_attr_init(&image_attr);
31565- image_attr.private = bgrt_image;
31566- image_attr.size = bgrt_image_size;
31567+ pax_open_kernel();
31568+ *(void **)&image_attr.private = bgrt_image;
31569+ *(size_t *)&image_attr.size = bgrt_image_size;
31570+ pax_close_kernel();
31571
31572 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31573 if (!bgrt_kobj)
31574diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31575index cb96296..b81293b 100644
31576--- a/drivers/acpi/blacklist.c
31577+++ b/drivers/acpi/blacklist.c
31578@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31579 u32 is_critical_error;
31580 };
31581
31582-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31583+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31584
31585 /*
31586 * POLICY: If *anything* doesn't work, put it on the blacklist.
31587@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31588 return 0;
31589 }
31590
31591-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31592+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31593 {
31594 .callback = dmi_disable_osi_vista,
31595 .ident = "Fujitsu Siemens",
31596diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31597index 7586544..636a2f0 100644
31598--- a/drivers/acpi/ec_sys.c
31599+++ b/drivers/acpi/ec_sys.c
31600@@ -12,6 +12,7 @@
31601 #include <linux/acpi.h>
31602 #include <linux/debugfs.h>
31603 #include <linux/module.h>
31604+#include <linux/uaccess.h>
31605 #include "internal.h"
31606
31607 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31608@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31609 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31610 */
31611 unsigned int size = EC_SPACE_SIZE;
31612- u8 *data = (u8 *) buf;
31613+ u8 data;
31614 loff_t init_off = *off;
31615 int err = 0;
31616
31617@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31618 size = count;
31619
31620 while (size) {
31621- err = ec_read(*off, &data[*off - init_off]);
31622+ err = ec_read(*off, &data);
31623 if (err)
31624 return err;
31625+ if (put_user(data, &buf[*off - init_off]))
31626+ return -EFAULT;
31627 *off += 1;
31628 size--;
31629 }
31630@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31631
31632 unsigned int size = count;
31633 loff_t init_off = *off;
31634- u8 *data = (u8 *) buf;
31635 int err = 0;
31636
31637 if (*off >= EC_SPACE_SIZE)
31638@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31639 }
31640
31641 while (size) {
31642- u8 byte_write = data[*off - init_off];
31643+ u8 byte_write;
31644+ if (get_user(byte_write, &buf[*off - init_off]))
31645+ return -EFAULT;
31646 err = ec_write(*off, byte_write);
31647 if (err)
31648 return err;
31649diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
31650index e83311b..142b5cc 100644
31651--- a/drivers/acpi/processor_driver.c
31652+++ b/drivers/acpi/processor_driver.c
31653@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
31654 return 0;
31655 #endif
31656
31657- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
31658+ BUG_ON(pr->id >= nr_cpu_ids);
31659
31660 /*
31661 * Buggy BIOS check
31662diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31663index ed9a1cc..f4a354c 100644
31664--- a/drivers/acpi/processor_idle.c
31665+++ b/drivers/acpi/processor_idle.c
31666@@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
31667 {
31668 int i, count = CPUIDLE_DRIVER_STATE_START;
31669 struct acpi_processor_cx *cx;
31670- struct cpuidle_state *state;
31671+ cpuidle_state_no_const *state;
31672 struct cpuidle_driver *drv = &acpi_idle_driver;
31673
31674 if (!pr->flags.power_setup_done)
31675diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
31676index ea61ca9..3fdd70d 100644
31677--- a/drivers/acpi/sysfs.c
31678+++ b/drivers/acpi/sysfs.c
31679@@ -420,11 +420,11 @@ static u32 num_counters;
31680 static struct attribute **all_attrs;
31681 static u32 acpi_gpe_count;
31682
31683-static struct attribute_group interrupt_stats_attr_group = {
31684+static attribute_group_no_const interrupt_stats_attr_group = {
31685 .name = "interrupts",
31686 };
31687
31688-static struct kobj_attribute *counter_attrs;
31689+static kobj_attribute_no_const *counter_attrs;
31690
31691 static void delete_gpe_attr_array(void)
31692 {
31693diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
31694index 6cd7805..07facb3 100644
31695--- a/drivers/ata/libahci.c
31696+++ b/drivers/ata/libahci.c
31697@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
31698 }
31699 EXPORT_SYMBOL_GPL(ahci_kick_engine);
31700
31701-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31702+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31703 struct ata_taskfile *tf, int is_cmd, u16 flags,
31704 unsigned long timeout_msec)
31705 {
31706diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31707index 46cd3f4..0871ad0 100644
31708--- a/drivers/ata/libata-core.c
31709+++ b/drivers/ata/libata-core.c
31710@@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31711 struct ata_port *ap;
31712 unsigned int tag;
31713
31714- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31715+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31716 ap = qc->ap;
31717
31718 qc->flags = 0;
31719@@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
31720 struct ata_port *ap;
31721 struct ata_link *link;
31722
31723- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31724+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31725 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31726 ap = qc->ap;
31727 link = qc->dev->link;
31728@@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31729 return;
31730
31731 spin_lock(&lock);
31732+ pax_open_kernel();
31733
31734 for (cur = ops->inherits; cur; cur = cur->inherits) {
31735 void **inherit = (void **)cur;
31736@@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31737 if (IS_ERR(*pp))
31738 *pp = NULL;
31739
31740- ops->inherits = NULL;
31741+ *(struct ata_port_operations **)&ops->inherits = NULL;
31742
31743+ pax_close_kernel();
31744 spin_unlock(&lock);
31745 }
31746
31747diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31748index 405022d..fb70e53 100644
31749--- a/drivers/ata/pata_arasan_cf.c
31750+++ b/drivers/ata/pata_arasan_cf.c
31751@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31752 /* Handle platform specific quirks */
31753 if (pdata->quirk) {
31754 if (pdata->quirk & CF_BROKEN_PIO) {
31755- ap->ops->set_piomode = NULL;
31756+ pax_open_kernel();
31757+ *(void **)&ap->ops->set_piomode = NULL;
31758+ pax_close_kernel();
31759 ap->pio_mask = 0;
31760 }
31761 if (pdata->quirk & CF_BROKEN_MWDMA)
31762diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31763index f9b983a..887b9d8 100644
31764--- a/drivers/atm/adummy.c
31765+++ b/drivers/atm/adummy.c
31766@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31767 vcc->pop(vcc, skb);
31768 else
31769 dev_kfree_skb_any(skb);
31770- atomic_inc(&vcc->stats->tx);
31771+ atomic_inc_unchecked(&vcc->stats->tx);
31772
31773 return 0;
31774 }
31775diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31776index 77a7480..05cde58 100644
31777--- a/drivers/atm/ambassador.c
31778+++ b/drivers/atm/ambassador.c
31779@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31780 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31781
31782 // VC layer stats
31783- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31784+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31785
31786 // free the descriptor
31787 kfree (tx_descr);
31788@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31789 dump_skb ("<<<", vc, skb);
31790
31791 // VC layer stats
31792- atomic_inc(&atm_vcc->stats->rx);
31793+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31794 __net_timestamp(skb);
31795 // end of our responsibility
31796 atm_vcc->push (atm_vcc, skb);
31797@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31798 } else {
31799 PRINTK (KERN_INFO, "dropped over-size frame");
31800 // should we count this?
31801- atomic_inc(&atm_vcc->stats->rx_drop);
31802+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31803 }
31804
31805 } else {
31806@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31807 }
31808
31809 if (check_area (skb->data, skb->len)) {
31810- atomic_inc(&atm_vcc->stats->tx_err);
31811+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31812 return -ENOMEM; // ?
31813 }
31814
31815diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31816index b22d71c..d6e1049 100644
31817--- a/drivers/atm/atmtcp.c
31818+++ b/drivers/atm/atmtcp.c
31819@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31820 if (vcc->pop) vcc->pop(vcc,skb);
31821 else dev_kfree_skb(skb);
31822 if (dev_data) return 0;
31823- atomic_inc(&vcc->stats->tx_err);
31824+ atomic_inc_unchecked(&vcc->stats->tx_err);
31825 return -ENOLINK;
31826 }
31827 size = skb->len+sizeof(struct atmtcp_hdr);
31828@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31829 if (!new_skb) {
31830 if (vcc->pop) vcc->pop(vcc,skb);
31831 else dev_kfree_skb(skb);
31832- atomic_inc(&vcc->stats->tx_err);
31833+ atomic_inc_unchecked(&vcc->stats->tx_err);
31834 return -ENOBUFS;
31835 }
31836 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31837@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31838 if (vcc->pop) vcc->pop(vcc,skb);
31839 else dev_kfree_skb(skb);
31840 out_vcc->push(out_vcc,new_skb);
31841- atomic_inc(&vcc->stats->tx);
31842- atomic_inc(&out_vcc->stats->rx);
31843+ atomic_inc_unchecked(&vcc->stats->tx);
31844+ atomic_inc_unchecked(&out_vcc->stats->rx);
31845 return 0;
31846 }
31847
31848@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31849 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31850 read_unlock(&vcc_sklist_lock);
31851 if (!out_vcc) {
31852- atomic_inc(&vcc->stats->tx_err);
31853+ atomic_inc_unchecked(&vcc->stats->tx_err);
31854 goto done;
31855 }
31856 skb_pull(skb,sizeof(struct atmtcp_hdr));
31857@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31858 __net_timestamp(new_skb);
31859 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31860 out_vcc->push(out_vcc,new_skb);
31861- atomic_inc(&vcc->stats->tx);
31862- atomic_inc(&out_vcc->stats->rx);
31863+ atomic_inc_unchecked(&vcc->stats->tx);
31864+ atomic_inc_unchecked(&out_vcc->stats->rx);
31865 done:
31866 if (vcc->pop) vcc->pop(vcc,skb);
31867 else dev_kfree_skb(skb);
31868diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31869index c1eb6fa..4c71be9 100644
31870--- a/drivers/atm/eni.c
31871+++ b/drivers/atm/eni.c
31872@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31873 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31874 vcc->dev->number);
31875 length = 0;
31876- atomic_inc(&vcc->stats->rx_err);
31877+ atomic_inc_unchecked(&vcc->stats->rx_err);
31878 }
31879 else {
31880 length = ATM_CELL_SIZE-1; /* no HEC */
31881@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31882 size);
31883 }
31884 eff = length = 0;
31885- atomic_inc(&vcc->stats->rx_err);
31886+ atomic_inc_unchecked(&vcc->stats->rx_err);
31887 }
31888 else {
31889 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
31890@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31891 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
31892 vcc->dev->number,vcc->vci,length,size << 2,descr);
31893 length = eff = 0;
31894- atomic_inc(&vcc->stats->rx_err);
31895+ atomic_inc_unchecked(&vcc->stats->rx_err);
31896 }
31897 }
31898 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
31899@@ -767,7 +767,7 @@ rx_dequeued++;
31900 vcc->push(vcc,skb);
31901 pushed++;
31902 }
31903- atomic_inc(&vcc->stats->rx);
31904+ atomic_inc_unchecked(&vcc->stats->rx);
31905 }
31906 wake_up(&eni_dev->rx_wait);
31907 }
31908@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
31909 PCI_DMA_TODEVICE);
31910 if (vcc->pop) vcc->pop(vcc,skb);
31911 else dev_kfree_skb_irq(skb);
31912- atomic_inc(&vcc->stats->tx);
31913+ atomic_inc_unchecked(&vcc->stats->tx);
31914 wake_up(&eni_dev->tx_wait);
31915 dma_complete++;
31916 }
31917diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
31918index b41c948..a002b17 100644
31919--- a/drivers/atm/firestream.c
31920+++ b/drivers/atm/firestream.c
31921@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
31922 }
31923 }
31924
31925- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31926+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31927
31928 fs_dprintk (FS_DEBUG_TXMEM, "i");
31929 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
31930@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31931 #endif
31932 skb_put (skb, qe->p1 & 0xffff);
31933 ATM_SKB(skb)->vcc = atm_vcc;
31934- atomic_inc(&atm_vcc->stats->rx);
31935+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31936 __net_timestamp(skb);
31937 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
31938 atm_vcc->push (atm_vcc, skb);
31939@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31940 kfree (pe);
31941 }
31942 if (atm_vcc)
31943- atomic_inc(&atm_vcc->stats->rx_drop);
31944+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31945 break;
31946 case 0x1f: /* Reassembly abort: no buffers. */
31947 /* Silently increment error counter. */
31948 if (atm_vcc)
31949- atomic_inc(&atm_vcc->stats->rx_drop);
31950+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31951 break;
31952 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
31953 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
31954diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
31955index 204814e..cede831 100644
31956--- a/drivers/atm/fore200e.c
31957+++ b/drivers/atm/fore200e.c
31958@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
31959 #endif
31960 /* check error condition */
31961 if (*entry->status & STATUS_ERROR)
31962- atomic_inc(&vcc->stats->tx_err);
31963+ atomic_inc_unchecked(&vcc->stats->tx_err);
31964 else
31965- atomic_inc(&vcc->stats->tx);
31966+ atomic_inc_unchecked(&vcc->stats->tx);
31967 }
31968 }
31969
31970@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31971 if (skb == NULL) {
31972 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
31973
31974- atomic_inc(&vcc->stats->rx_drop);
31975+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31976 return -ENOMEM;
31977 }
31978
31979@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31980
31981 dev_kfree_skb_any(skb);
31982
31983- atomic_inc(&vcc->stats->rx_drop);
31984+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31985 return -ENOMEM;
31986 }
31987
31988 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31989
31990 vcc->push(vcc, skb);
31991- atomic_inc(&vcc->stats->rx);
31992+ atomic_inc_unchecked(&vcc->stats->rx);
31993
31994 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31995
31996@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
31997 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
31998 fore200e->atm_dev->number,
31999 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32000- atomic_inc(&vcc->stats->rx_err);
32001+ atomic_inc_unchecked(&vcc->stats->rx_err);
32002 }
32003 }
32004
32005@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32006 goto retry_here;
32007 }
32008
32009- atomic_inc(&vcc->stats->tx_err);
32010+ atomic_inc_unchecked(&vcc->stats->tx_err);
32011
32012 fore200e->tx_sat++;
32013 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32014diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32015index 72b6960..cf9167a 100644
32016--- a/drivers/atm/he.c
32017+++ b/drivers/atm/he.c
32018@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32019
32020 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32021 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32022- atomic_inc(&vcc->stats->rx_drop);
32023+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32024 goto return_host_buffers;
32025 }
32026
32027@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32028 RBRQ_LEN_ERR(he_dev->rbrq_head)
32029 ? "LEN_ERR" : "",
32030 vcc->vpi, vcc->vci);
32031- atomic_inc(&vcc->stats->rx_err);
32032+ atomic_inc_unchecked(&vcc->stats->rx_err);
32033 goto return_host_buffers;
32034 }
32035
32036@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32037 vcc->push(vcc, skb);
32038 spin_lock(&he_dev->global_lock);
32039
32040- atomic_inc(&vcc->stats->rx);
32041+ atomic_inc_unchecked(&vcc->stats->rx);
32042
32043 return_host_buffers:
32044 ++pdus_assembled;
32045@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32046 tpd->vcc->pop(tpd->vcc, tpd->skb);
32047 else
32048 dev_kfree_skb_any(tpd->skb);
32049- atomic_inc(&tpd->vcc->stats->tx_err);
32050+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32051 }
32052 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32053 return;
32054@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32055 vcc->pop(vcc, skb);
32056 else
32057 dev_kfree_skb_any(skb);
32058- atomic_inc(&vcc->stats->tx_err);
32059+ atomic_inc_unchecked(&vcc->stats->tx_err);
32060 return -EINVAL;
32061 }
32062
32063@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32064 vcc->pop(vcc, skb);
32065 else
32066 dev_kfree_skb_any(skb);
32067- atomic_inc(&vcc->stats->tx_err);
32068+ atomic_inc_unchecked(&vcc->stats->tx_err);
32069 return -EINVAL;
32070 }
32071 #endif
32072@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32073 vcc->pop(vcc, skb);
32074 else
32075 dev_kfree_skb_any(skb);
32076- atomic_inc(&vcc->stats->tx_err);
32077+ atomic_inc_unchecked(&vcc->stats->tx_err);
32078 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32079 return -ENOMEM;
32080 }
32081@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32082 vcc->pop(vcc, skb);
32083 else
32084 dev_kfree_skb_any(skb);
32085- atomic_inc(&vcc->stats->tx_err);
32086+ atomic_inc_unchecked(&vcc->stats->tx_err);
32087 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32088 return -ENOMEM;
32089 }
32090@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32091 __enqueue_tpd(he_dev, tpd, cid);
32092 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32093
32094- atomic_inc(&vcc->stats->tx);
32095+ atomic_inc_unchecked(&vcc->stats->tx);
32096
32097 return 0;
32098 }
32099diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32100index 1dc0519..1aadaf7 100644
32101--- a/drivers/atm/horizon.c
32102+++ b/drivers/atm/horizon.c
32103@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32104 {
32105 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32106 // VC layer stats
32107- atomic_inc(&vcc->stats->rx);
32108+ atomic_inc_unchecked(&vcc->stats->rx);
32109 __net_timestamp(skb);
32110 // end of our responsibility
32111 vcc->push (vcc, skb);
32112@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32113 dev->tx_iovec = NULL;
32114
32115 // VC layer stats
32116- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32117+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32118
32119 // free the skb
32120 hrz_kfree_skb (skb);
32121diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32122index 272f009..a18ba55 100644
32123--- a/drivers/atm/idt77252.c
32124+++ b/drivers/atm/idt77252.c
32125@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32126 else
32127 dev_kfree_skb(skb);
32128
32129- atomic_inc(&vcc->stats->tx);
32130+ atomic_inc_unchecked(&vcc->stats->tx);
32131 }
32132
32133 atomic_dec(&scq->used);
32134@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32135 if ((sb = dev_alloc_skb(64)) == NULL) {
32136 printk("%s: Can't allocate buffers for aal0.\n",
32137 card->name);
32138- atomic_add(i, &vcc->stats->rx_drop);
32139+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32140 break;
32141 }
32142 if (!atm_charge(vcc, sb->truesize)) {
32143 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32144 card->name);
32145- atomic_add(i - 1, &vcc->stats->rx_drop);
32146+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32147 dev_kfree_skb(sb);
32148 break;
32149 }
32150@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32151 ATM_SKB(sb)->vcc = vcc;
32152 __net_timestamp(sb);
32153 vcc->push(vcc, sb);
32154- atomic_inc(&vcc->stats->rx);
32155+ atomic_inc_unchecked(&vcc->stats->rx);
32156
32157 cell += ATM_CELL_PAYLOAD;
32158 }
32159@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32160 "(CDC: %08x)\n",
32161 card->name, len, rpp->len, readl(SAR_REG_CDC));
32162 recycle_rx_pool_skb(card, rpp);
32163- atomic_inc(&vcc->stats->rx_err);
32164+ atomic_inc_unchecked(&vcc->stats->rx_err);
32165 return;
32166 }
32167 if (stat & SAR_RSQE_CRC) {
32168 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32169 recycle_rx_pool_skb(card, rpp);
32170- atomic_inc(&vcc->stats->rx_err);
32171+ atomic_inc_unchecked(&vcc->stats->rx_err);
32172 return;
32173 }
32174 if (skb_queue_len(&rpp->queue) > 1) {
32175@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32176 RXPRINTK("%s: Can't alloc RX skb.\n",
32177 card->name);
32178 recycle_rx_pool_skb(card, rpp);
32179- atomic_inc(&vcc->stats->rx_err);
32180+ atomic_inc_unchecked(&vcc->stats->rx_err);
32181 return;
32182 }
32183 if (!atm_charge(vcc, skb->truesize)) {
32184@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32185 __net_timestamp(skb);
32186
32187 vcc->push(vcc, skb);
32188- atomic_inc(&vcc->stats->rx);
32189+ atomic_inc_unchecked(&vcc->stats->rx);
32190
32191 return;
32192 }
32193@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32194 __net_timestamp(skb);
32195
32196 vcc->push(vcc, skb);
32197- atomic_inc(&vcc->stats->rx);
32198+ atomic_inc_unchecked(&vcc->stats->rx);
32199
32200 if (skb->truesize > SAR_FB_SIZE_3)
32201 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32202@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32203 if (vcc->qos.aal != ATM_AAL0) {
32204 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32205 card->name, vpi, vci);
32206- atomic_inc(&vcc->stats->rx_drop);
32207+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32208 goto drop;
32209 }
32210
32211 if ((sb = dev_alloc_skb(64)) == NULL) {
32212 printk("%s: Can't allocate buffers for AAL0.\n",
32213 card->name);
32214- atomic_inc(&vcc->stats->rx_err);
32215+ atomic_inc_unchecked(&vcc->stats->rx_err);
32216 goto drop;
32217 }
32218
32219@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32220 ATM_SKB(sb)->vcc = vcc;
32221 __net_timestamp(sb);
32222 vcc->push(vcc, sb);
32223- atomic_inc(&vcc->stats->rx);
32224+ atomic_inc_unchecked(&vcc->stats->rx);
32225
32226 drop:
32227 skb_pull(queue, 64);
32228@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32229
32230 if (vc == NULL) {
32231 printk("%s: NULL connection in send().\n", card->name);
32232- atomic_inc(&vcc->stats->tx_err);
32233+ atomic_inc_unchecked(&vcc->stats->tx_err);
32234 dev_kfree_skb(skb);
32235 return -EINVAL;
32236 }
32237 if (!test_bit(VCF_TX, &vc->flags)) {
32238 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32239- atomic_inc(&vcc->stats->tx_err);
32240+ atomic_inc_unchecked(&vcc->stats->tx_err);
32241 dev_kfree_skb(skb);
32242 return -EINVAL;
32243 }
32244@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32245 break;
32246 default:
32247 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32248- atomic_inc(&vcc->stats->tx_err);
32249+ atomic_inc_unchecked(&vcc->stats->tx_err);
32250 dev_kfree_skb(skb);
32251 return -EINVAL;
32252 }
32253
32254 if (skb_shinfo(skb)->nr_frags != 0) {
32255 printk("%s: No scatter-gather yet.\n", card->name);
32256- atomic_inc(&vcc->stats->tx_err);
32257+ atomic_inc_unchecked(&vcc->stats->tx_err);
32258 dev_kfree_skb(skb);
32259 return -EINVAL;
32260 }
32261@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32262
32263 err = queue_skb(card, vc, skb, oam);
32264 if (err) {
32265- atomic_inc(&vcc->stats->tx_err);
32266+ atomic_inc_unchecked(&vcc->stats->tx_err);
32267 dev_kfree_skb(skb);
32268 return err;
32269 }
32270@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32271 skb = dev_alloc_skb(64);
32272 if (!skb) {
32273 printk("%s: Out of memory in send_oam().\n", card->name);
32274- atomic_inc(&vcc->stats->tx_err);
32275+ atomic_inc_unchecked(&vcc->stats->tx_err);
32276 return -ENOMEM;
32277 }
32278 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32279diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32280index 4217f29..88f547a 100644
32281--- a/drivers/atm/iphase.c
32282+++ b/drivers/atm/iphase.c
32283@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32284 status = (u_short) (buf_desc_ptr->desc_mode);
32285 if (status & (RX_CER | RX_PTE | RX_OFL))
32286 {
32287- atomic_inc(&vcc->stats->rx_err);
32288+ atomic_inc_unchecked(&vcc->stats->rx_err);
32289 IF_ERR(printk("IA: bad packet, dropping it");)
32290 if (status & RX_CER) {
32291 IF_ERR(printk(" cause: packet CRC error\n");)
32292@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32293 len = dma_addr - buf_addr;
32294 if (len > iadev->rx_buf_sz) {
32295 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32296- atomic_inc(&vcc->stats->rx_err);
32297+ atomic_inc_unchecked(&vcc->stats->rx_err);
32298 goto out_free_desc;
32299 }
32300
32301@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32302 ia_vcc = INPH_IA_VCC(vcc);
32303 if (ia_vcc == NULL)
32304 {
32305- atomic_inc(&vcc->stats->rx_err);
32306+ atomic_inc_unchecked(&vcc->stats->rx_err);
32307 atm_return(vcc, skb->truesize);
32308 dev_kfree_skb_any(skb);
32309 goto INCR_DLE;
32310@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32311 if ((length > iadev->rx_buf_sz) || (length >
32312 (skb->len - sizeof(struct cpcs_trailer))))
32313 {
32314- atomic_inc(&vcc->stats->rx_err);
32315+ atomic_inc_unchecked(&vcc->stats->rx_err);
32316 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32317 length, skb->len);)
32318 atm_return(vcc, skb->truesize);
32319@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32320
32321 IF_RX(printk("rx_dle_intr: skb push");)
32322 vcc->push(vcc,skb);
32323- atomic_inc(&vcc->stats->rx);
32324+ atomic_inc_unchecked(&vcc->stats->rx);
32325 iadev->rx_pkt_cnt++;
32326 }
32327 INCR_DLE:
32328@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32329 {
32330 struct k_sonet_stats *stats;
32331 stats = &PRIV(_ia_dev[board])->sonet_stats;
32332- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32333- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32334- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32335- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32336- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32337- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32338- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32339- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32340- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32341+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32342+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32343+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32344+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32345+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32346+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32347+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32348+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32349+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32350 }
32351 ia_cmds.status = 0;
32352 break;
32353@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32354 if ((desc == 0) || (desc > iadev->num_tx_desc))
32355 {
32356 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32357- atomic_inc(&vcc->stats->tx);
32358+ atomic_inc_unchecked(&vcc->stats->tx);
32359 if (vcc->pop)
32360 vcc->pop(vcc, skb);
32361 else
32362@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32363 ATM_DESC(skb) = vcc->vci;
32364 skb_queue_tail(&iadev->tx_dma_q, skb);
32365
32366- atomic_inc(&vcc->stats->tx);
32367+ atomic_inc_unchecked(&vcc->stats->tx);
32368 iadev->tx_pkt_cnt++;
32369 /* Increment transaction counter */
32370 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32371
32372 #if 0
32373 /* add flow control logic */
32374- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32375+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32376 if (iavcc->vc_desc_cnt > 10) {
32377 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32378 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32379diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32380index fa7d701..1e404c7 100644
32381--- a/drivers/atm/lanai.c
32382+++ b/drivers/atm/lanai.c
32383@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32384 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32385 lanai_endtx(lanai, lvcc);
32386 lanai_free_skb(lvcc->tx.atmvcc, skb);
32387- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32388+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32389 }
32390
32391 /* Try to fill the buffer - don't call unless there is backlog */
32392@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32393 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32394 __net_timestamp(skb);
32395 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32396- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32397+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32398 out:
32399 lvcc->rx.buf.ptr = end;
32400 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32401@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32402 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32403 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32404 lanai->stats.service_rxnotaal5++;
32405- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32406+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32407 return 0;
32408 }
32409 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32410@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32411 int bytes;
32412 read_unlock(&vcc_sklist_lock);
32413 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32414- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32415+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32416 lvcc->stats.x.aal5.service_trash++;
32417 bytes = (SERVICE_GET_END(s) * 16) -
32418 (((unsigned long) lvcc->rx.buf.ptr) -
32419@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32420 }
32421 if (s & SERVICE_STREAM) {
32422 read_unlock(&vcc_sklist_lock);
32423- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32424+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32425 lvcc->stats.x.aal5.service_stream++;
32426 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32427 "PDU on VCI %d!\n", lanai->number, vci);
32428@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32429 return 0;
32430 }
32431 DPRINTK("got rx crc error on vci %d\n", vci);
32432- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32433+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32434 lvcc->stats.x.aal5.service_rxcrc++;
32435 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32436 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32437diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32438index ed1d2b7..8cffc1f 100644
32439--- a/drivers/atm/nicstar.c
32440+++ b/drivers/atm/nicstar.c
32441@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32442 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32443 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32444 card->index);
32445- atomic_inc(&vcc->stats->tx_err);
32446+ atomic_inc_unchecked(&vcc->stats->tx_err);
32447 dev_kfree_skb_any(skb);
32448 return -EINVAL;
32449 }
32450@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32451 if (!vc->tx) {
32452 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32453 card->index);
32454- atomic_inc(&vcc->stats->tx_err);
32455+ atomic_inc_unchecked(&vcc->stats->tx_err);
32456 dev_kfree_skb_any(skb);
32457 return -EINVAL;
32458 }
32459@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32460 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32461 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32462 card->index);
32463- atomic_inc(&vcc->stats->tx_err);
32464+ atomic_inc_unchecked(&vcc->stats->tx_err);
32465 dev_kfree_skb_any(skb);
32466 return -EINVAL;
32467 }
32468
32469 if (skb_shinfo(skb)->nr_frags != 0) {
32470 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32471- atomic_inc(&vcc->stats->tx_err);
32472+ atomic_inc_unchecked(&vcc->stats->tx_err);
32473 dev_kfree_skb_any(skb);
32474 return -EINVAL;
32475 }
32476@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32477 }
32478
32479 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32480- atomic_inc(&vcc->stats->tx_err);
32481+ atomic_inc_unchecked(&vcc->stats->tx_err);
32482 dev_kfree_skb_any(skb);
32483 return -EIO;
32484 }
32485- atomic_inc(&vcc->stats->tx);
32486+ atomic_inc_unchecked(&vcc->stats->tx);
32487
32488 return 0;
32489 }
32490@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32491 printk
32492 ("nicstar%d: Can't allocate buffers for aal0.\n",
32493 card->index);
32494- atomic_add(i, &vcc->stats->rx_drop);
32495+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32496 break;
32497 }
32498 if (!atm_charge(vcc, sb->truesize)) {
32499 RXPRINTK
32500 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32501 card->index);
32502- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32503+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32504 dev_kfree_skb_any(sb);
32505 break;
32506 }
32507@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32508 ATM_SKB(sb)->vcc = vcc;
32509 __net_timestamp(sb);
32510 vcc->push(vcc, sb);
32511- atomic_inc(&vcc->stats->rx);
32512+ atomic_inc_unchecked(&vcc->stats->rx);
32513 cell += ATM_CELL_PAYLOAD;
32514 }
32515
32516@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32517 if (iovb == NULL) {
32518 printk("nicstar%d: Out of iovec buffers.\n",
32519 card->index);
32520- atomic_inc(&vcc->stats->rx_drop);
32521+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32522 recycle_rx_buf(card, skb);
32523 return;
32524 }
32525@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32526 small or large buffer itself. */
32527 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32528 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32529- atomic_inc(&vcc->stats->rx_err);
32530+ atomic_inc_unchecked(&vcc->stats->rx_err);
32531 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32532 NS_MAX_IOVECS);
32533 NS_PRV_IOVCNT(iovb) = 0;
32534@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32535 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32536 card->index);
32537 which_list(card, skb);
32538- atomic_inc(&vcc->stats->rx_err);
32539+ atomic_inc_unchecked(&vcc->stats->rx_err);
32540 recycle_rx_buf(card, skb);
32541 vc->rx_iov = NULL;
32542 recycle_iov_buf(card, iovb);
32543@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32544 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32545 card->index);
32546 which_list(card, skb);
32547- atomic_inc(&vcc->stats->rx_err);
32548+ atomic_inc_unchecked(&vcc->stats->rx_err);
32549 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32550 NS_PRV_IOVCNT(iovb));
32551 vc->rx_iov = NULL;
32552@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32553 printk(" - PDU size mismatch.\n");
32554 else
32555 printk(".\n");
32556- atomic_inc(&vcc->stats->rx_err);
32557+ atomic_inc_unchecked(&vcc->stats->rx_err);
32558 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32559 NS_PRV_IOVCNT(iovb));
32560 vc->rx_iov = NULL;
32561@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32562 /* skb points to a small buffer */
32563 if (!atm_charge(vcc, skb->truesize)) {
32564 push_rxbufs(card, skb);
32565- atomic_inc(&vcc->stats->rx_drop);
32566+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32567 } else {
32568 skb_put(skb, len);
32569 dequeue_sm_buf(card, skb);
32570@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32571 ATM_SKB(skb)->vcc = vcc;
32572 __net_timestamp(skb);
32573 vcc->push(vcc, skb);
32574- atomic_inc(&vcc->stats->rx);
32575+ atomic_inc_unchecked(&vcc->stats->rx);
32576 }
32577 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32578 struct sk_buff *sb;
32579@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32580 if (len <= NS_SMBUFSIZE) {
32581 if (!atm_charge(vcc, sb->truesize)) {
32582 push_rxbufs(card, sb);
32583- atomic_inc(&vcc->stats->rx_drop);
32584+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32585 } else {
32586 skb_put(sb, len);
32587 dequeue_sm_buf(card, sb);
32588@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32589 ATM_SKB(sb)->vcc = vcc;
32590 __net_timestamp(sb);
32591 vcc->push(vcc, sb);
32592- atomic_inc(&vcc->stats->rx);
32593+ atomic_inc_unchecked(&vcc->stats->rx);
32594 }
32595
32596 push_rxbufs(card, skb);
32597@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32598
32599 if (!atm_charge(vcc, skb->truesize)) {
32600 push_rxbufs(card, skb);
32601- atomic_inc(&vcc->stats->rx_drop);
32602+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32603 } else {
32604 dequeue_lg_buf(card, skb);
32605 #ifdef NS_USE_DESTRUCTORS
32606@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32607 ATM_SKB(skb)->vcc = vcc;
32608 __net_timestamp(skb);
32609 vcc->push(vcc, skb);
32610- atomic_inc(&vcc->stats->rx);
32611+ atomic_inc_unchecked(&vcc->stats->rx);
32612 }
32613
32614 push_rxbufs(card, sb);
32615@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32616 printk
32617 ("nicstar%d: Out of huge buffers.\n",
32618 card->index);
32619- atomic_inc(&vcc->stats->rx_drop);
32620+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32621 recycle_iovec_rx_bufs(card,
32622 (struct iovec *)
32623 iovb->data,
32624@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32625 card->hbpool.count++;
32626 } else
32627 dev_kfree_skb_any(hb);
32628- atomic_inc(&vcc->stats->rx_drop);
32629+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32630 } else {
32631 /* Copy the small buffer to the huge buffer */
32632 sb = (struct sk_buff *)iov->iov_base;
32633@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32634 #endif /* NS_USE_DESTRUCTORS */
32635 __net_timestamp(hb);
32636 vcc->push(vcc, hb);
32637- atomic_inc(&vcc->stats->rx);
32638+ atomic_inc_unchecked(&vcc->stats->rx);
32639 }
32640 }
32641
32642diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32643index 0474a89..06ea4a1 100644
32644--- a/drivers/atm/solos-pci.c
32645+++ b/drivers/atm/solos-pci.c
32646@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32647 }
32648 atm_charge(vcc, skb->truesize);
32649 vcc->push(vcc, skb);
32650- atomic_inc(&vcc->stats->rx);
32651+ atomic_inc_unchecked(&vcc->stats->rx);
32652 break;
32653
32654 case PKT_STATUS:
32655@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32656 vcc = SKB_CB(oldskb)->vcc;
32657
32658 if (vcc) {
32659- atomic_inc(&vcc->stats->tx);
32660+ atomic_inc_unchecked(&vcc->stats->tx);
32661 solos_pop(vcc, oldskb);
32662 } else {
32663 dev_kfree_skb_irq(oldskb);
32664diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32665index 0215934..ce9f5b1 100644
32666--- a/drivers/atm/suni.c
32667+++ b/drivers/atm/suni.c
32668@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32669
32670
32671 #define ADD_LIMITED(s,v) \
32672- atomic_add((v),&stats->s); \
32673- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32674+ atomic_add_unchecked((v),&stats->s); \
32675+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32676
32677
32678 static void suni_hz(unsigned long from_timer)
32679diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32680index 5120a96..e2572bd 100644
32681--- a/drivers/atm/uPD98402.c
32682+++ b/drivers/atm/uPD98402.c
32683@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32684 struct sonet_stats tmp;
32685 int error = 0;
32686
32687- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32688+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32689 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32690 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32691 if (zero && !error) {
32692@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32693
32694
32695 #define ADD_LIMITED(s,v) \
32696- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32697- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32698- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32699+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32700+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32701+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32702
32703
32704 static void stat_event(struct atm_dev *dev)
32705@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32706 if (reason & uPD98402_INT_PFM) stat_event(dev);
32707 if (reason & uPD98402_INT_PCO) {
32708 (void) GET(PCOCR); /* clear interrupt cause */
32709- atomic_add(GET(HECCT),
32710+ atomic_add_unchecked(GET(HECCT),
32711 &PRIV(dev)->sonet_stats.uncorr_hcs);
32712 }
32713 if ((reason & uPD98402_INT_RFO) &&
32714@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32715 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
32716 uPD98402_INT_LOS),PIMR); /* enable them */
32717 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
32718- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32719- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
32720- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
32721+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32722+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
32723+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32724 return 0;
32725 }
32726
32727diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32728index 969c3c2..9b72956 100644
32729--- a/drivers/atm/zatm.c
32730+++ b/drivers/atm/zatm.c
32731@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32732 }
32733 if (!size) {
32734 dev_kfree_skb_irq(skb);
32735- if (vcc) atomic_inc(&vcc->stats->rx_err);
32736+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32737 continue;
32738 }
32739 if (!atm_charge(vcc,skb->truesize)) {
32740@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32741 skb->len = size;
32742 ATM_SKB(skb)->vcc = vcc;
32743 vcc->push(vcc,skb);
32744- atomic_inc(&vcc->stats->rx);
32745+ atomic_inc_unchecked(&vcc->stats->rx);
32746 }
32747 zout(pos & 0xffff,MTA(mbx));
32748 #if 0 /* probably a stupid idea */
32749@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32750 skb_queue_head(&zatm_vcc->backlog,skb);
32751 break;
32752 }
32753- atomic_inc(&vcc->stats->tx);
32754+ atomic_inc_unchecked(&vcc->stats->tx);
32755 wake_up(&zatm_vcc->tx_wait);
32756 }
32757
32758diff --git a/drivers/base/bus.c b/drivers/base/bus.c
32759index 6856303..0602d70 100644
32760--- a/drivers/base/bus.c
32761+++ b/drivers/base/bus.c
32762@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
32763 return -EINVAL;
32764
32765 mutex_lock(&subsys->p->mutex);
32766- list_add_tail(&sif->node, &subsys->p->interfaces);
32767+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
32768 if (sif->add_dev) {
32769 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32770 while ((dev = subsys_dev_iter_next(&iter)))
32771@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
32772 subsys = sif->subsys;
32773
32774 mutex_lock(&subsys->p->mutex);
32775- list_del_init(&sif->node);
32776+ pax_list_del_init((struct list_head *)&sif->node);
32777 if (sif->remove_dev) {
32778 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32779 while ((dev = subsys_dev_iter_next(&iter)))
32780diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32781index 17cf7ca..7e553e1 100644
32782--- a/drivers/base/devtmpfs.c
32783+++ b/drivers/base/devtmpfs.c
32784@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32785 if (!thread)
32786 return 0;
32787
32788- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32789+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32790 if (err)
32791 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32792 else
32793diff --git a/drivers/base/node.c b/drivers/base/node.c
32794index fac124a..66bd4ab 100644
32795--- a/drivers/base/node.c
32796+++ b/drivers/base/node.c
32797@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
32798 struct node_attr {
32799 struct device_attribute attr;
32800 enum node_states state;
32801-};
32802+} __do_const;
32803
32804 static ssize_t show_node_state(struct device *dev,
32805 struct device_attribute *attr, char *buf)
32806diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
32807index acc3a8d..981c236 100644
32808--- a/drivers/base/power/domain.c
32809+++ b/drivers/base/power/domain.c
32810@@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
32811 {
32812 struct cpuidle_driver *cpuidle_drv;
32813 struct gpd_cpu_data *cpu_data;
32814- struct cpuidle_state *idle_state;
32815+ cpuidle_state_no_const *idle_state;
32816 int ret = 0;
32817
32818 if (IS_ERR_OR_NULL(genpd) || state < 0)
32819@@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
32820 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
32821 {
32822 struct gpd_cpu_data *cpu_data;
32823- struct cpuidle_state *idle_state;
32824+ cpuidle_state_no_const *idle_state;
32825 int ret = 0;
32826
32827 if (IS_ERR_OR_NULL(genpd))
32828diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32829index e6ee5e8..98ad7fc 100644
32830--- a/drivers/base/power/wakeup.c
32831+++ b/drivers/base/power/wakeup.c
32832@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32833 * They need to be modified together atomically, so it's better to use one
32834 * atomic variable to hold them both.
32835 */
32836-static atomic_t combined_event_count = ATOMIC_INIT(0);
32837+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32838
32839 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32840 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32841
32842 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32843 {
32844- unsigned int comb = atomic_read(&combined_event_count);
32845+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
32846
32847 *cnt = (comb >> IN_PROGRESS_BITS);
32848 *inpr = comb & MAX_IN_PROGRESS;
32849@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32850 ws->start_prevent_time = ws->last_time;
32851
32852 /* Increment the counter of events in progress. */
32853- cec = atomic_inc_return(&combined_event_count);
32854+ cec = atomic_inc_return_unchecked(&combined_event_count);
32855
32856 trace_wakeup_source_activate(ws->name, cec);
32857 }
32858@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32859 * Increment the counter of registered wakeup events and decrement the
32860 * couter of wakeup events in progress simultaneously.
32861 */
32862- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32863+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32864 trace_wakeup_source_deactivate(ws->name, cec);
32865
32866 split_counters(&cnt, &inpr);
32867diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
32868index e8d11b6..7b1b36f 100644
32869--- a/drivers/base/syscore.c
32870+++ b/drivers/base/syscore.c
32871@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
32872 void register_syscore_ops(struct syscore_ops *ops)
32873 {
32874 mutex_lock(&syscore_ops_lock);
32875- list_add_tail(&ops->node, &syscore_ops_list);
32876+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
32877 mutex_unlock(&syscore_ops_lock);
32878 }
32879 EXPORT_SYMBOL_GPL(register_syscore_ops);
32880@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
32881 void unregister_syscore_ops(struct syscore_ops *ops)
32882 {
32883 mutex_lock(&syscore_ops_lock);
32884- list_del(&ops->node);
32885+ pax_list_del((struct list_head *)&ops->node);
32886 mutex_unlock(&syscore_ops_lock);
32887 }
32888 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
32889diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
32890index ade58bc..867143d 100644
32891--- a/drivers/block/cciss.c
32892+++ b/drivers/block/cciss.c
32893@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
32894 int err;
32895 u32 cp;
32896
32897+ memset(&arg64, 0, sizeof(arg64));
32898+
32899 err = 0;
32900 err |=
32901 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
32902@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
32903 while (!list_empty(&h->reqQ)) {
32904 c = list_entry(h->reqQ.next, CommandList_struct, list);
32905 /* can't do anything if fifo is full */
32906- if ((h->access.fifo_full(h))) {
32907+ if ((h->access->fifo_full(h))) {
32908 dev_warn(&h->pdev->dev, "fifo full\n");
32909 break;
32910 }
32911@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
32912 h->Qdepth--;
32913
32914 /* Tell the controller execute command */
32915- h->access.submit_command(h, c);
32916+ h->access->submit_command(h, c);
32917
32918 /* Put job onto the completed Q */
32919 addQ(&h->cmpQ, c);
32920@@ -3441,17 +3443,17 @@ startio:
32921
32922 static inline unsigned long get_next_completion(ctlr_info_t *h)
32923 {
32924- return h->access.command_completed(h);
32925+ return h->access->command_completed(h);
32926 }
32927
32928 static inline int interrupt_pending(ctlr_info_t *h)
32929 {
32930- return h->access.intr_pending(h);
32931+ return h->access->intr_pending(h);
32932 }
32933
32934 static inline long interrupt_not_for_us(ctlr_info_t *h)
32935 {
32936- return ((h->access.intr_pending(h) == 0) ||
32937+ return ((h->access->intr_pending(h) == 0) ||
32938 (h->interrupts_enabled == 0));
32939 }
32940
32941@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
32942 u32 a;
32943
32944 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
32945- return h->access.command_completed(h);
32946+ return h->access->command_completed(h);
32947
32948 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
32949 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
32950@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
32951 trans_support & CFGTBL_Trans_use_short_tags);
32952
32953 /* Change the access methods to the performant access methods */
32954- h->access = SA5_performant_access;
32955+ h->access = &SA5_performant_access;
32956 h->transMethod = CFGTBL_Trans_Performant;
32957
32958 return;
32959@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
32960 if (prod_index < 0)
32961 return -ENODEV;
32962 h->product_name = products[prod_index].product_name;
32963- h->access = *(products[prod_index].access);
32964+ h->access = products[prod_index].access;
32965
32966 if (cciss_board_disabled(h)) {
32967 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
32968@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
32969 }
32970
32971 /* make sure the board interrupts are off */
32972- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32973+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32974 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
32975 if (rc)
32976 goto clean2;
32977@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
32978 * fake ones to scoop up any residual completions.
32979 */
32980 spin_lock_irqsave(&h->lock, flags);
32981- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32982+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32983 spin_unlock_irqrestore(&h->lock, flags);
32984 free_irq(h->intr[h->intr_mode], h);
32985 rc = cciss_request_irq(h, cciss_msix_discard_completions,
32986@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
32987 dev_info(&h->pdev->dev, "Board READY.\n");
32988 dev_info(&h->pdev->dev,
32989 "Waiting for stale completions to drain.\n");
32990- h->access.set_intr_mask(h, CCISS_INTR_ON);
32991+ h->access->set_intr_mask(h, CCISS_INTR_ON);
32992 msleep(10000);
32993- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32994+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32995
32996 rc = controller_reset_failed(h->cfgtable);
32997 if (rc)
32998@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
32999 cciss_scsi_setup(h);
33000
33001 /* Turn the interrupts on so we can service requests */
33002- h->access.set_intr_mask(h, CCISS_INTR_ON);
33003+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33004
33005 /* Get the firmware version */
33006 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33007@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33008 kfree(flush_buf);
33009 if (return_code != IO_OK)
33010 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33011- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33012+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33013 free_irq(h->intr[h->intr_mode], h);
33014 }
33015
33016diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33017index 7fda30e..eb5dfe0 100644
33018--- a/drivers/block/cciss.h
33019+++ b/drivers/block/cciss.h
33020@@ -101,7 +101,7 @@ struct ctlr_info
33021 /* information about each logical volume */
33022 drive_info_struct *drv[CISS_MAX_LUN];
33023
33024- struct access_method access;
33025+ struct access_method *access;
33026
33027 /* queue and queue Info */
33028 struct list_head reqQ;
33029diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33030index 3f08713..56a586a 100644
33031--- a/drivers/block/cpqarray.c
33032+++ b/drivers/block/cpqarray.c
33033@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33034 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33035 goto Enomem4;
33036 }
33037- hba[i]->access.set_intr_mask(hba[i], 0);
33038+ hba[i]->access->set_intr_mask(hba[i], 0);
33039 if (request_irq(hba[i]->intr, do_ida_intr,
33040 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33041 {
33042@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33043 add_timer(&hba[i]->timer);
33044
33045 /* Enable IRQ now that spinlock and rate limit timer are set up */
33046- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33047+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33048
33049 for(j=0; j<NWD; j++) {
33050 struct gendisk *disk = ida_gendisk[i][j];
33051@@ -694,7 +694,7 @@ DBGINFO(
33052 for(i=0; i<NR_PRODUCTS; i++) {
33053 if (board_id == products[i].board_id) {
33054 c->product_name = products[i].product_name;
33055- c->access = *(products[i].access);
33056+ c->access = products[i].access;
33057 break;
33058 }
33059 }
33060@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33061 hba[ctlr]->intr = intr;
33062 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33063 hba[ctlr]->product_name = products[j].product_name;
33064- hba[ctlr]->access = *(products[j].access);
33065+ hba[ctlr]->access = products[j].access;
33066 hba[ctlr]->ctlr = ctlr;
33067 hba[ctlr]->board_id = board_id;
33068 hba[ctlr]->pci_dev = NULL; /* not PCI */
33069@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33070
33071 while((c = h->reqQ) != NULL) {
33072 /* Can't do anything if we're busy */
33073- if (h->access.fifo_full(h) == 0)
33074+ if (h->access->fifo_full(h) == 0)
33075 return;
33076
33077 /* Get the first entry from the request Q */
33078@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33079 h->Qdepth--;
33080
33081 /* Tell the controller to do our bidding */
33082- h->access.submit_command(h, c);
33083+ h->access->submit_command(h, c);
33084
33085 /* Get onto the completion Q */
33086 addQ(&h->cmpQ, c);
33087@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33088 unsigned long flags;
33089 __u32 a,a1;
33090
33091- istat = h->access.intr_pending(h);
33092+ istat = h->access->intr_pending(h);
33093 /* Is this interrupt for us? */
33094 if (istat == 0)
33095 return IRQ_NONE;
33096@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33097 */
33098 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33099 if (istat & FIFO_NOT_EMPTY) {
33100- while((a = h->access.command_completed(h))) {
33101+ while((a = h->access->command_completed(h))) {
33102 a1 = a; a &= ~3;
33103 if ((c = h->cmpQ) == NULL)
33104 {
33105@@ -1449,11 +1449,11 @@ static int sendcmd(
33106 /*
33107 * Disable interrupt
33108 */
33109- info_p->access.set_intr_mask(info_p, 0);
33110+ info_p->access->set_intr_mask(info_p, 0);
33111 /* Make sure there is room in the command FIFO */
33112 /* Actually it should be completely empty at this time. */
33113 for (i = 200000; i > 0; i--) {
33114- temp = info_p->access.fifo_full(info_p);
33115+ temp = info_p->access->fifo_full(info_p);
33116 if (temp != 0) {
33117 break;
33118 }
33119@@ -1466,7 +1466,7 @@ DBG(
33120 /*
33121 * Send the cmd
33122 */
33123- info_p->access.submit_command(info_p, c);
33124+ info_p->access->submit_command(info_p, c);
33125 complete = pollcomplete(ctlr);
33126
33127 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33128@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33129 * we check the new geometry. Then turn interrupts back on when
33130 * we're done.
33131 */
33132- host->access.set_intr_mask(host, 0);
33133+ host->access->set_intr_mask(host, 0);
33134 getgeometry(ctlr);
33135- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33136+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33137
33138 for(i=0; i<NWD; i++) {
33139 struct gendisk *disk = ida_gendisk[ctlr][i];
33140@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
33141 /* Wait (up to 2 seconds) for a command to complete */
33142
33143 for (i = 200000; i > 0; i--) {
33144- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33145+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33146 if (done == 0) {
33147 udelay(10); /* a short fixed delay */
33148 } else
33149diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33150index be73e9d..7fbf140 100644
33151--- a/drivers/block/cpqarray.h
33152+++ b/drivers/block/cpqarray.h
33153@@ -99,7 +99,7 @@ struct ctlr_info {
33154 drv_info_t drv[NWD];
33155 struct proc_dir_entry *proc;
33156
33157- struct access_method access;
33158+ struct access_method *access;
33159
33160 cmdlist_t *reqQ;
33161 cmdlist_t *cmpQ;
33162diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33163index 6b51afa..17e1191 100644
33164--- a/drivers/block/drbd/drbd_int.h
33165+++ b/drivers/block/drbd/drbd_int.h
33166@@ -582,7 +582,7 @@ struct drbd_epoch {
33167 struct drbd_tconn *tconn;
33168 struct list_head list;
33169 unsigned int barrier_nr;
33170- atomic_t epoch_size; /* increased on every request added. */
33171+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33172 atomic_t active; /* increased on every req. added, and dec on every finished. */
33173 unsigned long flags;
33174 };
33175@@ -1011,7 +1011,7 @@ struct drbd_conf {
33176 int al_tr_cycle;
33177 int al_tr_pos; /* position of the next transaction in the journal */
33178 wait_queue_head_t seq_wait;
33179- atomic_t packet_seq;
33180+ atomic_unchecked_t packet_seq;
33181 unsigned int peer_seq;
33182 spinlock_t peer_seq_lock;
33183 unsigned int minor;
33184@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33185 char __user *uoptval;
33186 int err;
33187
33188- uoptval = (char __user __force *)optval;
33189+ uoptval = (char __force_user *)optval;
33190
33191 set_fs(KERNEL_DS);
33192 if (level == SOL_SOCKET)
33193diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33194index 8c13eeb..217adee 100644
33195--- a/drivers/block/drbd/drbd_main.c
33196+++ b/drivers/block/drbd/drbd_main.c
33197@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33198 p->sector = sector;
33199 p->block_id = block_id;
33200 p->blksize = blksize;
33201- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33202+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33203 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33204 }
33205
33206@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33207 return -EIO;
33208 p->sector = cpu_to_be64(req->i.sector);
33209 p->block_id = (unsigned long)req;
33210- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33211+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33212 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33213 if (mdev->state.conn >= C_SYNC_SOURCE &&
33214 mdev->state.conn <= C_PAUSED_SYNC_T)
33215@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33216 {
33217 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33218
33219- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33220- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33221+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33222+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33223 kfree(tconn->current_epoch);
33224
33225 idr_destroy(&tconn->volumes);
33226diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33227index a9eccfc..f5efe87 100644
33228--- a/drivers/block/drbd/drbd_receiver.c
33229+++ b/drivers/block/drbd/drbd_receiver.c
33230@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33231 {
33232 int err;
33233
33234- atomic_set(&mdev->packet_seq, 0);
33235+ atomic_set_unchecked(&mdev->packet_seq, 0);
33236 mdev->peer_seq = 0;
33237
33238 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33239@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33240 do {
33241 next_epoch = NULL;
33242
33243- epoch_size = atomic_read(&epoch->epoch_size);
33244+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33245
33246 switch (ev & ~EV_CLEANUP) {
33247 case EV_PUT:
33248@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33249 rv = FE_DESTROYED;
33250 } else {
33251 epoch->flags = 0;
33252- atomic_set(&epoch->epoch_size, 0);
33253+ atomic_set_unchecked(&epoch->epoch_size, 0);
33254 /* atomic_set(&epoch->active, 0); is already zero */
33255 if (rv == FE_STILL_LIVE)
33256 rv = FE_RECYCLED;
33257@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33258 conn_wait_active_ee_empty(tconn);
33259 drbd_flush(tconn);
33260
33261- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33262+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33263 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33264 if (epoch)
33265 break;
33266@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33267 }
33268
33269 epoch->flags = 0;
33270- atomic_set(&epoch->epoch_size, 0);
33271+ atomic_set_unchecked(&epoch->epoch_size, 0);
33272 atomic_set(&epoch->active, 0);
33273
33274 spin_lock(&tconn->epoch_lock);
33275- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33276+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33277 list_add(&epoch->list, &tconn->current_epoch->list);
33278 tconn->current_epoch = epoch;
33279 tconn->epochs++;
33280@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33281
33282 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33283 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33284- atomic_inc(&tconn->current_epoch->epoch_size);
33285+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33286 err2 = drbd_drain_block(mdev, pi->size);
33287 if (!err)
33288 err = err2;
33289@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33290
33291 spin_lock(&tconn->epoch_lock);
33292 peer_req->epoch = tconn->current_epoch;
33293- atomic_inc(&peer_req->epoch->epoch_size);
33294+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33295 atomic_inc(&peer_req->epoch->active);
33296 spin_unlock(&tconn->epoch_lock);
33297
33298@@ -4346,7 +4346,7 @@ struct data_cmd {
33299 int expect_payload;
33300 size_t pkt_size;
33301 int (*fn)(struct drbd_tconn *, struct packet_info *);
33302-};
33303+} __do_const;
33304
33305 static struct data_cmd drbd_cmd_handler[] = {
33306 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33307@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33308 if (!list_empty(&tconn->current_epoch->list))
33309 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33310 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33311- atomic_set(&tconn->current_epoch->epoch_size, 0);
33312+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33313 tconn->send.seen_any_write_yet = false;
33314
33315 conn_info(tconn, "Connection closed\n");
33316@@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33317 struct asender_cmd {
33318 size_t pkt_size;
33319 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33320-};
33321+} __do_const;
33322
33323 static struct asender_cmd asender_tbl[] = {
33324 [P_PING] = { 0, got_Ping },
33325diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33326index ae12512..37fa397 100644
33327--- a/drivers/block/loop.c
33328+++ b/drivers/block/loop.c
33329@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33330 mm_segment_t old_fs = get_fs();
33331
33332 set_fs(get_ds());
33333- bw = file->f_op->write(file, buf, len, &pos);
33334+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33335 set_fs(old_fs);
33336 if (likely(bw == len))
33337 return 0;
33338diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33339index d620b44..587561e 100644
33340--- a/drivers/cdrom/cdrom.c
33341+++ b/drivers/cdrom/cdrom.c
33342@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33343 ENSURE(reset, CDC_RESET);
33344 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33345 cdi->mc_flags = 0;
33346- cdo->n_minors = 0;
33347 cdi->options = CDO_USE_FFLAGS;
33348
33349 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33350@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33351 else
33352 cdi->cdda_method = CDDA_OLD;
33353
33354- if (!cdo->generic_packet)
33355- cdo->generic_packet = cdrom_dummy_generic_packet;
33356+ if (!cdo->generic_packet) {
33357+ pax_open_kernel();
33358+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33359+ pax_close_kernel();
33360+ }
33361
33362 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33363 mutex_lock(&cdrom_mutex);
33364@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33365 if (cdi->exit)
33366 cdi->exit(cdi);
33367
33368- cdi->ops->n_minors--;
33369 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33370 }
33371
33372diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33373index d59cdcb..11afddf 100644
33374--- a/drivers/cdrom/gdrom.c
33375+++ b/drivers/cdrom/gdrom.c
33376@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33377 .audio_ioctl = gdrom_audio_ioctl,
33378 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33379 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33380- .n_minors = 1,
33381 };
33382
33383 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33384diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33385index 72bedad..8181ce1 100644
33386--- a/drivers/char/Kconfig
33387+++ b/drivers/char/Kconfig
33388@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33389
33390 config DEVKMEM
33391 bool "/dev/kmem virtual device support"
33392- default y
33393+ default n
33394+ depends on !GRKERNSEC_KMEM
33395 help
33396 Say Y here if you want to support the /dev/kmem device. The
33397 /dev/kmem device is rarely used, but can be used for certain
33398@@ -581,6 +582,7 @@ config DEVPORT
33399 bool
33400 depends on !M68K
33401 depends on ISA || PCI
33402+ depends on !GRKERNSEC_KMEM
33403 default y
33404
33405 source "drivers/s390/char/Kconfig"
33406diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33407index 2e04433..22afc64 100644
33408--- a/drivers/char/agp/frontend.c
33409+++ b/drivers/char/agp/frontend.c
33410@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33411 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33412 return -EFAULT;
33413
33414- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33415+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33416 return -EFAULT;
33417
33418 client = agp_find_client_by_pid(reserve.pid);
33419diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33420index 21cb980..f15107c 100644
33421--- a/drivers/char/genrtc.c
33422+++ b/drivers/char/genrtc.c
33423@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33424 switch (cmd) {
33425
33426 case RTC_PLL_GET:
33427+ memset(&pll, 0, sizeof(pll));
33428 if (get_rtc_pll(&pll))
33429 return -EINVAL;
33430 else
33431diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33432index fe6d4be..89f32100 100644
33433--- a/drivers/char/hpet.c
33434+++ b/drivers/char/hpet.c
33435@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33436 }
33437
33438 static int
33439-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33440+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33441 struct hpet_info *info)
33442 {
33443 struct hpet_timer __iomem *timer;
33444diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33445index 053201b0..8335cce 100644
33446--- a/drivers/char/ipmi/ipmi_msghandler.c
33447+++ b/drivers/char/ipmi/ipmi_msghandler.c
33448@@ -420,7 +420,7 @@ struct ipmi_smi {
33449 struct proc_dir_entry *proc_dir;
33450 char proc_dir_name[10];
33451
33452- atomic_t stats[IPMI_NUM_STATS];
33453+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33454
33455 /*
33456 * run_to_completion duplicate of smb_info, smi_info
33457@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33458
33459
33460 #define ipmi_inc_stat(intf, stat) \
33461- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33462+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33463 #define ipmi_get_stat(intf, stat) \
33464- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33465+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33466
33467 static int is_lan_addr(struct ipmi_addr *addr)
33468 {
33469@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33470 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33471 init_waitqueue_head(&intf->waitq);
33472 for (i = 0; i < IPMI_NUM_STATS; i++)
33473- atomic_set(&intf->stats[i], 0);
33474+ atomic_set_unchecked(&intf->stats[i], 0);
33475
33476 intf->proc_dir = NULL;
33477
33478diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33479index 1c7fdcd..4899100 100644
33480--- a/drivers/char/ipmi/ipmi_si_intf.c
33481+++ b/drivers/char/ipmi/ipmi_si_intf.c
33482@@ -275,7 +275,7 @@ struct smi_info {
33483 unsigned char slave_addr;
33484
33485 /* Counters and things for the proc filesystem. */
33486- atomic_t stats[SI_NUM_STATS];
33487+ atomic_unchecked_t stats[SI_NUM_STATS];
33488
33489 struct task_struct *thread;
33490
33491@@ -284,9 +284,9 @@ struct smi_info {
33492 };
33493
33494 #define smi_inc_stat(smi, stat) \
33495- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33496+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33497 #define smi_get_stat(smi, stat) \
33498- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33499+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33500
33501 #define SI_MAX_PARMS 4
33502
33503@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
33504 atomic_set(&new_smi->req_events, 0);
33505 new_smi->run_to_completion = 0;
33506 for (i = 0; i < SI_NUM_STATS; i++)
33507- atomic_set(&new_smi->stats[i], 0);
33508+ atomic_set_unchecked(&new_smi->stats[i], 0);
33509
33510 new_smi->interrupt_disabled = 1;
33511 atomic_set(&new_smi->stop_operation, 0);
33512diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33513index c6fa3bc..4ca3e42 100644
33514--- a/drivers/char/mem.c
33515+++ b/drivers/char/mem.c
33516@@ -18,6 +18,7 @@
33517 #include <linux/raw.h>
33518 #include <linux/tty.h>
33519 #include <linux/capability.h>
33520+#include <linux/security.h>
33521 #include <linux/ptrace.h>
33522 #include <linux/device.h>
33523 #include <linux/highmem.h>
33524@@ -37,6 +38,10 @@
33525
33526 #define DEVPORT_MINOR 4
33527
33528+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33529+extern const struct file_operations grsec_fops;
33530+#endif
33531+
33532 static inline unsigned long size_inside_page(unsigned long start,
33533 unsigned long size)
33534 {
33535@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33536
33537 while (cursor < to) {
33538 if (!devmem_is_allowed(pfn)) {
33539+#ifdef CONFIG_GRKERNSEC_KMEM
33540+ gr_handle_mem_readwrite(from, to);
33541+#else
33542 printk(KERN_INFO
33543 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33544 current->comm, from, to);
33545+#endif
33546 return 0;
33547 }
33548 cursor += PAGE_SIZE;
33549@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33550 }
33551 return 1;
33552 }
33553+#elif defined(CONFIG_GRKERNSEC_KMEM)
33554+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33555+{
33556+ return 0;
33557+}
33558 #else
33559 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33560 {
33561@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33562
33563 while (count > 0) {
33564 unsigned long remaining;
33565+ char *temp;
33566
33567 sz = size_inside_page(p, count);
33568
33569@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33570 if (!ptr)
33571 return -EFAULT;
33572
33573- remaining = copy_to_user(buf, ptr, sz);
33574+#ifdef CONFIG_PAX_USERCOPY
33575+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33576+ if (!temp) {
33577+ unxlate_dev_mem_ptr(p, ptr);
33578+ return -ENOMEM;
33579+ }
33580+ memcpy(temp, ptr, sz);
33581+#else
33582+ temp = ptr;
33583+#endif
33584+
33585+ remaining = copy_to_user(buf, temp, sz);
33586+
33587+#ifdef CONFIG_PAX_USERCOPY
33588+ kfree(temp);
33589+#endif
33590+
33591 unxlate_dev_mem_ptr(p, ptr);
33592 if (remaining)
33593 return -EFAULT;
33594@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33595 size_t count, loff_t *ppos)
33596 {
33597 unsigned long p = *ppos;
33598- ssize_t low_count, read, sz;
33599+ ssize_t low_count, read, sz, err = 0;
33600 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
33601- int err = 0;
33602
33603 read = 0;
33604 if (p < (unsigned long) high_memory) {
33605@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33606 }
33607 #endif
33608 while (low_count > 0) {
33609+ char *temp;
33610+
33611 sz = size_inside_page(p, low_count);
33612
33613 /*
33614@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33615 */
33616 kbuf = xlate_dev_kmem_ptr((char *)p);
33617
33618- if (copy_to_user(buf, kbuf, sz))
33619+#ifdef CONFIG_PAX_USERCOPY
33620+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33621+ if (!temp)
33622+ return -ENOMEM;
33623+ memcpy(temp, kbuf, sz);
33624+#else
33625+ temp = kbuf;
33626+#endif
33627+
33628+ err = copy_to_user(buf, temp, sz);
33629+
33630+#ifdef CONFIG_PAX_USERCOPY
33631+ kfree(temp);
33632+#endif
33633+
33634+ if (err)
33635 return -EFAULT;
33636 buf += sz;
33637 p += sz;
33638@@ -833,6 +880,9 @@ static const struct memdev {
33639 #ifdef CONFIG_CRASH_DUMP
33640 [12] = { "oldmem", 0, &oldmem_fops, NULL },
33641 #endif
33642+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33643+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
33644+#endif
33645 };
33646
33647 static int memory_open(struct inode *inode, struct file *filp)
33648diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
33649index 9df78e2..01ba9ae 100644
33650--- a/drivers/char/nvram.c
33651+++ b/drivers/char/nvram.c
33652@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
33653
33654 spin_unlock_irq(&rtc_lock);
33655
33656- if (copy_to_user(buf, contents, tmp - contents))
33657+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
33658 return -EFAULT;
33659
33660 *ppos = i;
33661diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
33662index b66eaa0..2619d1b 100644
33663--- a/drivers/char/pcmcia/synclink_cs.c
33664+++ b/drivers/char/pcmcia/synclink_cs.c
33665@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33666
33667 if (debug_level >= DEBUG_LEVEL_INFO)
33668 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
33669- __FILE__,__LINE__, info->device_name, port->count);
33670+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
33671
33672- WARN_ON(!port->count);
33673+ WARN_ON(!atomic_read(&port->count));
33674
33675 if (tty_port_close_start(port, tty, filp) == 0)
33676 goto cleanup;
33677@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33678 cleanup:
33679 if (debug_level >= DEBUG_LEVEL_INFO)
33680 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
33681- tty->driver->name, port->count);
33682+ tty->driver->name, atomic_read(&port->count));
33683 }
33684
33685 /* Wait until the transmitter is empty.
33686@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33687
33688 if (debug_level >= DEBUG_LEVEL_INFO)
33689 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
33690- __FILE__,__LINE__,tty->driver->name, port->count);
33691+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
33692
33693 /* If port is closing, signal caller to try again */
33694 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
33695@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33696 goto cleanup;
33697 }
33698 spin_lock(&port->lock);
33699- port->count++;
33700+ atomic_inc(&port->count);
33701 spin_unlock(&port->lock);
33702 spin_unlock_irqrestore(&info->netlock, flags);
33703
33704- if (port->count == 1) {
33705+ if (atomic_read(&port->count) == 1) {
33706 /* 1st open on this device, init hardware */
33707 retval = startup(info, tty);
33708 if (retval < 0)
33709@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
33710 unsigned short new_crctype;
33711
33712 /* return error if TTY interface open */
33713- if (info->port.count)
33714+ if (atomic_read(&info->port.count))
33715 return -EBUSY;
33716
33717 switch (encoding)
33718@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
33719
33720 /* arbitrate between network and tty opens */
33721 spin_lock_irqsave(&info->netlock, flags);
33722- if (info->port.count != 0 || info->netcount != 0) {
33723+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
33724 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
33725 spin_unlock_irqrestore(&info->netlock, flags);
33726 return -EBUSY;
33727@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33728 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
33729
33730 /* return error if TTY interface open */
33731- if (info->port.count)
33732+ if (atomic_read(&info->port.count))
33733 return -EBUSY;
33734
33735 if (cmd != SIOCWANDEV)
33736diff --git a/drivers/char/random.c b/drivers/char/random.c
33737index 57d4b15..253207b 100644
33738--- a/drivers/char/random.c
33739+++ b/drivers/char/random.c
33740@@ -272,8 +272,13 @@
33741 /*
33742 * Configuration information
33743 */
33744+#ifdef CONFIG_GRKERNSEC_RANDNET
33745+#define INPUT_POOL_WORDS 512
33746+#define OUTPUT_POOL_WORDS 128
33747+#else
33748 #define INPUT_POOL_WORDS 128
33749 #define OUTPUT_POOL_WORDS 32
33750+#endif
33751 #define SEC_XFER_SIZE 512
33752 #define EXTRACT_SIZE 10
33753
33754@@ -313,10 +318,17 @@ static struct poolinfo {
33755 int poolwords;
33756 int tap1, tap2, tap3, tap4, tap5;
33757 } poolinfo_table[] = {
33758+#ifdef CONFIG_GRKERNSEC_RANDNET
33759+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
33760+ { 512, 411, 308, 208, 104, 1 },
33761+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
33762+ { 128, 103, 76, 51, 25, 1 },
33763+#else
33764 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
33765 { 128, 103, 76, 51, 25, 1 },
33766 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
33767 { 32, 26, 20, 14, 7, 1 },
33768+#endif
33769 #if 0
33770 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
33771 { 2048, 1638, 1231, 819, 411, 1 },
33772@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
33773 input_rotate += i ? 7 : 14;
33774 }
33775
33776- ACCESS_ONCE(r->input_rotate) = input_rotate;
33777- ACCESS_ONCE(r->add_ptr) = i;
33778+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
33779+ ACCESS_ONCE_RW(r->add_ptr) = i;
33780 smp_wmb();
33781
33782 if (out)
33783@@ -1024,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
33784
33785 extract_buf(r, tmp);
33786 i = min_t(int, nbytes, EXTRACT_SIZE);
33787- if (copy_to_user(buf, tmp, i)) {
33788+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
33789 ret = -EFAULT;
33790 break;
33791 }
33792@@ -1360,7 +1372,7 @@ EXPORT_SYMBOL(generate_random_uuid);
33793 #include <linux/sysctl.h>
33794
33795 static int min_read_thresh = 8, min_write_thresh;
33796-static int max_read_thresh = INPUT_POOL_WORDS * 32;
33797+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
33798 static int max_write_thresh = INPUT_POOL_WORDS * 32;
33799 static char sysctl_bootid[16];
33800
33801@@ -1376,7 +1388,7 @@ static char sysctl_bootid[16];
33802 static int proc_do_uuid(ctl_table *table, int write,
33803 void __user *buffer, size_t *lenp, loff_t *ppos)
33804 {
33805- ctl_table fake_table;
33806+ ctl_table_no_const fake_table;
33807 unsigned char buf[64], tmp_uuid[16], *uuid;
33808
33809 uuid = table->data;
33810diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
33811index d780295..b29f3a8 100644
33812--- a/drivers/char/sonypi.c
33813+++ b/drivers/char/sonypi.c
33814@@ -54,6 +54,7 @@
33815
33816 #include <asm/uaccess.h>
33817 #include <asm/io.h>
33818+#include <asm/local.h>
33819
33820 #include <linux/sonypi.h>
33821
33822@@ -490,7 +491,7 @@ static struct sonypi_device {
33823 spinlock_t fifo_lock;
33824 wait_queue_head_t fifo_proc_list;
33825 struct fasync_struct *fifo_async;
33826- int open_count;
33827+ local_t open_count;
33828 int model;
33829 struct input_dev *input_jog_dev;
33830 struct input_dev *input_key_dev;
33831@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33832 static int sonypi_misc_release(struct inode *inode, struct file *file)
33833 {
33834 mutex_lock(&sonypi_device.lock);
33835- sonypi_device.open_count--;
33836+ local_dec(&sonypi_device.open_count);
33837 mutex_unlock(&sonypi_device.lock);
33838 return 0;
33839 }
33840@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33841 {
33842 mutex_lock(&sonypi_device.lock);
33843 /* Flush input queue on first open */
33844- if (!sonypi_device.open_count)
33845+ if (!local_read(&sonypi_device.open_count))
33846 kfifo_reset(&sonypi_device.fifo);
33847- sonypi_device.open_count++;
33848+ local_inc(&sonypi_device.open_count);
33849 mutex_unlock(&sonypi_device.lock);
33850
33851 return 0;
33852diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33853index 93211df..c7805f7 100644
33854--- a/drivers/char/tpm/tpm.c
33855+++ b/drivers/char/tpm/tpm.c
33856@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33857 chip->vendor.req_complete_val)
33858 goto out_recv;
33859
33860- if ((status == chip->vendor.req_canceled)) {
33861+ if (status == chip->vendor.req_canceled) {
33862 dev_err(chip->dev, "Operation Canceled\n");
33863 rc = -ECANCELED;
33864 goto out;
33865diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33866index 56051d0..11cf3b7 100644
33867--- a/drivers/char/tpm/tpm_acpi.c
33868+++ b/drivers/char/tpm/tpm_acpi.c
33869@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33870 virt = acpi_os_map_memory(start, len);
33871 if (!virt) {
33872 kfree(log->bios_event_log);
33873+ log->bios_event_log = NULL;
33874 printk("%s: ERROR - Unable to map memory\n", __func__);
33875 return -EIO;
33876 }
33877
33878- memcpy_fromio(log->bios_event_log, virt, len);
33879+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33880
33881 acpi_os_unmap_memory(virt, len);
33882 return 0;
33883diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
33884index 84ddc55..1d32f1e 100644
33885--- a/drivers/char/tpm/tpm_eventlog.c
33886+++ b/drivers/char/tpm/tpm_eventlog.c
33887@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
33888 event = addr;
33889
33890 if ((event->event_type == 0 && event->event_size == 0) ||
33891- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
33892+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
33893 return NULL;
33894
33895 return addr;
33896@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
33897 return NULL;
33898
33899 if ((event->event_type == 0 && event->event_size == 0) ||
33900- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
33901+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
33902 return NULL;
33903
33904 (*pos)++;
33905@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
33906 int i;
33907
33908 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
33909- seq_putc(m, data[i]);
33910+ if (!seq_putc(m, data[i]))
33911+ return -EFAULT;
33912
33913 return 0;
33914 }
33915diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
33916index ee4dbea..69c817b 100644
33917--- a/drivers/char/virtio_console.c
33918+++ b/drivers/char/virtio_console.c
33919@@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
33920 if (to_user) {
33921 ssize_t ret;
33922
33923- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
33924+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
33925 if (ret)
33926 return -EFAULT;
33927 } else {
33928@@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
33929 if (!port_has_data(port) && !port->host_connected)
33930 return 0;
33931
33932- return fill_readbuf(port, ubuf, count, true);
33933+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
33934 }
33935
33936 static int wait_port_writable(struct port *port, bool nonblock)
33937diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
33938index 8ae1a61..9c00613 100644
33939--- a/drivers/clocksource/arm_generic.c
33940+++ b/drivers/clocksource/arm_generic.c
33941@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
33942 return NOTIFY_OK;
33943 }
33944
33945-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
33946+static struct notifier_block arch_timer_cpu_nb = {
33947 .notifier_call = arch_timer_cpu_notify,
33948 };
33949
33950diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
33951index 7b0d49d..134fac9 100644
33952--- a/drivers/cpufreq/acpi-cpufreq.c
33953+++ b/drivers/cpufreq/acpi-cpufreq.c
33954@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
33955 return sprintf(buf, "%u\n", boost_enabled);
33956 }
33957
33958-static struct global_attr global_boost = __ATTR(boost, 0644,
33959+static global_attr_no_const global_boost = __ATTR(boost, 0644,
33960 show_global_boost,
33961 store_global_boost);
33962
33963@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33964 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
33965 per_cpu(acfreq_data, cpu) = data;
33966
33967- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
33968- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
33969+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
33970+ pax_open_kernel();
33971+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
33972+ pax_close_kernel();
33973+ }
33974
33975 result = acpi_processor_register_performance(data->acpi_data, cpu);
33976 if (result)
33977@@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33978 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
33979 break;
33980 case ACPI_ADR_SPACE_FIXED_HARDWARE:
33981- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
33982+ pax_open_kernel();
33983+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
33984+ pax_close_kernel();
33985 policy->cur = get_cur_freq_on_cpu(cpu);
33986 break;
33987 default:
33988@@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33989 acpi_processor_notify_smm(THIS_MODULE);
33990
33991 /* Check for APERF/MPERF support in hardware */
33992- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
33993- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
33994+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
33995+ pax_open_kernel();
33996+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
33997+ pax_close_kernel();
33998+ }
33999
34000 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34001 for (i = 0; i < perf->state_count; i++)
34002diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34003index 1f93dbd..305cef1 100644
34004--- a/drivers/cpufreq/cpufreq.c
34005+++ b/drivers/cpufreq/cpufreq.c
34006@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34007 return NOTIFY_OK;
34008 }
34009
34010-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34011+static struct notifier_block cpufreq_cpu_notifier = {
34012 .notifier_call = cpufreq_cpu_callback,
34013 };
34014
34015@@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34016
34017 pr_debug("trying to register driver %s\n", driver_data->name);
34018
34019- if (driver_data->setpolicy)
34020- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34021+ if (driver_data->setpolicy) {
34022+ pax_open_kernel();
34023+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34024+ pax_close_kernel();
34025+ }
34026
34027 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34028 if (cpufreq_driver) {
34029diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34030index 6c5f1d3..c7e2f35e 100644
34031--- a/drivers/cpufreq/cpufreq_governor.c
34032+++ b/drivers/cpufreq/cpufreq_governor.c
34033@@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34034 * governor, thus we are bound to jiffes/HZ
34035 */
34036 if (dbs_data->governor == GOV_CONSERVATIVE) {
34037- struct cs_ops *ops = dbs_data->gov_ops;
34038+ const struct cs_ops *ops = dbs_data->gov_ops;
34039
34040 cpufreq_register_notifier(ops->notifier_block,
34041 CPUFREQ_TRANSITION_NOTIFIER);
34042@@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34043 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
34044 jiffies_to_usecs(10);
34045 } else {
34046- struct od_ops *ops = dbs_data->gov_ops;
34047+ const struct od_ops *ops = dbs_data->gov_ops;
34048
34049 od_tuners->io_is_busy = ops->io_busy();
34050 }
34051@@ -268,7 +268,7 @@ second_time:
34052 cs_dbs_info->enable = 1;
34053 cs_dbs_info->requested_freq = policy->cur;
34054 } else {
34055- struct od_ops *ops = dbs_data->gov_ops;
34056+ const struct od_ops *ops = dbs_data->gov_ops;
34057 od_dbs_info->rate_mult = 1;
34058 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
34059 ops->powersave_bias_init_cpu(cpu);
34060@@ -289,7 +289,7 @@ second_time:
34061 mutex_destroy(&cpu_cdbs->timer_mutex);
34062 dbs_data->enable--;
34063 if (!dbs_data->enable) {
34064- struct cs_ops *ops = dbs_data->gov_ops;
34065+ const struct cs_ops *ops = dbs_data->gov_ops;
34066
34067 sysfs_remove_group(cpufreq_global_kobject,
34068 dbs_data->attr_group);
34069diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34070index f661654..6c8e638 100644
34071--- a/drivers/cpufreq/cpufreq_governor.h
34072+++ b/drivers/cpufreq/cpufreq_governor.h
34073@@ -142,7 +142,7 @@ struct dbs_data {
34074 void (*gov_check_cpu)(int cpu, unsigned int load);
34075
34076 /* Governor specific ops, see below */
34077- void *gov_ops;
34078+ const void *gov_ops;
34079 };
34080
34081 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34082diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34083index 9d7732b..0b1a793 100644
34084--- a/drivers/cpufreq/cpufreq_stats.c
34085+++ b/drivers/cpufreq/cpufreq_stats.c
34086@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34087 }
34088
34089 /* priority=1 so this will get called before cpufreq_remove_dev */
34090-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34091+static struct notifier_block cpufreq_stat_cpu_notifier = {
34092 .notifier_call = cpufreq_stat_cpu_callback,
34093 .priority = 1,
34094 };
34095diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34096index 827629c9..0bc6a03 100644
34097--- a/drivers/cpufreq/p4-clockmod.c
34098+++ b/drivers/cpufreq/p4-clockmod.c
34099@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34100 case 0x0F: /* Core Duo */
34101 case 0x16: /* Celeron Core */
34102 case 0x1C: /* Atom */
34103- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34104+ pax_open_kernel();
34105+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34106+ pax_close_kernel();
34107 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34108 case 0x0D: /* Pentium M (Dothan) */
34109- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34110+ pax_open_kernel();
34111+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34112+ pax_close_kernel();
34113 /* fall through */
34114 case 0x09: /* Pentium M (Banias) */
34115 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34116@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34117
34118 /* on P-4s, the TSC runs with constant frequency independent whether
34119 * throttling is active or not. */
34120- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34121+ pax_open_kernel();
34122+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34123+ pax_close_kernel();
34124
34125 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34126 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34127diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34128index 3a953d5..f5993f6 100644
34129--- a/drivers/cpufreq/speedstep-centrino.c
34130+++ b/drivers/cpufreq/speedstep-centrino.c
34131@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34132 !cpu_has(cpu, X86_FEATURE_EST))
34133 return -ENODEV;
34134
34135- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34136- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34137+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34138+ pax_open_kernel();
34139+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34140+ pax_close_kernel();
34141+ }
34142
34143 if (policy->cpu != 0)
34144 return -ENODEV;
34145diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34146index e1f6860..f8de20b 100644
34147--- a/drivers/cpuidle/cpuidle.c
34148+++ b/drivers/cpuidle/cpuidle.c
34149@@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
34150
34151 static void poll_idle_init(struct cpuidle_driver *drv)
34152 {
34153- struct cpuidle_state *state = &drv->states[0];
34154+ cpuidle_state_no_const *state = &drv->states[0];
34155
34156 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34157 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34158diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34159index ea2f8e7..70ac501 100644
34160--- a/drivers/cpuidle/governor.c
34161+++ b/drivers/cpuidle/governor.c
34162@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34163 mutex_lock(&cpuidle_lock);
34164 if (__cpuidle_find_governor(gov->name) == NULL) {
34165 ret = 0;
34166- list_add_tail(&gov->governor_list, &cpuidle_governors);
34167+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34168 if (!cpuidle_curr_governor ||
34169 cpuidle_curr_governor->rating < gov->rating)
34170 cpuidle_switch_governor(gov);
34171@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34172 new_gov = cpuidle_replace_governor(gov->rating);
34173 cpuidle_switch_governor(new_gov);
34174 }
34175- list_del(&gov->governor_list);
34176+ pax_list_del((struct list_head *)&gov->governor_list);
34177 mutex_unlock(&cpuidle_lock);
34178 }
34179
34180diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34181index 428754a..8bdf9cc 100644
34182--- a/drivers/cpuidle/sysfs.c
34183+++ b/drivers/cpuidle/sysfs.c
34184@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34185 NULL
34186 };
34187
34188-static struct attribute_group cpuidle_attr_group = {
34189+static attribute_group_no_const cpuidle_attr_group = {
34190 .attrs = cpuidle_default_attrs,
34191 .name = "cpuidle",
34192 };
34193diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34194index 3b36797..289c16a 100644
34195--- a/drivers/devfreq/devfreq.c
34196+++ b/drivers/devfreq/devfreq.c
34197@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34198 goto err_out;
34199 }
34200
34201- list_add(&governor->node, &devfreq_governor_list);
34202+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34203
34204 list_for_each_entry(devfreq, &devfreq_list, node) {
34205 int ret = 0;
34206@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34207 }
34208 }
34209
34210- list_del(&governor->node);
34211+ pax_list_del((struct list_head *)&governor->node);
34212 err_out:
34213 mutex_unlock(&devfreq_list_lock);
34214
34215diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34216index b70709b..1d8d02a 100644
34217--- a/drivers/dma/sh/shdma.c
34218+++ b/drivers/dma/sh/shdma.c
34219@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34220 return ret;
34221 }
34222
34223-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34224+static struct notifier_block sh_dmae_nmi_notifier = {
34225 .notifier_call = sh_dmae_nmi_handler,
34226
34227 /* Run before NMI debug handler and KGDB */
34228diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34229index 0ca1ca7..6e6f454 100644
34230--- a/drivers/edac/edac_mc_sysfs.c
34231+++ b/drivers/edac/edac_mc_sysfs.c
34232@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34233 struct dev_ch_attribute {
34234 struct device_attribute attr;
34235 int channel;
34236-};
34237+} __do_const;
34238
34239 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34240 struct dev_ch_attribute dev_attr_legacy_##_name = \
34241diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34242index 0056c4d..23b54d9 100644
34243--- a/drivers/edac/edac_pci_sysfs.c
34244+++ b/drivers/edac/edac_pci_sysfs.c
34245@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34246 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34247 static int edac_pci_poll_msec = 1000; /* one second workq period */
34248
34249-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34250-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34251+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34252+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34253
34254 static struct kobject *edac_pci_top_main_kobj;
34255 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34256@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34257 void *value;
34258 ssize_t(*show) (void *, char *);
34259 ssize_t(*store) (void *, const char *, size_t);
34260-};
34261+} __do_const;
34262
34263 /* Set of show/store abstract level functions for PCI Parity object */
34264 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34265@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34266 edac_printk(KERN_CRIT, EDAC_PCI,
34267 "Signaled System Error on %s\n",
34268 pci_name(dev));
34269- atomic_inc(&pci_nonparity_count);
34270+ atomic_inc_unchecked(&pci_nonparity_count);
34271 }
34272
34273 if (status & (PCI_STATUS_PARITY)) {
34274@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34275 "Master Data Parity Error on %s\n",
34276 pci_name(dev));
34277
34278- atomic_inc(&pci_parity_count);
34279+ atomic_inc_unchecked(&pci_parity_count);
34280 }
34281
34282 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34283@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34284 "Detected Parity Error on %s\n",
34285 pci_name(dev));
34286
34287- atomic_inc(&pci_parity_count);
34288+ atomic_inc_unchecked(&pci_parity_count);
34289 }
34290 }
34291
34292@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34293 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34294 "Signaled System Error on %s\n",
34295 pci_name(dev));
34296- atomic_inc(&pci_nonparity_count);
34297+ atomic_inc_unchecked(&pci_nonparity_count);
34298 }
34299
34300 if (status & (PCI_STATUS_PARITY)) {
34301@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34302 "Master Data Parity Error on "
34303 "%s\n", pci_name(dev));
34304
34305- atomic_inc(&pci_parity_count);
34306+ atomic_inc_unchecked(&pci_parity_count);
34307 }
34308
34309 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34310@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34311 "Detected Parity Error on %s\n",
34312 pci_name(dev));
34313
34314- atomic_inc(&pci_parity_count);
34315+ atomic_inc_unchecked(&pci_parity_count);
34316 }
34317 }
34318 }
34319@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34320 if (!check_pci_errors)
34321 return;
34322
34323- before_count = atomic_read(&pci_parity_count);
34324+ before_count = atomic_read_unchecked(&pci_parity_count);
34325
34326 /* scan all PCI devices looking for a Parity Error on devices and
34327 * bridges.
34328@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34329 /* Only if operator has selected panic on PCI Error */
34330 if (edac_pci_get_panic_on_pe()) {
34331 /* If the count is different 'after' from 'before' */
34332- if (before_count != atomic_read(&pci_parity_count))
34333+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34334 panic("EDAC: PCI Parity Error");
34335 }
34336 }
34337diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34338index 6796799..99e8377 100644
34339--- a/drivers/edac/mce_amd.h
34340+++ b/drivers/edac/mce_amd.h
34341@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34342 struct amd_decoder_ops {
34343 bool (*mc0_mce)(u16, u8);
34344 bool (*mc1_mce)(u16, u8);
34345-};
34346+} __no_const;
34347
34348 void amd_report_gart_errors(bool);
34349 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34350diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34351index 57ea7f4..789e3c3 100644
34352--- a/drivers/firewire/core-card.c
34353+++ b/drivers/firewire/core-card.c
34354@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34355
34356 void fw_core_remove_card(struct fw_card *card)
34357 {
34358- struct fw_card_driver dummy_driver = dummy_driver_template;
34359+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34360
34361 card->driver->update_phy_reg(card, 4,
34362 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34363diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34364index f8d2287..5aaf4db 100644
34365--- a/drivers/firewire/core-cdev.c
34366+++ b/drivers/firewire/core-cdev.c
34367@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34368 int ret;
34369
34370 if ((request->channels == 0 && request->bandwidth == 0) ||
34371- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34372- request->bandwidth < 0)
34373+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34374 return -EINVAL;
34375
34376 r = kmalloc(sizeof(*r), GFP_KERNEL);
34377diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34378index af3e8aa..eb2f227 100644
34379--- a/drivers/firewire/core-device.c
34380+++ b/drivers/firewire/core-device.c
34381@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34382 struct config_rom_attribute {
34383 struct device_attribute attr;
34384 u32 key;
34385-};
34386+} __do_const;
34387
34388 static ssize_t show_immediate(struct device *dev,
34389 struct device_attribute *dattr, char *buf)
34390diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34391index 28a94c7..58da63a 100644
34392--- a/drivers/firewire/core-transaction.c
34393+++ b/drivers/firewire/core-transaction.c
34394@@ -38,6 +38,7 @@
34395 #include <linux/timer.h>
34396 #include <linux/types.h>
34397 #include <linux/workqueue.h>
34398+#include <linux/sched.h>
34399
34400 #include <asm/byteorder.h>
34401
34402diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34403index 515a42c..5ecf3ba 100644
34404--- a/drivers/firewire/core.h
34405+++ b/drivers/firewire/core.h
34406@@ -111,6 +111,7 @@ struct fw_card_driver {
34407
34408 int (*stop_iso)(struct fw_iso_context *ctx);
34409 };
34410+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34411
34412 void fw_card_initialize(struct fw_card *card,
34413 const struct fw_card_driver *driver, struct device *device);
34414diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34415index 94a58a0..f5eba42 100644
34416--- a/drivers/firmware/dmi-id.c
34417+++ b/drivers/firmware/dmi-id.c
34418@@ -16,7 +16,7 @@
34419 struct dmi_device_attribute{
34420 struct device_attribute dev_attr;
34421 int field;
34422-};
34423+} __do_const;
34424 #define to_dmi_dev_attr(_dev_attr) \
34425 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34426
34427diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34428index 4cd392d..4b629e1 100644
34429--- a/drivers/firmware/dmi_scan.c
34430+++ b/drivers/firmware/dmi_scan.c
34431@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
34432 }
34433 }
34434 else {
34435- /*
34436- * no iounmap() for that ioremap(); it would be a no-op, but
34437- * it's so early in setup that sucker gets confused into doing
34438- * what it shouldn't if we actually call it.
34439- */
34440 p = dmi_ioremap(0xF0000, 0x10000);
34441 if (p == NULL)
34442 goto error;
34443@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
34444 if (buf == NULL)
34445 return -1;
34446
34447- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
34448+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
34449
34450 iounmap(buf);
34451 return 0;
34452diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
34453index 2a2e145..73745e79 100644
34454--- a/drivers/firmware/efivars.c
34455+++ b/drivers/firmware/efivars.c
34456@@ -133,7 +133,7 @@ struct efivar_attribute {
34457 };
34458
34459 static struct efivars __efivars;
34460-static struct efivar_operations ops;
34461+static efivar_operations_no_const ops __read_only;
34462
34463 #define PSTORE_EFI_ATTRIBUTES \
34464 (EFI_VARIABLE_NON_VOLATILE | \
34465@@ -1798,7 +1798,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
34466 static int
34467 create_efivars_bin_attributes(struct efivars *efivars)
34468 {
34469- struct bin_attribute *attr;
34470+ bin_attribute_no_const *attr;
34471 int error;
34472
34473 /* new_var */
34474diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
34475index 2a90ba6..07f3733 100644
34476--- a/drivers/firmware/google/memconsole.c
34477+++ b/drivers/firmware/google/memconsole.c
34478@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
34479 if (!found_memconsole())
34480 return -ENODEV;
34481
34482- memconsole_bin_attr.size = memconsole_length;
34483+ pax_open_kernel();
34484+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
34485+ pax_close_kernel();
34486
34487 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
34488
34489diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
34490index 6f2306d..af9476a 100644
34491--- a/drivers/gpio/gpio-ich.c
34492+++ b/drivers/gpio/gpio-ich.c
34493@@ -69,7 +69,7 @@ struct ichx_desc {
34494 /* Some chipsets have quirks, let these use their own request/get */
34495 int (*request)(struct gpio_chip *chip, unsigned offset);
34496 int (*get)(struct gpio_chip *chip, unsigned offset);
34497-};
34498+} __do_const;
34499
34500 static struct {
34501 spinlock_t lock;
34502diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
34503index 9902732..64b62dd 100644
34504--- a/drivers/gpio/gpio-vr41xx.c
34505+++ b/drivers/gpio/gpio-vr41xx.c
34506@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
34507 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
34508 maskl, pendl, maskh, pendh);
34509
34510- atomic_inc(&irq_err_count);
34511+ atomic_inc_unchecked(&irq_err_count);
34512
34513 return -EINVAL;
34514 }
34515diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
34516index 7b2d378..cc947ea 100644
34517--- a/drivers/gpu/drm/drm_crtc_helper.c
34518+++ b/drivers/gpu/drm/drm_crtc_helper.c
34519@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
34520 struct drm_crtc *tmp;
34521 int crtc_mask = 1;
34522
34523- WARN(!crtc, "checking null crtc?\n");
34524+ BUG_ON(!crtc);
34525
34526 dev = crtc->dev;
34527
34528diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
34529index be174ca..7f38143 100644
34530--- a/drivers/gpu/drm/drm_drv.c
34531+++ b/drivers/gpu/drm/drm_drv.c
34532@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
34533 /**
34534 * Copy and IOCTL return string to user space
34535 */
34536-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
34537+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
34538 {
34539 int len;
34540
34541@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
34542 struct drm_file *file_priv = filp->private_data;
34543 struct drm_device *dev;
34544 struct drm_ioctl_desc *ioctl;
34545- drm_ioctl_t *func;
34546+ drm_ioctl_no_const_t func;
34547 unsigned int nr = DRM_IOCTL_NR(cmd);
34548 int retcode = -EINVAL;
34549 char stack_kdata[128];
34550@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
34551 return -ENODEV;
34552
34553 atomic_inc(&dev->ioctl_count);
34554- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
34555+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
34556 ++file_priv->ioctl_count;
34557
34558 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
34559diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
34560index 133b413..fd68225 100644
34561--- a/drivers/gpu/drm/drm_fops.c
34562+++ b/drivers/gpu/drm/drm_fops.c
34563@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
34564 }
34565
34566 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
34567- atomic_set(&dev->counts[i], 0);
34568+ atomic_set_unchecked(&dev->counts[i], 0);
34569
34570 dev->sigdata.lock = NULL;
34571
34572@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
34573 if (drm_device_is_unplugged(dev))
34574 return -ENODEV;
34575
34576- if (!dev->open_count++)
34577+ if (local_inc_return(&dev->open_count) == 1)
34578 need_setup = 1;
34579 mutex_lock(&dev->struct_mutex);
34580 old_mapping = dev->dev_mapping;
34581@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
34582 retcode = drm_open_helper(inode, filp, dev);
34583 if (retcode)
34584 goto err_undo;
34585- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
34586+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
34587 if (need_setup) {
34588 retcode = drm_setup(dev);
34589 if (retcode)
34590@@ -164,7 +164,7 @@ err_undo:
34591 iput(container_of(dev->dev_mapping, struct inode, i_data));
34592 dev->dev_mapping = old_mapping;
34593 mutex_unlock(&dev->struct_mutex);
34594- dev->open_count--;
34595+ local_dec(&dev->open_count);
34596 return retcode;
34597 }
34598 EXPORT_SYMBOL(drm_open);
34599@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
34600
34601 mutex_lock(&drm_global_mutex);
34602
34603- DRM_DEBUG("open_count = %d\n", dev->open_count);
34604+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
34605
34606 if (dev->driver->preclose)
34607 dev->driver->preclose(dev, file_priv);
34608@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
34609 * Begin inline drm_release
34610 */
34611
34612- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
34613+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
34614 task_pid_nr(current),
34615 (long)old_encode_dev(file_priv->minor->device),
34616- dev->open_count);
34617+ local_read(&dev->open_count));
34618
34619 /* Release any auth tokens that might point to this file_priv,
34620 (do that under the drm_global_mutex) */
34621@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
34622 * End inline drm_release
34623 */
34624
34625- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
34626- if (!--dev->open_count) {
34627+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
34628+ if (local_dec_and_test(&dev->open_count)) {
34629 if (atomic_read(&dev->ioctl_count)) {
34630 DRM_ERROR("Device busy: %d\n",
34631 atomic_read(&dev->ioctl_count));
34632diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
34633index f731116..629842c 100644
34634--- a/drivers/gpu/drm/drm_global.c
34635+++ b/drivers/gpu/drm/drm_global.c
34636@@ -36,7 +36,7 @@
34637 struct drm_global_item {
34638 struct mutex mutex;
34639 void *object;
34640- int refcount;
34641+ atomic_t refcount;
34642 };
34643
34644 static struct drm_global_item glob[DRM_GLOBAL_NUM];
34645@@ -49,7 +49,7 @@ void drm_global_init(void)
34646 struct drm_global_item *item = &glob[i];
34647 mutex_init(&item->mutex);
34648 item->object = NULL;
34649- item->refcount = 0;
34650+ atomic_set(&item->refcount, 0);
34651 }
34652 }
34653
34654@@ -59,7 +59,7 @@ void drm_global_release(void)
34655 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
34656 struct drm_global_item *item = &glob[i];
34657 BUG_ON(item->object != NULL);
34658- BUG_ON(item->refcount != 0);
34659+ BUG_ON(atomic_read(&item->refcount) != 0);
34660 }
34661 }
34662
34663@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34664 void *object;
34665
34666 mutex_lock(&item->mutex);
34667- if (item->refcount == 0) {
34668+ if (atomic_read(&item->refcount) == 0) {
34669 item->object = kzalloc(ref->size, GFP_KERNEL);
34670 if (unlikely(item->object == NULL)) {
34671 ret = -ENOMEM;
34672@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34673 goto out_err;
34674
34675 }
34676- ++item->refcount;
34677+ atomic_inc(&item->refcount);
34678 ref->object = item->object;
34679 object = item->object;
34680 mutex_unlock(&item->mutex);
34681@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
34682 struct drm_global_item *item = &glob[ref->global_type];
34683
34684 mutex_lock(&item->mutex);
34685- BUG_ON(item->refcount == 0);
34686+ BUG_ON(atomic_read(&item->refcount) == 0);
34687 BUG_ON(ref->object != item->object);
34688- if (--item->refcount == 0) {
34689+ if (atomic_dec_and_test(&item->refcount)) {
34690 ref->release(ref);
34691 item->object = NULL;
34692 }
34693diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
34694index d4b20ce..77a8d41 100644
34695--- a/drivers/gpu/drm/drm_info.c
34696+++ b/drivers/gpu/drm/drm_info.c
34697@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
34698 struct drm_local_map *map;
34699 struct drm_map_list *r_list;
34700
34701- /* Hardcoded from _DRM_FRAME_BUFFER,
34702- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
34703- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
34704- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
34705+ static const char * const types[] = {
34706+ [_DRM_FRAME_BUFFER] = "FB",
34707+ [_DRM_REGISTERS] = "REG",
34708+ [_DRM_SHM] = "SHM",
34709+ [_DRM_AGP] = "AGP",
34710+ [_DRM_SCATTER_GATHER] = "SG",
34711+ [_DRM_CONSISTENT] = "PCI",
34712+ [_DRM_GEM] = "GEM" };
34713 const char *type;
34714 int i;
34715
34716@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
34717 map = r_list->map;
34718 if (!map)
34719 continue;
34720- if (map->type < 0 || map->type > 5)
34721+ if (map->type >= ARRAY_SIZE(types))
34722 type = "??";
34723 else
34724 type = types[map->type];
34725@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
34726 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
34727 vma->vm_flags & VM_LOCKED ? 'l' : '-',
34728 vma->vm_flags & VM_IO ? 'i' : '-',
34729+#ifdef CONFIG_GRKERNSEC_HIDESYM
34730+ 0);
34731+#else
34732 vma->vm_pgoff);
34733+#endif
34734
34735 #if defined(__i386__)
34736 pgprot = pgprot_val(vma->vm_page_prot);
34737diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
34738index 2f4c434..dd12cd2 100644
34739--- a/drivers/gpu/drm/drm_ioc32.c
34740+++ b/drivers/gpu/drm/drm_ioc32.c
34741@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
34742 request = compat_alloc_user_space(nbytes);
34743 if (!access_ok(VERIFY_WRITE, request, nbytes))
34744 return -EFAULT;
34745- list = (struct drm_buf_desc *) (request + 1);
34746+ list = (struct drm_buf_desc __user *) (request + 1);
34747
34748 if (__put_user(count, &request->count)
34749 || __put_user(list, &request->list))
34750@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
34751 request = compat_alloc_user_space(nbytes);
34752 if (!access_ok(VERIFY_WRITE, request, nbytes))
34753 return -EFAULT;
34754- list = (struct drm_buf_pub *) (request + 1);
34755+ list = (struct drm_buf_pub __user *) (request + 1);
34756
34757 if (__put_user(count, &request->count)
34758 || __put_user(list, &request->list))
34759@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
34760 return 0;
34761 }
34762
34763-drm_ioctl_compat_t *drm_compat_ioctls[] = {
34764+drm_ioctl_compat_t drm_compat_ioctls[] = {
34765 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
34766 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
34767 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
34768@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
34769 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34770 {
34771 unsigned int nr = DRM_IOCTL_NR(cmd);
34772- drm_ioctl_compat_t *fn;
34773 int ret;
34774
34775 /* Assume that ioctls without an explicit compat routine will just
34776@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34777 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
34778 return drm_ioctl(filp, cmd, arg);
34779
34780- fn = drm_compat_ioctls[nr];
34781-
34782- if (fn != NULL)
34783- ret = (*fn) (filp, cmd, arg);
34784+ if (drm_compat_ioctls[nr] != NULL)
34785+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
34786 else
34787 ret = drm_ioctl(filp, cmd, arg);
34788
34789diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
34790index e77bd8b..1571b85 100644
34791--- a/drivers/gpu/drm/drm_ioctl.c
34792+++ b/drivers/gpu/drm/drm_ioctl.c
34793@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
34794 stats->data[i].value =
34795 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
34796 else
34797- stats->data[i].value = atomic_read(&dev->counts[i]);
34798+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
34799 stats->data[i].type = dev->types[i];
34800 }
34801
34802diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
34803index d752c96..fe08455 100644
34804--- a/drivers/gpu/drm/drm_lock.c
34805+++ b/drivers/gpu/drm/drm_lock.c
34806@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34807 if (drm_lock_take(&master->lock, lock->context)) {
34808 master->lock.file_priv = file_priv;
34809 master->lock.lock_time = jiffies;
34810- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
34811+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
34812 break; /* Got lock */
34813 }
34814
34815@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34816 return -EINVAL;
34817 }
34818
34819- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
34820+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
34821
34822 if (drm_lock_free(&master->lock, lock->context)) {
34823 /* FIXME: Should really bail out here. */
34824diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
34825index 200e104..59facda 100644
34826--- a/drivers/gpu/drm/drm_stub.c
34827+++ b/drivers/gpu/drm/drm_stub.c
34828@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
34829
34830 drm_device_set_unplugged(dev);
34831
34832- if (dev->open_count == 0) {
34833+ if (local_read(&dev->open_count) == 0) {
34834 drm_put_dev(dev);
34835 }
34836 mutex_unlock(&drm_global_mutex);
34837diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
34838index 004ecdf..db1f6e0 100644
34839--- a/drivers/gpu/drm/i810/i810_dma.c
34840+++ b/drivers/gpu/drm/i810/i810_dma.c
34841@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
34842 dma->buflist[vertex->idx],
34843 vertex->discard, vertex->used);
34844
34845- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34846- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34847+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34848+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34849 sarea_priv->last_enqueue = dev_priv->counter - 1;
34850 sarea_priv->last_dispatch = (int)hw_status[5];
34851
34852@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
34853 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
34854 mc->last_render);
34855
34856- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34857- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34858+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34859+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34860 sarea_priv->last_enqueue = dev_priv->counter - 1;
34861 sarea_priv->last_dispatch = (int)hw_status[5];
34862
34863diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
34864index 6e0acad..93c8289 100644
34865--- a/drivers/gpu/drm/i810/i810_drv.h
34866+++ b/drivers/gpu/drm/i810/i810_drv.h
34867@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
34868 int page_flipping;
34869
34870 wait_queue_head_t irq_queue;
34871- atomic_t irq_received;
34872- atomic_t irq_emitted;
34873+ atomic_unchecked_t irq_received;
34874+ atomic_unchecked_t irq_emitted;
34875
34876 int front_offset;
34877 } drm_i810_private_t;
34878diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
34879index 8a7c48b..72effc2 100644
34880--- a/drivers/gpu/drm/i915/i915_debugfs.c
34881+++ b/drivers/gpu/drm/i915/i915_debugfs.c
34882@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
34883 I915_READ(GTIMR));
34884 }
34885 seq_printf(m, "Interrupts received: %d\n",
34886- atomic_read(&dev_priv->irq_received));
34887+ atomic_read_unchecked(&dev_priv->irq_received));
34888 for_each_ring(ring, dev_priv, i) {
34889 if (IS_GEN6(dev) || IS_GEN7(dev)) {
34890 seq_printf(m,
34891diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
34892index 5206f24..7af0a0a 100644
34893--- a/drivers/gpu/drm/i915/i915_dma.c
34894+++ b/drivers/gpu/drm/i915/i915_dma.c
34895@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
34896 bool can_switch;
34897
34898 spin_lock(&dev->count_lock);
34899- can_switch = (dev->open_count == 0);
34900+ can_switch = (local_read(&dev->open_count) == 0);
34901 spin_unlock(&dev->count_lock);
34902 return can_switch;
34903 }
34904diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
34905index 66ad64f..a865871 100644
34906--- a/drivers/gpu/drm/i915/i915_drv.h
34907+++ b/drivers/gpu/drm/i915/i915_drv.h
34908@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
34909 drm_dma_handle_t *status_page_dmah;
34910 struct resource mch_res;
34911
34912- atomic_t irq_received;
34913+ atomic_unchecked_t irq_received;
34914
34915 /* protects the irq masks */
34916 spinlock_t irq_lock;
34917@@ -1103,7 +1103,7 @@ struct drm_i915_gem_object {
34918 * will be page flipped away on the next vblank. When it
34919 * reaches 0, dev_priv->pending_flip_queue will be woken up.
34920 */
34921- atomic_t pending_flip;
34922+ atomic_unchecked_t pending_flip;
34923 };
34924 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
34925
34926@@ -1634,7 +1634,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
34927 struct drm_i915_private *dev_priv, unsigned port);
34928 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
34929 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
34930-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
34931+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
34932 {
34933 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
34934 }
34935diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34936index 26d08bb..a6203ff 100644
34937--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34938+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34939@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
34940 i915_gem_clflush_object(obj);
34941
34942 if (obj->base.pending_write_domain)
34943- flips |= atomic_read(&obj->pending_flip);
34944+ flips |= atomic_read_unchecked(&obj->pending_flip);
34945
34946 flush_domains |= obj->base.write_domain;
34947 }
34948@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
34949
34950 static int
34951 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
34952- int count)
34953+ unsigned int count)
34954 {
34955- int i;
34956+ unsigned int i;
34957
34958 for (i = 0; i < count; i++) {
34959 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
34960@@ -1197,7 +1197,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
34961 return -ENOMEM;
34962 }
34963 ret = copy_from_user(exec2_list,
34964- (struct drm_i915_relocation_entry __user *)
34965+ (struct drm_i915_gem_exec_object2 __user *)
34966 (uintptr_t) args->buffers_ptr,
34967 sizeof(*exec2_list) * args->buffer_count);
34968 if (ret != 0) {
34969diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
34970index 3c59584..500f2e9 100644
34971--- a/drivers/gpu/drm/i915/i915_ioc32.c
34972+++ b/drivers/gpu/drm/i915/i915_ioc32.c
34973@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
34974 (unsigned long)request);
34975 }
34976
34977-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
34978+static drm_ioctl_compat_t i915_compat_ioctls[] = {
34979 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
34980 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
34981 [DRM_I915_GETPARAM] = compat_i915_getparam,
34982@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
34983 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34984 {
34985 unsigned int nr = DRM_IOCTL_NR(cmd);
34986- drm_ioctl_compat_t *fn = NULL;
34987 int ret;
34988
34989 if (nr < DRM_COMMAND_BASE)
34990 return drm_compat_ioctl(filp, cmd, arg);
34991
34992- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
34993- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
34994-
34995- if (fn != NULL)
34996+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
34997+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
34998 ret = (*fn) (filp, cmd, arg);
34999- else
35000+ } else
35001 ret = drm_ioctl(filp, cmd, arg);
35002
35003 return ret;
35004diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35005index 3c00403..5a5c6c9 100644
35006--- a/drivers/gpu/drm/i915/i915_irq.c
35007+++ b/drivers/gpu/drm/i915/i915_irq.c
35008@@ -539,7 +539,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35009 u32 pipe_stats[I915_MAX_PIPES];
35010 bool blc_event;
35011
35012- atomic_inc(&dev_priv->irq_received);
35013+ atomic_inc_unchecked(&dev_priv->irq_received);
35014
35015 while (true) {
35016 iir = I915_READ(VLV_IIR);
35017@@ -692,7 +692,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35018 irqreturn_t ret = IRQ_NONE;
35019 int i;
35020
35021- atomic_inc(&dev_priv->irq_received);
35022+ atomic_inc_unchecked(&dev_priv->irq_received);
35023
35024 /* disable master interrupt before clearing iir */
35025 de_ier = I915_READ(DEIER);
35026@@ -764,7 +764,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35027 int ret = IRQ_NONE;
35028 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
35029
35030- atomic_inc(&dev_priv->irq_received);
35031+ atomic_inc_unchecked(&dev_priv->irq_received);
35032
35033 /* disable master interrupt before clearing iir */
35034 de_ier = I915_READ(DEIER);
35035@@ -1791,7 +1791,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35036 {
35037 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35038
35039- atomic_set(&dev_priv->irq_received, 0);
35040+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35041
35042 I915_WRITE(HWSTAM, 0xeffe);
35043
35044@@ -1817,7 +1817,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35045 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35046 int pipe;
35047
35048- atomic_set(&dev_priv->irq_received, 0);
35049+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35050
35051 /* VLV magic */
35052 I915_WRITE(VLV_IMR, 0);
35053@@ -2112,7 +2112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35054 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35055 int pipe;
35056
35057- atomic_set(&dev_priv->irq_received, 0);
35058+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35059
35060 for_each_pipe(pipe)
35061 I915_WRITE(PIPESTAT(pipe), 0);
35062@@ -2163,7 +2163,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35063 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35064 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35065
35066- atomic_inc(&dev_priv->irq_received);
35067+ atomic_inc_unchecked(&dev_priv->irq_received);
35068
35069 iir = I915_READ16(IIR);
35070 if (iir == 0)
35071@@ -2248,7 +2248,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35072 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35073 int pipe;
35074
35075- atomic_set(&dev_priv->irq_received, 0);
35076+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35077
35078 if (I915_HAS_HOTPLUG(dev)) {
35079 I915_WRITE(PORT_HOTPLUG_EN, 0);
35080@@ -2343,7 +2343,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35081 };
35082 int pipe, ret = IRQ_NONE;
35083
35084- atomic_inc(&dev_priv->irq_received);
35085+ atomic_inc_unchecked(&dev_priv->irq_received);
35086
35087 iir = I915_READ(IIR);
35088 do {
35089@@ -2469,7 +2469,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35090 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35091 int pipe;
35092
35093- atomic_set(&dev_priv->irq_received, 0);
35094+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35095
35096 I915_WRITE(PORT_HOTPLUG_EN, 0);
35097 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35098@@ -2576,7 +2576,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35099 int irq_received;
35100 int ret = IRQ_NONE, pipe;
35101
35102- atomic_inc(&dev_priv->irq_received);
35103+ atomic_inc_unchecked(&dev_priv->irq_received);
35104
35105 iir = I915_READ(IIR);
35106
35107diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35108index 80aa1fc..85cfce3 100644
35109--- a/drivers/gpu/drm/i915/intel_display.c
35110+++ b/drivers/gpu/drm/i915/intel_display.c
35111@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
35112
35113 wait_event(dev_priv->pending_flip_queue,
35114 atomic_read(&dev_priv->mm.wedged) ||
35115- atomic_read(&obj->pending_flip) == 0);
35116+ atomic_read_unchecked(&obj->pending_flip) == 0);
35117
35118 /* Big Hammer, we also need to ensure that any pending
35119 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
35120@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
35121
35122 obj = work->old_fb_obj;
35123
35124- atomic_clear_mask(1 << intel_crtc->plane,
35125- &obj->pending_flip.counter);
35126+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
35127 wake_up(&dev_priv->pending_flip_queue);
35128
35129 queue_work(dev_priv->wq, &work->work);
35130@@ -7490,7 +7489,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35131 /* Block clients from rendering to the new back buffer until
35132 * the flip occurs and the object is no longer visible.
35133 */
35134- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35135+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35136 atomic_inc(&intel_crtc->unpin_work_count);
35137
35138 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
35139@@ -7507,7 +7506,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
35140
35141 cleanup_pending:
35142 atomic_dec(&intel_crtc->unpin_work_count);
35143- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35144+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
35145 drm_gem_object_unreference(&work->old_fb_obj->base);
35146 drm_gem_object_unreference(&obj->base);
35147 mutex_unlock(&dev->struct_mutex);
35148@@ -8849,13 +8848,13 @@ struct intel_quirk {
35149 int subsystem_vendor;
35150 int subsystem_device;
35151 void (*hook)(struct drm_device *dev);
35152-};
35153+} __do_const;
35154
35155 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35156 struct intel_dmi_quirk {
35157 void (*hook)(struct drm_device *dev);
35158 const struct dmi_system_id (*dmi_id_list)[];
35159-};
35160+} __do_const;
35161
35162 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35163 {
35164@@ -8863,18 +8862,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35165 return 1;
35166 }
35167
35168+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35169+ {
35170+ .callback = intel_dmi_reverse_brightness,
35171+ .ident = "NCR Corporation",
35172+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35173+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35174+ },
35175+ },
35176+ { } /* terminating entry */
35177+};
35178+
35179 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35180 {
35181- .dmi_id_list = &(const struct dmi_system_id[]) {
35182- {
35183- .callback = intel_dmi_reverse_brightness,
35184- .ident = "NCR Corporation",
35185- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35186- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35187- },
35188- },
35189- { } /* terminating entry */
35190- },
35191+ .dmi_id_list = &intel_dmi_quirks_table,
35192 .hook = quirk_invert_brightness,
35193 },
35194 };
35195diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35196index 54558a0..2d97005 100644
35197--- a/drivers/gpu/drm/mga/mga_drv.h
35198+++ b/drivers/gpu/drm/mga/mga_drv.h
35199@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35200 u32 clear_cmd;
35201 u32 maccess;
35202
35203- atomic_t vbl_received; /**< Number of vblanks received. */
35204+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35205 wait_queue_head_t fence_queue;
35206- atomic_t last_fence_retired;
35207+ atomic_unchecked_t last_fence_retired;
35208 u32 next_fence_to_post;
35209
35210 unsigned int fb_cpp;
35211diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35212index 709e90d..89a1c0d 100644
35213--- a/drivers/gpu/drm/mga/mga_ioc32.c
35214+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35215@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35216 return 0;
35217 }
35218
35219-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35220+drm_ioctl_compat_t mga_compat_ioctls[] = {
35221 [DRM_MGA_INIT] = compat_mga_init,
35222 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35223 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35224@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35225 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35226 {
35227 unsigned int nr = DRM_IOCTL_NR(cmd);
35228- drm_ioctl_compat_t *fn = NULL;
35229 int ret;
35230
35231 if (nr < DRM_COMMAND_BASE)
35232 return drm_compat_ioctl(filp, cmd, arg);
35233
35234- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35235- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35236-
35237- if (fn != NULL)
35238+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35239+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35240 ret = (*fn) (filp, cmd, arg);
35241- else
35242+ } else
35243 ret = drm_ioctl(filp, cmd, arg);
35244
35245 return ret;
35246diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35247index 598c281..60d590e 100644
35248--- a/drivers/gpu/drm/mga/mga_irq.c
35249+++ b/drivers/gpu/drm/mga/mga_irq.c
35250@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35251 if (crtc != 0)
35252 return 0;
35253
35254- return atomic_read(&dev_priv->vbl_received);
35255+ return atomic_read_unchecked(&dev_priv->vbl_received);
35256 }
35257
35258
35259@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35260 /* VBLANK interrupt */
35261 if (status & MGA_VLINEPEN) {
35262 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35263- atomic_inc(&dev_priv->vbl_received);
35264+ atomic_inc_unchecked(&dev_priv->vbl_received);
35265 drm_handle_vblank(dev, 0);
35266 handled = 1;
35267 }
35268@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35269 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35270 MGA_WRITE(MGA_PRIMEND, prim_end);
35271
35272- atomic_inc(&dev_priv->last_fence_retired);
35273+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35274 DRM_WAKEUP(&dev_priv->fence_queue);
35275 handled = 1;
35276 }
35277@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35278 * using fences.
35279 */
35280 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35281- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35282+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35283 - *sequence) <= (1 << 23)));
35284
35285 *sequence = cur_fence;
35286diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35287index 865eddf..62c4cc3 100644
35288--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35289+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35290@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35291 struct bit_table {
35292 const char id;
35293 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35294-};
35295+} __no_const;
35296
35297 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35298
35299diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35300index aa89eb9..d45d38b 100644
35301--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35302+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35303@@ -80,7 +80,7 @@ struct nouveau_drm {
35304 struct drm_global_reference mem_global_ref;
35305 struct ttm_bo_global_ref bo_global_ref;
35306 struct ttm_bo_device bdev;
35307- atomic_t validate_sequence;
35308+ atomic_unchecked_t validate_sequence;
35309 int (*move)(struct nouveau_channel *,
35310 struct ttm_buffer_object *,
35311 struct ttm_mem_reg *, struct ttm_mem_reg *);
35312diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35313index cdb83ac..27f0a16 100644
35314--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35315+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35316@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35317 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35318 struct nouveau_channel *);
35319 u32 (*read)(struct nouveau_channel *);
35320-};
35321+} __no_const;
35322
35323 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35324
35325diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35326index 8bf695c..9fbc90a 100644
35327--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35328+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35329@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35330 int trycnt = 0;
35331 int ret, i;
35332
35333- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35334+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35335 retry:
35336 if (++trycnt > 100000) {
35337 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35338diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35339index 08214bc..9208577 100644
35340--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35341+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35342@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35343 unsigned long arg)
35344 {
35345 unsigned int nr = DRM_IOCTL_NR(cmd);
35346- drm_ioctl_compat_t *fn = NULL;
35347+ drm_ioctl_compat_t fn = NULL;
35348 int ret;
35349
35350 if (nr < DRM_COMMAND_BASE)
35351diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35352index 25d3495..d81aaf6 100644
35353--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35354+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35355@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35356 bool can_switch;
35357
35358 spin_lock(&dev->count_lock);
35359- can_switch = (dev->open_count == 0);
35360+ can_switch = (local_read(&dev->open_count) == 0);
35361 spin_unlock(&dev->count_lock);
35362 return can_switch;
35363 }
35364diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35365index d4660cf..70dbe65 100644
35366--- a/drivers/gpu/drm/r128/r128_cce.c
35367+++ b/drivers/gpu/drm/r128/r128_cce.c
35368@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35369
35370 /* GH: Simple idle check.
35371 */
35372- atomic_set(&dev_priv->idle_count, 0);
35373+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35374
35375 /* We don't support anything other than bus-mastering ring mode,
35376 * but the ring can be in either AGP or PCI space for the ring
35377diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35378index 930c71b..499aded 100644
35379--- a/drivers/gpu/drm/r128/r128_drv.h
35380+++ b/drivers/gpu/drm/r128/r128_drv.h
35381@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35382 int is_pci;
35383 unsigned long cce_buffers_offset;
35384
35385- atomic_t idle_count;
35386+ atomic_unchecked_t idle_count;
35387
35388 int page_flipping;
35389 int current_page;
35390 u32 crtc_offset;
35391 u32 crtc_offset_cntl;
35392
35393- atomic_t vbl_received;
35394+ atomic_unchecked_t vbl_received;
35395
35396 u32 color_fmt;
35397 unsigned int front_offset;
35398diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35399index a954c54..9cc595c 100644
35400--- a/drivers/gpu/drm/r128/r128_ioc32.c
35401+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35402@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35403 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35404 }
35405
35406-drm_ioctl_compat_t *r128_compat_ioctls[] = {
35407+drm_ioctl_compat_t r128_compat_ioctls[] = {
35408 [DRM_R128_INIT] = compat_r128_init,
35409 [DRM_R128_DEPTH] = compat_r128_depth,
35410 [DRM_R128_STIPPLE] = compat_r128_stipple,
35411@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35412 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35413 {
35414 unsigned int nr = DRM_IOCTL_NR(cmd);
35415- drm_ioctl_compat_t *fn = NULL;
35416 int ret;
35417
35418 if (nr < DRM_COMMAND_BASE)
35419 return drm_compat_ioctl(filp, cmd, arg);
35420
35421- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35422- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35423-
35424- if (fn != NULL)
35425+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35426+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35427 ret = (*fn) (filp, cmd, arg);
35428- else
35429+ } else
35430 ret = drm_ioctl(filp, cmd, arg);
35431
35432 return ret;
35433diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35434index 2ea4f09..d391371 100644
35435--- a/drivers/gpu/drm/r128/r128_irq.c
35436+++ b/drivers/gpu/drm/r128/r128_irq.c
35437@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35438 if (crtc != 0)
35439 return 0;
35440
35441- return atomic_read(&dev_priv->vbl_received);
35442+ return atomic_read_unchecked(&dev_priv->vbl_received);
35443 }
35444
35445 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35446@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35447 /* VBLANK interrupt */
35448 if (status & R128_CRTC_VBLANK_INT) {
35449 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35450- atomic_inc(&dev_priv->vbl_received);
35451+ atomic_inc_unchecked(&dev_priv->vbl_received);
35452 drm_handle_vblank(dev, 0);
35453 return IRQ_HANDLED;
35454 }
35455diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35456index 19bb7e6..de7e2a2 100644
35457--- a/drivers/gpu/drm/r128/r128_state.c
35458+++ b/drivers/gpu/drm/r128/r128_state.c
35459@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35460
35461 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35462 {
35463- if (atomic_read(&dev_priv->idle_count) == 0)
35464+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35465 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35466 else
35467- atomic_set(&dev_priv->idle_count, 0);
35468+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35469 }
35470
35471 #endif
35472diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35473index 5a82b6b..9e69c73 100644
35474--- a/drivers/gpu/drm/radeon/mkregtable.c
35475+++ b/drivers/gpu/drm/radeon/mkregtable.c
35476@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35477 regex_t mask_rex;
35478 regmatch_t match[4];
35479 char buf[1024];
35480- size_t end;
35481+ long end;
35482 int len;
35483 int done = 0;
35484 int r;
35485 unsigned o;
35486 struct offset *offset;
35487 char last_reg_s[10];
35488- int last_reg;
35489+ unsigned long last_reg;
35490
35491 if (regcomp
35492 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35493diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35494index 0d6562b..a154330 100644
35495--- a/drivers/gpu/drm/radeon/radeon_device.c
35496+++ b/drivers/gpu/drm/radeon/radeon_device.c
35497@@ -969,7 +969,7 @@ static bool radeon_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/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35507index e7fdf16..f4f6490 100644
35508--- a/drivers/gpu/drm/radeon/radeon_drv.h
35509+++ b/drivers/gpu/drm/radeon/radeon_drv.h
35510@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
35511
35512 /* SW interrupt */
35513 wait_queue_head_t swi_queue;
35514- atomic_t swi_emitted;
35515+ atomic_unchecked_t swi_emitted;
35516 int vblank_crtc;
35517 uint32_t irq_enable_reg;
35518 uint32_t r500_disp_irq_reg;
35519diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35520index c180df8..5fd8186 100644
35521--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35522+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35523@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35524 request = compat_alloc_user_space(sizeof(*request));
35525 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35526 || __put_user(req32.param, &request->param)
35527- || __put_user((void __user *)(unsigned long)req32.value,
35528+ || __put_user((unsigned long)req32.value,
35529 &request->value))
35530 return -EFAULT;
35531
35532@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35533 #define compat_radeon_cp_setparam NULL
35534 #endif /* X86_64 || IA64 */
35535
35536-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35537+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35538 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35539 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35540 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35541@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35542 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35543 {
35544 unsigned int nr = DRM_IOCTL_NR(cmd);
35545- drm_ioctl_compat_t *fn = NULL;
35546 int ret;
35547
35548 if (nr < DRM_COMMAND_BASE)
35549 return drm_compat_ioctl(filp, cmd, arg);
35550
35551- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35552- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35553-
35554- if (fn != NULL)
35555+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35556+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35557 ret = (*fn) (filp, cmd, arg);
35558- else
35559+ } else
35560 ret = drm_ioctl(filp, cmd, arg);
35561
35562 return ret;
35563diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35564index e771033..a0bc6b3 100644
35565--- a/drivers/gpu/drm/radeon/radeon_irq.c
35566+++ b/drivers/gpu/drm/radeon/radeon_irq.c
35567@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
35568 unsigned int ret;
35569 RING_LOCALS;
35570
35571- atomic_inc(&dev_priv->swi_emitted);
35572- ret = atomic_read(&dev_priv->swi_emitted);
35573+ atomic_inc_unchecked(&dev_priv->swi_emitted);
35574+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
35575
35576 BEGIN_RING(4);
35577 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
35578@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
35579 drm_radeon_private_t *dev_priv =
35580 (drm_radeon_private_t *) dev->dev_private;
35581
35582- atomic_set(&dev_priv->swi_emitted, 0);
35583+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
35584 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
35585
35586 dev->max_vblank_count = 0x001fffff;
35587diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
35588index 8e9057b..af6dacb 100644
35589--- a/drivers/gpu/drm/radeon/radeon_state.c
35590+++ b/drivers/gpu/drm/radeon/radeon_state.c
35591@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
35592 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
35593 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
35594
35595- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35596+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35597 sarea_priv->nbox * sizeof(depth_boxes[0])))
35598 return -EFAULT;
35599
35600@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
35601 {
35602 drm_radeon_private_t *dev_priv = dev->dev_private;
35603 drm_radeon_getparam_t *param = data;
35604- int value;
35605+ int value = 0;
35606
35607 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
35608
35609diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
35610index 93f760e..8088227 100644
35611--- a/drivers/gpu/drm/radeon/radeon_ttm.c
35612+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
35613@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
35614 man->size = size >> PAGE_SHIFT;
35615 }
35616
35617-static struct vm_operations_struct radeon_ttm_vm_ops;
35618+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
35619 static const struct vm_operations_struct *ttm_vm_ops = NULL;
35620
35621 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35622@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
35623 }
35624 if (unlikely(ttm_vm_ops == NULL)) {
35625 ttm_vm_ops = vma->vm_ops;
35626+ pax_open_kernel();
35627 radeon_ttm_vm_ops = *ttm_vm_ops;
35628 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
35629+ pax_close_kernel();
35630 }
35631 vma->vm_ops = &radeon_ttm_vm_ops;
35632 return 0;
35633@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
35634 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
35635 else
35636 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
35637- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35638- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35639- radeon_mem_types_list[i].driver_features = 0;
35640+ pax_open_kernel();
35641+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35642+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35643+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35644 if (i == 0)
35645- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35646+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35647 else
35648- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35649-
35650+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35651+ pax_close_kernel();
35652 }
35653 /* Add ttm page pool to debugfs */
35654 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
35655- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35656- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35657- radeon_mem_types_list[i].driver_features = 0;
35658- radeon_mem_types_list[i++].data = NULL;
35659+ pax_open_kernel();
35660+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35661+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35662+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35663+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35664+ pax_close_kernel();
35665 #ifdef CONFIG_SWIOTLB
35666 if (swiotlb_nr_tbl()) {
35667 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
35668- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35669- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35670- radeon_mem_types_list[i].driver_features = 0;
35671- radeon_mem_types_list[i++].data = NULL;
35672+ pax_open_kernel();
35673+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35674+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35675+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35676+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35677+ pax_close_kernel();
35678 }
35679 #endif
35680 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
35681diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
35682index 5706d2a..17aedaa 100644
35683--- a/drivers/gpu/drm/radeon/rs690.c
35684+++ b/drivers/gpu/drm/radeon/rs690.c
35685@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
35686 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
35687 rdev->pm.sideport_bandwidth.full)
35688 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
35689- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
35690+ read_delay_latency.full = dfixed_const(800 * 1000);
35691 read_delay_latency.full = dfixed_div(read_delay_latency,
35692 rdev->pm.igp_sideport_mclk);
35693+ a.full = dfixed_const(370);
35694+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
35695 } else {
35696 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
35697 rdev->pm.k8_bandwidth.full)
35698diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35699index bd2a3b4..122d9ad 100644
35700--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
35701+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35702@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
35703 static int ttm_pool_mm_shrink(struct shrinker *shrink,
35704 struct shrink_control *sc)
35705 {
35706- static atomic_t start_pool = ATOMIC_INIT(0);
35707+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
35708 unsigned i;
35709- unsigned pool_offset = atomic_add_return(1, &start_pool);
35710+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
35711 struct ttm_page_pool *pool;
35712 int shrink_pages = sc->nr_to_scan;
35713
35714diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
35715index 1eb060c..188b1fc 100644
35716--- a/drivers/gpu/drm/udl/udl_fb.c
35717+++ b/drivers/gpu/drm/udl/udl_fb.c
35718@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
35719 fb_deferred_io_cleanup(info);
35720 kfree(info->fbdefio);
35721 info->fbdefio = NULL;
35722- info->fbops->fb_mmap = udl_fb_mmap;
35723 }
35724
35725 pr_warn("released /dev/fb%d user=%d count=%d\n",
35726diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
35727index 893a650..6190d3b 100644
35728--- a/drivers/gpu/drm/via/via_drv.h
35729+++ b/drivers/gpu/drm/via/via_drv.h
35730@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
35731 typedef uint32_t maskarray_t[5];
35732
35733 typedef struct drm_via_irq {
35734- atomic_t irq_received;
35735+ atomic_unchecked_t irq_received;
35736 uint32_t pending_mask;
35737 uint32_t enable_mask;
35738 wait_queue_head_t irq_queue;
35739@@ -75,7 +75,7 @@ typedef struct drm_via_private {
35740 struct timeval last_vblank;
35741 int last_vblank_valid;
35742 unsigned usec_per_vblank;
35743- atomic_t vbl_received;
35744+ atomic_unchecked_t vbl_received;
35745 drm_via_state_t hc_state;
35746 char pci_buf[VIA_PCI_BUF_SIZE];
35747 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
35748diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
35749index ac98964..5dbf512 100644
35750--- a/drivers/gpu/drm/via/via_irq.c
35751+++ b/drivers/gpu/drm/via/via_irq.c
35752@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
35753 if (crtc != 0)
35754 return 0;
35755
35756- return atomic_read(&dev_priv->vbl_received);
35757+ return atomic_read_unchecked(&dev_priv->vbl_received);
35758 }
35759
35760 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35761@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35762
35763 status = VIA_READ(VIA_REG_INTERRUPT);
35764 if (status & VIA_IRQ_VBLANK_PENDING) {
35765- atomic_inc(&dev_priv->vbl_received);
35766- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
35767+ atomic_inc_unchecked(&dev_priv->vbl_received);
35768+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
35769 do_gettimeofday(&cur_vblank);
35770 if (dev_priv->last_vblank_valid) {
35771 dev_priv->usec_per_vblank =
35772@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35773 dev_priv->last_vblank = cur_vblank;
35774 dev_priv->last_vblank_valid = 1;
35775 }
35776- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
35777+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
35778 DRM_DEBUG("US per vblank is: %u\n",
35779 dev_priv->usec_per_vblank);
35780 }
35781@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35782
35783 for (i = 0; i < dev_priv->num_irqs; ++i) {
35784 if (status & cur_irq->pending_mask) {
35785- atomic_inc(&cur_irq->irq_received);
35786+ atomic_inc_unchecked(&cur_irq->irq_received);
35787 DRM_WAKEUP(&cur_irq->irq_queue);
35788 handled = 1;
35789 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
35790@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
35791 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35792 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
35793 masks[irq][4]));
35794- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
35795+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
35796 } else {
35797 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35798 (((cur_irq_sequence =
35799- atomic_read(&cur_irq->irq_received)) -
35800+ atomic_read_unchecked(&cur_irq->irq_received)) -
35801 *sequence) <= (1 << 23)));
35802 }
35803 *sequence = cur_irq_sequence;
35804@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
35805 }
35806
35807 for (i = 0; i < dev_priv->num_irqs; ++i) {
35808- atomic_set(&cur_irq->irq_received, 0);
35809+ atomic_set_unchecked(&cur_irq->irq_received, 0);
35810 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
35811 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
35812 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
35813@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
35814 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
35815 case VIA_IRQ_RELATIVE:
35816 irqwait->request.sequence +=
35817- atomic_read(&cur_irq->irq_received);
35818+ atomic_read_unchecked(&cur_irq->irq_received);
35819 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
35820 case VIA_IRQ_ABSOLUTE:
35821 break;
35822diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35823index 13aeda7..4a952d1 100644
35824--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35825+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35826@@ -290,7 +290,7 @@ struct vmw_private {
35827 * Fencing and IRQs.
35828 */
35829
35830- atomic_t marker_seq;
35831+ atomic_unchecked_t marker_seq;
35832 wait_queue_head_t fence_queue;
35833 wait_queue_head_t fifo_queue;
35834 int fence_queue_waiters; /* Protected by hw_mutex */
35835diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35836index 3eb1486..0a47ee9 100644
35837--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35838+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35839@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
35840 (unsigned int) min,
35841 (unsigned int) fifo->capabilities);
35842
35843- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35844+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35845 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
35846 vmw_marker_queue_init(&fifo->marker_queue);
35847 return vmw_fifo_send_fence(dev_priv, &dummy);
35848@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
35849 if (reserveable)
35850 iowrite32(bytes, fifo_mem +
35851 SVGA_FIFO_RESERVED);
35852- return fifo_mem + (next_cmd >> 2);
35853+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
35854 } else {
35855 need_bounce = true;
35856 }
35857@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35858
35859 fm = vmw_fifo_reserve(dev_priv, bytes);
35860 if (unlikely(fm == NULL)) {
35861- *seqno = atomic_read(&dev_priv->marker_seq);
35862+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35863 ret = -ENOMEM;
35864 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
35865 false, 3*HZ);
35866@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35867 }
35868
35869 do {
35870- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
35871+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
35872 } while (*seqno == 0);
35873
35874 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
35875diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35876index 4640adb..e1384ed 100644
35877--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35878+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35879@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
35880 * emitted. Then the fence is stale and signaled.
35881 */
35882
35883- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
35884+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
35885 > VMW_FENCE_WRAP);
35886
35887 return ret;
35888@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
35889
35890 if (fifo_idle)
35891 down_read(&fifo_state->rwsem);
35892- signal_seq = atomic_read(&dev_priv->marker_seq);
35893+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
35894 ret = 0;
35895
35896 for (;;) {
35897diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35898index 8a8725c..afed796 100644
35899--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35900+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35901@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
35902 while (!vmw_lag_lt(queue, us)) {
35903 spin_lock(&queue->lock);
35904 if (list_empty(&queue->head))
35905- seqno = atomic_read(&dev_priv->marker_seq);
35906+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35907 else {
35908 marker = list_first_entry(&queue->head,
35909 struct vmw_marker, head);
35910diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
35911index ceb3040..6160c5c 100644
35912--- a/drivers/hid/hid-core.c
35913+++ b/drivers/hid/hid-core.c
35914@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
35915
35916 int hid_add_device(struct hid_device *hdev)
35917 {
35918- static atomic_t id = ATOMIC_INIT(0);
35919+ static atomic_unchecked_t id = ATOMIC_INIT(0);
35920 int ret;
35921
35922 if (WARN_ON(hdev->status & HID_STAT_ADDED))
35923@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
35924 /* XXX hack, any other cleaner solution after the driver core
35925 * is converted to allow more than 20 bytes as the device name? */
35926 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
35927- hdev->vendor, hdev->product, atomic_inc_return(&id));
35928+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
35929
35930 hid_debug_register(hdev, dev_name(&hdev->dev));
35931 ret = device_add(&hdev->dev);
35932diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
35933index eec3291..8ed706b 100644
35934--- a/drivers/hid/hid-wiimote-debug.c
35935+++ b/drivers/hid/hid-wiimote-debug.c
35936@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
35937 else if (size == 0)
35938 return -EIO;
35939
35940- if (copy_to_user(u, buf, size))
35941+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
35942 return -EFAULT;
35943
35944 *off += size;
35945diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
35946index 773a2f2..7ce08bc 100644
35947--- a/drivers/hv/channel.c
35948+++ b/drivers/hv/channel.c
35949@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
35950 int ret = 0;
35951 int t;
35952
35953- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
35954- atomic_inc(&vmbus_connection.next_gpadl_handle);
35955+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
35956+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
35957
35958 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
35959 if (ret)
35960diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
35961index 3648f8f..30ef30d 100644
35962--- a/drivers/hv/hv.c
35963+++ b/drivers/hv/hv.c
35964@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
35965 u64 output_address = (output) ? virt_to_phys(output) : 0;
35966 u32 output_address_hi = output_address >> 32;
35967 u32 output_address_lo = output_address & 0xFFFFFFFF;
35968- void *hypercall_page = hv_context.hypercall_page;
35969+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
35970
35971 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
35972 "=a"(hv_status_lo) : "d" (control_hi),
35973diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
35974index d8d1fad..b91caf7 100644
35975--- a/drivers/hv/hyperv_vmbus.h
35976+++ b/drivers/hv/hyperv_vmbus.h
35977@@ -594,7 +594,7 @@ enum vmbus_connect_state {
35978 struct vmbus_connection {
35979 enum vmbus_connect_state conn_state;
35980
35981- atomic_t next_gpadl_handle;
35982+ atomic_unchecked_t next_gpadl_handle;
35983
35984 /*
35985 * Represents channel interrupts. Each bit position represents a
35986diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
35987index 8e1a9ec..4687821 100644
35988--- a/drivers/hv/vmbus_drv.c
35989+++ b/drivers/hv/vmbus_drv.c
35990@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
35991 {
35992 int ret = 0;
35993
35994- static atomic_t device_num = ATOMIC_INIT(0);
35995+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
35996
35997 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
35998- atomic_inc_return(&device_num));
35999+ atomic_inc_return_unchecked(&device_num));
36000
36001 child_device_obj->device.bus = &hv_bus;
36002 child_device_obj->device.parent = &hv_acpi_dev->dev;
36003diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36004index 1672e2a..4a6297c 100644
36005--- a/drivers/hwmon/acpi_power_meter.c
36006+++ b/drivers/hwmon/acpi_power_meter.c
36007@@ -117,7 +117,7 @@ struct sensor_template {
36008 struct device_attribute *devattr,
36009 const char *buf, size_t count);
36010 int index;
36011-};
36012+} __do_const;
36013
36014 /* Averaging interval */
36015 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36016@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36017 struct sensor_template *attrs)
36018 {
36019 struct device *dev = &resource->acpi_dev->dev;
36020- struct sensor_device_attribute *sensors =
36021+ sensor_device_attribute_no_const *sensors =
36022 &resource->sensors[resource->num_sensors];
36023 int res = 0;
36024
36025diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36026index b41baff..4953e4d 100644
36027--- a/drivers/hwmon/applesmc.c
36028+++ b/drivers/hwmon/applesmc.c
36029@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36030 {
36031 struct applesmc_node_group *grp;
36032 struct applesmc_dev_attr *node;
36033- struct attribute *attr;
36034+ attribute_no_const *attr;
36035 int ret, i;
36036
36037 for (grp = groups; grp->format; grp++) {
36038diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36039index 56dbcfb..9874bf1 100644
36040--- a/drivers/hwmon/asus_atk0110.c
36041+++ b/drivers/hwmon/asus_atk0110.c
36042@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36043 struct atk_sensor_data {
36044 struct list_head list;
36045 struct atk_data *data;
36046- struct device_attribute label_attr;
36047- struct device_attribute input_attr;
36048- struct device_attribute limit1_attr;
36049- struct device_attribute limit2_attr;
36050+ device_attribute_no_const label_attr;
36051+ device_attribute_no_const input_attr;
36052+ device_attribute_no_const limit1_attr;
36053+ device_attribute_no_const limit2_attr;
36054 char label_attr_name[ATTR_NAME_SIZE];
36055 char input_attr_name[ATTR_NAME_SIZE];
36056 char limit1_attr_name[ATTR_NAME_SIZE];
36057@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36058 static struct device_attribute atk_name_attr =
36059 __ATTR(name, 0444, atk_name_show, NULL);
36060
36061-static void atk_init_attribute(struct device_attribute *attr, char *name,
36062+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36063 sysfs_show_func show)
36064 {
36065 sysfs_attr_init(&attr->attr);
36066diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36067index d64923d..72591e8 100644
36068--- a/drivers/hwmon/coretemp.c
36069+++ b/drivers/hwmon/coretemp.c
36070@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36071 return NOTIFY_OK;
36072 }
36073
36074-static struct notifier_block coretemp_cpu_notifier __refdata = {
36075+static struct notifier_block coretemp_cpu_notifier = {
36076 .notifier_call = coretemp_cpu_callback,
36077 };
36078
36079diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36080index a14f634..2916ee2 100644
36081--- a/drivers/hwmon/ibmaem.c
36082+++ b/drivers/hwmon/ibmaem.c
36083@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36084 struct aem_rw_sensor_template *rw)
36085 {
36086 struct device *dev = &data->pdev->dev;
36087- struct sensor_device_attribute *sensors = data->sensors;
36088+ sensor_device_attribute_no_const *sensors = data->sensors;
36089 int err;
36090
36091 /* Set up read-only sensors */
36092diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36093index 7d19b1b..8fdaaac 100644
36094--- a/drivers/hwmon/pmbus/pmbus_core.c
36095+++ b/drivers/hwmon/pmbus/pmbus_core.c
36096@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
36097
36098 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
36099 do { \
36100- struct sensor_device_attribute *a \
36101+ sensor_device_attribute_no_const *a \
36102 = &data->_type##s[data->num_##_type##s].attribute; \
36103 BUG_ON(data->num_attributes >= data->max_attributes); \
36104 sysfs_attr_init(&a->dev_attr.attr); \
36105diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36106index 8047fed..1e956f0 100644
36107--- a/drivers/hwmon/sht15.c
36108+++ b/drivers/hwmon/sht15.c
36109@@ -169,7 +169,7 @@ struct sht15_data {
36110 int supply_uV;
36111 bool supply_uV_valid;
36112 struct work_struct update_supply_work;
36113- atomic_t interrupt_handled;
36114+ atomic_unchecked_t interrupt_handled;
36115 };
36116
36117 /**
36118@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
36119 return ret;
36120
36121 gpio_direction_input(data->pdata->gpio_data);
36122- atomic_set(&data->interrupt_handled, 0);
36123+ atomic_set_unchecked(&data->interrupt_handled, 0);
36124
36125 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36126 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36127 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36128 /* Only relevant if the interrupt hasn't occurred. */
36129- if (!atomic_read(&data->interrupt_handled))
36130+ if (!atomic_read_unchecked(&data->interrupt_handled))
36131 schedule_work(&data->read_work);
36132 }
36133 ret = wait_event_timeout(data->wait_queue,
36134@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36135
36136 /* First disable the interrupt */
36137 disable_irq_nosync(irq);
36138- atomic_inc(&data->interrupt_handled);
36139+ atomic_inc_unchecked(&data->interrupt_handled);
36140 /* Then schedule a reading work struct */
36141 if (data->state != SHT15_READING_NOTHING)
36142 schedule_work(&data->read_work);
36143@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36144 * If not, then start the interrupt again - care here as could
36145 * have gone low in meantime so verify it hasn't!
36146 */
36147- atomic_set(&data->interrupt_handled, 0);
36148+ atomic_set_unchecked(&data->interrupt_handled, 0);
36149 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36150 /* If still not occurred or another handler was scheduled */
36151 if (gpio_get_value(data->pdata->gpio_data)
36152- || atomic_read(&data->interrupt_handled))
36153+ || atomic_read_unchecked(&data->interrupt_handled))
36154 return;
36155 }
36156
36157diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36158index 76f157b..9c0db1b 100644
36159--- a/drivers/hwmon/via-cputemp.c
36160+++ b/drivers/hwmon/via-cputemp.c
36161@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36162 return NOTIFY_OK;
36163 }
36164
36165-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36166+static struct notifier_block via_cputemp_cpu_notifier = {
36167 .notifier_call = via_cputemp_cpu_callback,
36168 };
36169
36170diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36171index 378fcb5..5e91fa8 100644
36172--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36173+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36174@@ -43,7 +43,7 @@
36175 extern struct i2c_adapter amd756_smbus;
36176
36177 static struct i2c_adapter *s4882_adapter;
36178-static struct i2c_algorithm *s4882_algo;
36179+static i2c_algorithm_no_const *s4882_algo;
36180
36181 /* Wrapper access functions for multiplexed SMBus */
36182 static DEFINE_MUTEX(amd756_lock);
36183diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36184index 29015eb..af2d8e9 100644
36185--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36186+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36187@@ -41,7 +41,7 @@
36188 extern struct i2c_adapter *nforce2_smbus;
36189
36190 static struct i2c_adapter *s4985_adapter;
36191-static struct i2c_algorithm *s4985_algo;
36192+static i2c_algorithm_no_const *s4985_algo;
36193
36194 /* Wrapper access functions for multiplexed SMBus */
36195 static DEFINE_MUTEX(nforce2_lock);
36196diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36197index 8126824..55a2798 100644
36198--- a/drivers/ide/ide-cd.c
36199+++ b/drivers/ide/ide-cd.c
36200@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36201 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36202 if ((unsigned long)buf & alignment
36203 || blk_rq_bytes(rq) & q->dma_pad_mask
36204- || object_is_on_stack(buf))
36205+ || object_starts_on_stack(buf))
36206 drive->dma = 0;
36207 }
36208 }
36209diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36210index 8848f16..f8e6dd8 100644
36211--- a/drivers/iio/industrialio-core.c
36212+++ b/drivers/iio/industrialio-core.c
36213@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36214 }
36215
36216 static
36217-int __iio_device_attr_init(struct device_attribute *dev_attr,
36218+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36219 const char *postfix,
36220 struct iio_chan_spec const *chan,
36221 ssize_t (*readfunc)(struct device *dev,
36222diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36223index 394fea2..c833880 100644
36224--- a/drivers/infiniband/core/cm.c
36225+++ b/drivers/infiniband/core/cm.c
36226@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36227
36228 struct cm_counter_group {
36229 struct kobject obj;
36230- atomic_long_t counter[CM_ATTR_COUNT];
36231+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36232 };
36233
36234 struct cm_counter_attribute {
36235@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36236 struct ib_mad_send_buf *msg = NULL;
36237 int ret;
36238
36239- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36240+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36241 counter[CM_REQ_COUNTER]);
36242
36243 /* Quick state check to discard duplicate REQs. */
36244@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36245 if (!cm_id_priv)
36246 return;
36247
36248- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36249+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36250 counter[CM_REP_COUNTER]);
36251 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36252 if (ret)
36253@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36254 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36255 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36256 spin_unlock_irq(&cm_id_priv->lock);
36257- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36258+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36259 counter[CM_RTU_COUNTER]);
36260 goto out;
36261 }
36262@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36263 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36264 dreq_msg->local_comm_id);
36265 if (!cm_id_priv) {
36266- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36267+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36268 counter[CM_DREQ_COUNTER]);
36269 cm_issue_drep(work->port, work->mad_recv_wc);
36270 return -EINVAL;
36271@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36272 case IB_CM_MRA_REP_RCVD:
36273 break;
36274 case IB_CM_TIMEWAIT:
36275- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36276+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36277 counter[CM_DREQ_COUNTER]);
36278 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36279 goto unlock;
36280@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36281 cm_free_msg(msg);
36282 goto deref;
36283 case IB_CM_DREQ_RCVD:
36284- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36285+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36286 counter[CM_DREQ_COUNTER]);
36287 goto unlock;
36288 default:
36289@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36290 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36291 cm_id_priv->msg, timeout)) {
36292 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36293- atomic_long_inc(&work->port->
36294+ atomic_long_inc_unchecked(&work->port->
36295 counter_group[CM_RECV_DUPLICATES].
36296 counter[CM_MRA_COUNTER]);
36297 goto out;
36298@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36299 break;
36300 case IB_CM_MRA_REQ_RCVD:
36301 case IB_CM_MRA_REP_RCVD:
36302- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36303+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36304 counter[CM_MRA_COUNTER]);
36305 /* fall through */
36306 default:
36307@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36308 case IB_CM_LAP_IDLE:
36309 break;
36310 case IB_CM_MRA_LAP_SENT:
36311- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36312+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36313 counter[CM_LAP_COUNTER]);
36314 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36315 goto unlock;
36316@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36317 cm_free_msg(msg);
36318 goto deref;
36319 case IB_CM_LAP_RCVD:
36320- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36321+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36322 counter[CM_LAP_COUNTER]);
36323 goto unlock;
36324 default:
36325@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36326 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36327 if (cur_cm_id_priv) {
36328 spin_unlock_irq(&cm.lock);
36329- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36330+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36331 counter[CM_SIDR_REQ_COUNTER]);
36332 goto out; /* Duplicate message. */
36333 }
36334@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36335 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36336 msg->retries = 1;
36337
36338- atomic_long_add(1 + msg->retries,
36339+ atomic_long_add_unchecked(1 + msg->retries,
36340 &port->counter_group[CM_XMIT].counter[attr_index]);
36341 if (msg->retries)
36342- atomic_long_add(msg->retries,
36343+ atomic_long_add_unchecked(msg->retries,
36344 &port->counter_group[CM_XMIT_RETRIES].
36345 counter[attr_index]);
36346
36347@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36348 }
36349
36350 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36351- atomic_long_inc(&port->counter_group[CM_RECV].
36352+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36353 counter[attr_id - CM_ATTR_ID_OFFSET]);
36354
36355 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36356@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36357 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36358
36359 return sprintf(buf, "%ld\n",
36360- atomic_long_read(&group->counter[cm_attr->index]));
36361+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36362 }
36363
36364 static const struct sysfs_ops cm_counter_ops = {
36365diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36366index 176c8f9..2627b62 100644
36367--- a/drivers/infiniband/core/fmr_pool.c
36368+++ b/drivers/infiniband/core/fmr_pool.c
36369@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36370
36371 struct task_struct *thread;
36372
36373- atomic_t req_ser;
36374- atomic_t flush_ser;
36375+ atomic_unchecked_t req_ser;
36376+ atomic_unchecked_t flush_ser;
36377
36378 wait_queue_head_t force_wait;
36379 };
36380@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36381 struct ib_fmr_pool *pool = pool_ptr;
36382
36383 do {
36384- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36385+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36386 ib_fmr_batch_release(pool);
36387
36388- atomic_inc(&pool->flush_ser);
36389+ atomic_inc_unchecked(&pool->flush_ser);
36390 wake_up_interruptible(&pool->force_wait);
36391
36392 if (pool->flush_function)
36393@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36394 }
36395
36396 set_current_state(TASK_INTERRUPTIBLE);
36397- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36398+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36399 !kthread_should_stop())
36400 schedule();
36401 __set_current_state(TASK_RUNNING);
36402@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36403 pool->dirty_watermark = params->dirty_watermark;
36404 pool->dirty_len = 0;
36405 spin_lock_init(&pool->pool_lock);
36406- atomic_set(&pool->req_ser, 0);
36407- atomic_set(&pool->flush_ser, 0);
36408+ atomic_set_unchecked(&pool->req_ser, 0);
36409+ atomic_set_unchecked(&pool->flush_ser, 0);
36410 init_waitqueue_head(&pool->force_wait);
36411
36412 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36413@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36414 }
36415 spin_unlock_irq(&pool->pool_lock);
36416
36417- serial = atomic_inc_return(&pool->req_ser);
36418+ serial = atomic_inc_return_unchecked(&pool->req_ser);
36419 wake_up_process(pool->thread);
36420
36421 if (wait_event_interruptible(pool->force_wait,
36422- atomic_read(&pool->flush_ser) - serial >= 0))
36423+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36424 return -EINTR;
36425
36426 return 0;
36427@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36428 } else {
36429 list_add_tail(&fmr->list, &pool->dirty_list);
36430 if (++pool->dirty_len >= pool->dirty_watermark) {
36431- atomic_inc(&pool->req_ser);
36432+ atomic_inc_unchecked(&pool->req_ser);
36433 wake_up_process(pool->thread);
36434 }
36435 }
36436diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36437index afd8179..598063f 100644
36438--- a/drivers/infiniband/hw/cxgb4/mem.c
36439+++ b/drivers/infiniband/hw/cxgb4/mem.c
36440@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36441 int err;
36442 struct fw_ri_tpte tpt;
36443 u32 stag_idx;
36444- static atomic_t key;
36445+ static atomic_unchecked_t key;
36446
36447 if (c4iw_fatal_error(rdev))
36448 return -EIO;
36449@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36450 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36451 rdev->stats.stag.max = rdev->stats.stag.cur;
36452 mutex_unlock(&rdev->stats.lock);
36453- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36454+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36455 }
36456 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36457 __func__, stag_state, type, pdid, stag_idx);
36458diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36459index 79b3dbc..96e5fcc 100644
36460--- a/drivers/infiniband/hw/ipath/ipath_rc.c
36461+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36462@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36463 struct ib_atomic_eth *ateth;
36464 struct ipath_ack_entry *e;
36465 u64 vaddr;
36466- atomic64_t *maddr;
36467+ atomic64_unchecked_t *maddr;
36468 u64 sdata;
36469 u32 rkey;
36470 u8 next;
36471@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36472 IB_ACCESS_REMOTE_ATOMIC)))
36473 goto nack_acc_unlck;
36474 /* Perform atomic OP and save result. */
36475- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36476+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36477 sdata = be64_to_cpu(ateth->swap_data);
36478 e = &qp->s_ack_queue[qp->r_head_ack_queue];
36479 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
36480- (u64) atomic64_add_return(sdata, maddr) - sdata :
36481+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36482 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36483 be64_to_cpu(ateth->compare_data),
36484 sdata);
36485diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
36486index 1f95bba..9530f87 100644
36487--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
36488+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
36489@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
36490 unsigned long flags;
36491 struct ib_wc wc;
36492 u64 sdata;
36493- atomic64_t *maddr;
36494+ atomic64_unchecked_t *maddr;
36495 enum ib_wc_status send_status;
36496
36497 /*
36498@@ -382,11 +382,11 @@ again:
36499 IB_ACCESS_REMOTE_ATOMIC)))
36500 goto acc_err;
36501 /* Perform atomic OP and save result. */
36502- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36503+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36504 sdata = wqe->wr.wr.atomic.compare_add;
36505 *(u64 *) sqp->s_sge.sge.vaddr =
36506 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
36507- (u64) atomic64_add_return(sdata, maddr) - sdata :
36508+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36509 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36510 sdata, wqe->wr.wr.atomic.swap);
36511 goto send_comp;
36512diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
36513index 9d3e5c1..d9afe4a 100644
36514--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
36515+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
36516@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
36517 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
36518 }
36519
36520-int mthca_QUERY_FW(struct mthca_dev *dev)
36521+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
36522 {
36523 struct mthca_mailbox *mailbox;
36524 u32 *outbox;
36525diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
36526index ed9a989..e0c5871 100644
36527--- a/drivers/infiniband/hw/mthca/mthca_mr.c
36528+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
36529@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
36530 return key;
36531 }
36532
36533-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36534+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36535 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
36536 {
36537 struct mthca_mailbox *mailbox;
36538diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
36539index 5b152a3..c1f3e83 100644
36540--- a/drivers/infiniband/hw/nes/nes.c
36541+++ b/drivers/infiniband/hw/nes/nes.c
36542@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
36543 LIST_HEAD(nes_adapter_list);
36544 static LIST_HEAD(nes_dev_list);
36545
36546-atomic_t qps_destroyed;
36547+atomic_unchecked_t qps_destroyed;
36548
36549 static unsigned int ee_flsh_adapter;
36550 static unsigned int sysfs_nonidx_addr;
36551@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
36552 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
36553 struct nes_adapter *nesadapter = nesdev->nesadapter;
36554
36555- atomic_inc(&qps_destroyed);
36556+ atomic_inc_unchecked(&qps_destroyed);
36557
36558 /* Free the control structures */
36559
36560diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
36561index 33cc589..3bd6538 100644
36562--- a/drivers/infiniband/hw/nes/nes.h
36563+++ b/drivers/infiniband/hw/nes/nes.h
36564@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
36565 extern unsigned int wqm_quanta;
36566 extern struct list_head nes_adapter_list;
36567
36568-extern atomic_t cm_connects;
36569-extern atomic_t cm_accepts;
36570-extern atomic_t cm_disconnects;
36571-extern atomic_t cm_closes;
36572-extern atomic_t cm_connecteds;
36573-extern atomic_t cm_connect_reqs;
36574-extern atomic_t cm_rejects;
36575-extern atomic_t mod_qp_timouts;
36576-extern atomic_t qps_created;
36577-extern atomic_t qps_destroyed;
36578-extern atomic_t sw_qps_destroyed;
36579+extern atomic_unchecked_t cm_connects;
36580+extern atomic_unchecked_t cm_accepts;
36581+extern atomic_unchecked_t cm_disconnects;
36582+extern atomic_unchecked_t cm_closes;
36583+extern atomic_unchecked_t cm_connecteds;
36584+extern atomic_unchecked_t cm_connect_reqs;
36585+extern atomic_unchecked_t cm_rejects;
36586+extern atomic_unchecked_t mod_qp_timouts;
36587+extern atomic_unchecked_t qps_created;
36588+extern atomic_unchecked_t qps_destroyed;
36589+extern atomic_unchecked_t sw_qps_destroyed;
36590 extern u32 mh_detected;
36591 extern u32 mh_pauses_sent;
36592 extern u32 cm_packets_sent;
36593@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
36594 extern u32 cm_packets_received;
36595 extern u32 cm_packets_dropped;
36596 extern u32 cm_packets_retrans;
36597-extern atomic_t cm_listens_created;
36598-extern atomic_t cm_listens_destroyed;
36599+extern atomic_unchecked_t cm_listens_created;
36600+extern atomic_unchecked_t cm_listens_destroyed;
36601 extern u32 cm_backlog_drops;
36602-extern atomic_t cm_loopbacks;
36603-extern atomic_t cm_nodes_created;
36604-extern atomic_t cm_nodes_destroyed;
36605-extern atomic_t cm_accel_dropped_pkts;
36606-extern atomic_t cm_resets_recvd;
36607-extern atomic_t pau_qps_created;
36608-extern atomic_t pau_qps_destroyed;
36609+extern atomic_unchecked_t cm_loopbacks;
36610+extern atomic_unchecked_t cm_nodes_created;
36611+extern atomic_unchecked_t cm_nodes_destroyed;
36612+extern atomic_unchecked_t cm_accel_dropped_pkts;
36613+extern atomic_unchecked_t cm_resets_recvd;
36614+extern atomic_unchecked_t pau_qps_created;
36615+extern atomic_unchecked_t pau_qps_destroyed;
36616
36617 extern u32 int_mod_timer_init;
36618 extern u32 int_mod_cq_depth_256;
36619diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
36620index 22ea67e..dcbe3bc 100644
36621--- a/drivers/infiniband/hw/nes/nes_cm.c
36622+++ b/drivers/infiniband/hw/nes/nes_cm.c
36623@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
36624 u32 cm_packets_retrans;
36625 u32 cm_packets_created;
36626 u32 cm_packets_received;
36627-atomic_t cm_listens_created;
36628-atomic_t cm_listens_destroyed;
36629+atomic_unchecked_t cm_listens_created;
36630+atomic_unchecked_t cm_listens_destroyed;
36631 u32 cm_backlog_drops;
36632-atomic_t cm_loopbacks;
36633-atomic_t cm_nodes_created;
36634-atomic_t cm_nodes_destroyed;
36635-atomic_t cm_accel_dropped_pkts;
36636-atomic_t cm_resets_recvd;
36637+atomic_unchecked_t cm_loopbacks;
36638+atomic_unchecked_t cm_nodes_created;
36639+atomic_unchecked_t cm_nodes_destroyed;
36640+atomic_unchecked_t cm_accel_dropped_pkts;
36641+atomic_unchecked_t cm_resets_recvd;
36642
36643 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
36644 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
36645@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
36646
36647 static struct nes_cm_core *g_cm_core;
36648
36649-atomic_t cm_connects;
36650-atomic_t cm_accepts;
36651-atomic_t cm_disconnects;
36652-atomic_t cm_closes;
36653-atomic_t cm_connecteds;
36654-atomic_t cm_connect_reqs;
36655-atomic_t cm_rejects;
36656+atomic_unchecked_t cm_connects;
36657+atomic_unchecked_t cm_accepts;
36658+atomic_unchecked_t cm_disconnects;
36659+atomic_unchecked_t cm_closes;
36660+atomic_unchecked_t cm_connecteds;
36661+atomic_unchecked_t cm_connect_reqs;
36662+atomic_unchecked_t cm_rejects;
36663
36664 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
36665 {
36666@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
36667 kfree(listener);
36668 listener = NULL;
36669 ret = 0;
36670- atomic_inc(&cm_listens_destroyed);
36671+ atomic_inc_unchecked(&cm_listens_destroyed);
36672 } else {
36673 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
36674 }
36675@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
36676 cm_node->rem_mac);
36677
36678 add_hte_node(cm_core, cm_node);
36679- atomic_inc(&cm_nodes_created);
36680+ atomic_inc_unchecked(&cm_nodes_created);
36681
36682 return cm_node;
36683 }
36684@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
36685 }
36686
36687 atomic_dec(&cm_core->node_cnt);
36688- atomic_inc(&cm_nodes_destroyed);
36689+ atomic_inc_unchecked(&cm_nodes_destroyed);
36690 nesqp = cm_node->nesqp;
36691 if (nesqp) {
36692 nesqp->cm_node = NULL;
36693@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
36694
36695 static void drop_packet(struct sk_buff *skb)
36696 {
36697- atomic_inc(&cm_accel_dropped_pkts);
36698+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36699 dev_kfree_skb_any(skb);
36700 }
36701
36702@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
36703 {
36704
36705 int reset = 0; /* whether to send reset in case of err.. */
36706- atomic_inc(&cm_resets_recvd);
36707+ atomic_inc_unchecked(&cm_resets_recvd);
36708 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
36709 " refcnt=%d\n", cm_node, cm_node->state,
36710 atomic_read(&cm_node->ref_count));
36711@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
36712 rem_ref_cm_node(cm_node->cm_core, cm_node);
36713 return NULL;
36714 }
36715- atomic_inc(&cm_loopbacks);
36716+ atomic_inc_unchecked(&cm_loopbacks);
36717 loopbackremotenode->loopbackpartner = cm_node;
36718 loopbackremotenode->tcp_cntxt.rcv_wscale =
36719 NES_CM_DEFAULT_RCV_WND_SCALE;
36720@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
36721 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
36722 else {
36723 rem_ref_cm_node(cm_core, cm_node);
36724- atomic_inc(&cm_accel_dropped_pkts);
36725+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36726 dev_kfree_skb_any(skb);
36727 }
36728 break;
36729@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36730
36731 if ((cm_id) && (cm_id->event_handler)) {
36732 if (issue_disconn) {
36733- atomic_inc(&cm_disconnects);
36734+ atomic_inc_unchecked(&cm_disconnects);
36735 cm_event.event = IW_CM_EVENT_DISCONNECT;
36736 cm_event.status = disconn_status;
36737 cm_event.local_addr = cm_id->local_addr;
36738@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36739 }
36740
36741 if (issue_close) {
36742- atomic_inc(&cm_closes);
36743+ atomic_inc_unchecked(&cm_closes);
36744 nes_disconnect(nesqp, 1);
36745
36746 cm_id->provider_data = nesqp;
36747@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36748
36749 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
36750 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
36751- atomic_inc(&cm_accepts);
36752+ atomic_inc_unchecked(&cm_accepts);
36753
36754 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
36755 netdev_refcnt_read(nesvnic->netdev));
36756@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
36757 struct nes_cm_core *cm_core;
36758 u8 *start_buff;
36759
36760- atomic_inc(&cm_rejects);
36761+ atomic_inc_unchecked(&cm_rejects);
36762 cm_node = (struct nes_cm_node *)cm_id->provider_data;
36763 loopback = cm_node->loopbackpartner;
36764 cm_core = cm_node->cm_core;
36765@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36766 ntohl(cm_id->local_addr.sin_addr.s_addr),
36767 ntohs(cm_id->local_addr.sin_port));
36768
36769- atomic_inc(&cm_connects);
36770+ atomic_inc_unchecked(&cm_connects);
36771 nesqp->active_conn = 1;
36772
36773 /* cache the cm_id in the qp */
36774@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
36775 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
36776 return err;
36777 }
36778- atomic_inc(&cm_listens_created);
36779+ atomic_inc_unchecked(&cm_listens_created);
36780 }
36781
36782 cm_id->add_ref(cm_id);
36783@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
36784
36785 if (nesqp->destroyed)
36786 return;
36787- atomic_inc(&cm_connecteds);
36788+ atomic_inc_unchecked(&cm_connecteds);
36789 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
36790 " local port 0x%04X. jiffies = %lu.\n",
36791 nesqp->hwqp.qp_id,
36792@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
36793
36794 cm_id->add_ref(cm_id);
36795 ret = cm_id->event_handler(cm_id, &cm_event);
36796- atomic_inc(&cm_closes);
36797+ atomic_inc_unchecked(&cm_closes);
36798 cm_event.event = IW_CM_EVENT_CLOSE;
36799 cm_event.status = 0;
36800 cm_event.provider_data = cm_id->provider_data;
36801@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
36802 return;
36803 cm_id = cm_node->cm_id;
36804
36805- atomic_inc(&cm_connect_reqs);
36806+ atomic_inc_unchecked(&cm_connect_reqs);
36807 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36808 cm_node, cm_id, jiffies);
36809
36810@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
36811 return;
36812 cm_id = cm_node->cm_id;
36813
36814- atomic_inc(&cm_connect_reqs);
36815+ atomic_inc_unchecked(&cm_connect_reqs);
36816 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36817 cm_node, cm_id, jiffies);
36818
36819diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
36820index 4166452..fc952c3 100644
36821--- a/drivers/infiniband/hw/nes/nes_mgt.c
36822+++ b/drivers/infiniband/hw/nes/nes_mgt.c
36823@@ -40,8 +40,8 @@
36824 #include "nes.h"
36825 #include "nes_mgt.h"
36826
36827-atomic_t pau_qps_created;
36828-atomic_t pau_qps_destroyed;
36829+atomic_unchecked_t pau_qps_created;
36830+atomic_unchecked_t pau_qps_destroyed;
36831
36832 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
36833 {
36834@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
36835 {
36836 struct sk_buff *skb;
36837 unsigned long flags;
36838- atomic_inc(&pau_qps_destroyed);
36839+ atomic_inc_unchecked(&pau_qps_destroyed);
36840
36841 /* Free packets that have not yet been forwarded */
36842 /* Lock is acquired by skb_dequeue when removing the skb */
36843@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
36844 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
36845 skb_queue_head_init(&nesqp->pau_list);
36846 spin_lock_init(&nesqp->pau_lock);
36847- atomic_inc(&pau_qps_created);
36848+ atomic_inc_unchecked(&pau_qps_created);
36849 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
36850 }
36851
36852diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
36853index 9542e16..a008c40 100644
36854--- a/drivers/infiniband/hw/nes/nes_nic.c
36855+++ b/drivers/infiniband/hw/nes/nes_nic.c
36856@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
36857 target_stat_values[++index] = mh_detected;
36858 target_stat_values[++index] = mh_pauses_sent;
36859 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
36860- target_stat_values[++index] = atomic_read(&cm_connects);
36861- target_stat_values[++index] = atomic_read(&cm_accepts);
36862- target_stat_values[++index] = atomic_read(&cm_disconnects);
36863- target_stat_values[++index] = atomic_read(&cm_connecteds);
36864- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
36865- target_stat_values[++index] = atomic_read(&cm_rejects);
36866- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
36867- target_stat_values[++index] = atomic_read(&qps_created);
36868- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
36869- target_stat_values[++index] = atomic_read(&qps_destroyed);
36870- target_stat_values[++index] = atomic_read(&cm_closes);
36871+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
36872+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
36873+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
36874+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
36875+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
36876+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
36877+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
36878+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
36879+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
36880+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
36881+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
36882 target_stat_values[++index] = cm_packets_sent;
36883 target_stat_values[++index] = cm_packets_bounced;
36884 target_stat_values[++index] = cm_packets_created;
36885 target_stat_values[++index] = cm_packets_received;
36886 target_stat_values[++index] = cm_packets_dropped;
36887 target_stat_values[++index] = cm_packets_retrans;
36888- target_stat_values[++index] = atomic_read(&cm_listens_created);
36889- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
36890+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
36891+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
36892 target_stat_values[++index] = cm_backlog_drops;
36893- target_stat_values[++index] = atomic_read(&cm_loopbacks);
36894- target_stat_values[++index] = atomic_read(&cm_nodes_created);
36895- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
36896- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
36897- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
36898+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
36899+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
36900+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
36901+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
36902+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
36903 target_stat_values[++index] = nesadapter->free_4kpbl;
36904 target_stat_values[++index] = nesadapter->free_256pbl;
36905 target_stat_values[++index] = int_mod_timer_init;
36906 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
36907 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
36908 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
36909- target_stat_values[++index] = atomic_read(&pau_qps_created);
36910- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
36911+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
36912+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
36913 }
36914
36915 /**
36916diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
36917index 07e4fba..685f041 100644
36918--- a/drivers/infiniband/hw/nes/nes_verbs.c
36919+++ b/drivers/infiniband/hw/nes/nes_verbs.c
36920@@ -46,9 +46,9 @@
36921
36922 #include <rdma/ib_umem.h>
36923
36924-atomic_t mod_qp_timouts;
36925-atomic_t qps_created;
36926-atomic_t sw_qps_destroyed;
36927+atomic_unchecked_t mod_qp_timouts;
36928+atomic_unchecked_t qps_created;
36929+atomic_unchecked_t sw_qps_destroyed;
36930
36931 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
36932
36933@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
36934 if (init_attr->create_flags)
36935 return ERR_PTR(-EINVAL);
36936
36937- atomic_inc(&qps_created);
36938+ atomic_inc_unchecked(&qps_created);
36939 switch (init_attr->qp_type) {
36940 case IB_QPT_RC:
36941 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
36942@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
36943 struct iw_cm_event cm_event;
36944 int ret = 0;
36945
36946- atomic_inc(&sw_qps_destroyed);
36947+ atomic_inc_unchecked(&sw_qps_destroyed);
36948 nesqp->destroyed = 1;
36949
36950 /* Blow away the connection if it exists. */
36951diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
36952index 4d11575..3e890e5 100644
36953--- a/drivers/infiniband/hw/qib/qib.h
36954+++ b/drivers/infiniband/hw/qib/qib.h
36955@@ -51,6 +51,7 @@
36956 #include <linux/completion.h>
36957 #include <linux/kref.h>
36958 #include <linux/sched.h>
36959+#include <linux/slab.h>
36960
36961 #include "qib_common.h"
36962 #include "qib_verbs.h"
36963diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
36964index da739d9..da1c7f4 100644
36965--- a/drivers/input/gameport/gameport.c
36966+++ b/drivers/input/gameport/gameport.c
36967@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
36968 */
36969 static void gameport_init_port(struct gameport *gameport)
36970 {
36971- static atomic_t gameport_no = ATOMIC_INIT(0);
36972+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
36973
36974 __module_get(THIS_MODULE);
36975
36976 mutex_init(&gameport->drv_mutex);
36977 device_initialize(&gameport->dev);
36978 dev_set_name(&gameport->dev, "gameport%lu",
36979- (unsigned long)atomic_inc_return(&gameport_no) - 1);
36980+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
36981 gameport->dev.bus = &gameport_bus;
36982 gameport->dev.release = gameport_release_port;
36983 if (gameport->parent)
36984diff --git a/drivers/input/input.c b/drivers/input/input.c
36985index c044699..174d71a 100644
36986--- a/drivers/input/input.c
36987+++ b/drivers/input/input.c
36988@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
36989 */
36990 int input_register_device(struct input_dev *dev)
36991 {
36992- static atomic_t input_no = ATOMIC_INIT(0);
36993+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
36994 struct input_devres *devres = NULL;
36995 struct input_handler *handler;
36996 unsigned int packet_size;
36997@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
36998 dev->setkeycode = input_default_setkeycode;
36999
37000 dev_set_name(&dev->dev, "input%ld",
37001- (unsigned long) atomic_inc_return(&input_no) - 1);
37002+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37003
37004 error = device_add(&dev->dev);
37005 if (error)
37006diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37007index 04c69af..5f92d00 100644
37008--- a/drivers/input/joystick/sidewinder.c
37009+++ b/drivers/input/joystick/sidewinder.c
37010@@ -30,6 +30,7 @@
37011 #include <linux/kernel.h>
37012 #include <linux/module.h>
37013 #include <linux/slab.h>
37014+#include <linux/sched.h>
37015 #include <linux/init.h>
37016 #include <linux/input.h>
37017 #include <linux/gameport.h>
37018diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37019index d6cbfe9..6225402 100644
37020--- a/drivers/input/joystick/xpad.c
37021+++ b/drivers/input/joystick/xpad.c
37022@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37023
37024 static int xpad_led_probe(struct usb_xpad *xpad)
37025 {
37026- static atomic_t led_seq = ATOMIC_INIT(0);
37027+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37028 long led_no;
37029 struct xpad_led *led;
37030 struct led_classdev *led_cdev;
37031@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37032 if (!led)
37033 return -ENOMEM;
37034
37035- led_no = (long)atomic_inc_return(&led_seq) - 1;
37036+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37037
37038 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37039 led->xpad = xpad;
37040diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37041index fe1df23..5b710f3 100644
37042--- a/drivers/input/mouse/psmouse.h
37043+++ b/drivers/input/mouse/psmouse.h
37044@@ -115,7 +115,7 @@ struct psmouse_attribute {
37045 ssize_t (*set)(struct psmouse *psmouse, void *data,
37046 const char *buf, size_t count);
37047 bool protect;
37048-};
37049+} __do_const;
37050 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37051
37052 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37053diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37054index 4c842c3..590b0bf 100644
37055--- a/drivers/input/mousedev.c
37056+++ b/drivers/input/mousedev.c
37057@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37058
37059 spin_unlock_irq(&client->packet_lock);
37060
37061- if (copy_to_user(buffer, data, count))
37062+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37063 return -EFAULT;
37064
37065 return count;
37066diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37067index 25fc597..558bf3b 100644
37068--- a/drivers/input/serio/serio.c
37069+++ b/drivers/input/serio/serio.c
37070@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37071 */
37072 static void serio_init_port(struct serio *serio)
37073 {
37074- static atomic_t serio_no = ATOMIC_INIT(0);
37075+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37076
37077 __module_get(THIS_MODULE);
37078
37079@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37080 mutex_init(&serio->drv_mutex);
37081 device_initialize(&serio->dev);
37082 dev_set_name(&serio->dev, "serio%ld",
37083- (long)atomic_inc_return(&serio_no) - 1);
37084+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37085 serio->dev.bus = &serio_bus;
37086 serio->dev.release = serio_release_port;
37087 serio->dev.groups = serio_device_attr_groups;
37088diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37089index ddbdaca..be18a78 100644
37090--- a/drivers/iommu/iommu.c
37091+++ b/drivers/iommu/iommu.c
37092@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37093 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37094 {
37095 bus_register_notifier(bus, &iommu_bus_nb);
37096- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37097+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37098 }
37099
37100 /**
37101diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37102index 89562a8..218999b 100644
37103--- a/drivers/isdn/capi/capi.c
37104+++ b/drivers/isdn/capi/capi.c
37105@@ -81,8 +81,8 @@ struct capiminor {
37106
37107 struct capi20_appl *ap;
37108 u32 ncci;
37109- atomic_t datahandle;
37110- atomic_t msgid;
37111+ atomic_unchecked_t datahandle;
37112+ atomic_unchecked_t msgid;
37113
37114 struct tty_port port;
37115 int ttyinstop;
37116@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37117 capimsg_setu16(s, 2, mp->ap->applid);
37118 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37119 capimsg_setu8 (s, 5, CAPI_RESP);
37120- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37121+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37122 capimsg_setu32(s, 8, mp->ncci);
37123 capimsg_setu16(s, 12, datahandle);
37124 }
37125@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37126 mp->outbytes -= len;
37127 spin_unlock_bh(&mp->outlock);
37128
37129- datahandle = atomic_inc_return(&mp->datahandle);
37130+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37131 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37132 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37133 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37134 capimsg_setu16(skb->data, 2, mp->ap->applid);
37135 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37136 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37137- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37138+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37139 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37140 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37141 capimsg_setu16(skb->data, 16, len); /* Data length */
37142diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37143index 67abf3f..076b3a6 100644
37144--- a/drivers/isdn/gigaset/interface.c
37145+++ b/drivers/isdn/gigaset/interface.c
37146@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37147 }
37148 tty->driver_data = cs;
37149
37150- ++cs->port.count;
37151+ atomic_inc(&cs->port.count);
37152
37153- if (cs->port.count == 1) {
37154+ if (atomic_read(&cs->port.count) == 1) {
37155 tty_port_tty_set(&cs->port, tty);
37156 tty->low_latency = 1;
37157 }
37158@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37159
37160 if (!cs->connected)
37161 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37162- else if (!cs->port.count)
37163+ else if (!atomic_read(&cs->port.count))
37164 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37165- else if (!--cs->port.count)
37166+ else if (!atomic_dec_return(&cs->port.count))
37167 tty_port_tty_set(&cs->port, NULL);
37168
37169 mutex_unlock(&cs->mutex);
37170diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37171index 821f7ac..28d4030 100644
37172--- a/drivers/isdn/hardware/avm/b1.c
37173+++ b/drivers/isdn/hardware/avm/b1.c
37174@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37175 }
37176 if (left) {
37177 if (t4file->user) {
37178- if (copy_from_user(buf, dp, left))
37179+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37180 return -EFAULT;
37181 } else {
37182 memcpy(buf, dp, left);
37183@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37184 }
37185 if (left) {
37186 if (config->user) {
37187- if (copy_from_user(buf, dp, left))
37188+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37189 return -EFAULT;
37190 } else {
37191 memcpy(buf, dp, left);
37192diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37193index e09dc8a..15e2efb 100644
37194--- a/drivers/isdn/i4l/isdn_tty.c
37195+++ b/drivers/isdn/i4l/isdn_tty.c
37196@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37197
37198 #ifdef ISDN_DEBUG_MODEM_OPEN
37199 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37200- port->count);
37201+ atomic_read(&port->count));
37202 #endif
37203- port->count++;
37204+ atomic_inc(&port->count);
37205 port->tty = tty;
37206 /*
37207 * Start up serial port
37208@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37209 #endif
37210 return;
37211 }
37212- if ((tty->count == 1) && (port->count != 1)) {
37213+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37214 /*
37215 * Uh, oh. tty->count is 1, which means that the tty
37216 * structure will be freed. Info->count should always
37217@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37218 * serial port won't be shutdown.
37219 */
37220 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37221- "info->count is %d\n", port->count);
37222- port->count = 1;
37223+ "info->count is %d\n", atomic_read(&port->count));
37224+ atomic_set(&port->count, 1);
37225 }
37226- if (--port->count < 0) {
37227+ if (atomic_dec_return(&port->count) < 0) {
37228 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37229- info->line, port->count);
37230- port->count = 0;
37231+ info->line, atomic_read(&port->count));
37232+ atomic_set(&port->count, 0);
37233 }
37234- if (port->count) {
37235+ if (atomic_read(&port->count)) {
37236 #ifdef ISDN_DEBUG_MODEM_OPEN
37237 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37238 #endif
37239@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37240 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37241 return;
37242 isdn_tty_shutdown(info);
37243- port->count = 0;
37244+ atomic_set(&port->count, 0);
37245 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37246 port->tty = NULL;
37247 wake_up_interruptible(&port->open_wait);
37248@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37249 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37250 modem_info *info = &dev->mdm.info[i];
37251
37252- if (info->port.count == 0)
37253+ if (atomic_read(&info->port.count) == 0)
37254 continue;
37255 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37256 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37257diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37258index e74df7c..03a03ba 100644
37259--- a/drivers/isdn/icn/icn.c
37260+++ b/drivers/isdn/icn/icn.c
37261@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37262 if (count > len)
37263 count = len;
37264 if (user) {
37265- if (copy_from_user(msg, buf, count))
37266+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37267 return -EFAULT;
37268 } else
37269 memcpy(msg, buf, count);
37270diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37271index 6a8405d..0bd1c7e 100644
37272--- a/drivers/leds/leds-clevo-mail.c
37273+++ b/drivers/leds/leds-clevo-mail.c
37274@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37275 * detected as working, but in reality it is not) as low as
37276 * possible.
37277 */
37278-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37279+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37280 {
37281 .callback = clevo_mail_led_dmi_callback,
37282 .ident = "Clevo D410J",
37283diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37284index ec9b287..65c9bf4 100644
37285--- a/drivers/leds/leds-ss4200.c
37286+++ b/drivers/leds/leds-ss4200.c
37287@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37288 * detected as working, but in reality it is not) as low as
37289 * possible.
37290 */
37291-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37292+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37293 {
37294 .callback = ss4200_led_dmi_callback,
37295 .ident = "Intel SS4200-E",
37296diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37297index a5ebc00..982886f 100644
37298--- a/drivers/lguest/core.c
37299+++ b/drivers/lguest/core.c
37300@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37301 * it's worked so far. The end address needs +1 because __get_vm_area
37302 * allocates an extra guard page, so we need space for that.
37303 */
37304+
37305+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37306+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37307+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37308+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37309+#else
37310 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37311 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37312 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37313+#endif
37314+
37315 if (!switcher_vma) {
37316 err = -ENOMEM;
37317 printk("lguest: could not map switcher pages high\n");
37318@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37319 * Now the Switcher is mapped at the right address, we can't fail!
37320 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37321 */
37322- memcpy(switcher_vma->addr, start_switcher_text,
37323+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37324 end_switcher_text - start_switcher_text);
37325
37326 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37327diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37328index 3b62be16..e33134a 100644
37329--- a/drivers/lguest/page_tables.c
37330+++ b/drivers/lguest/page_tables.c
37331@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37332 /*:*/
37333
37334 #ifdef CONFIG_X86_PAE
37335-static void release_pmd(pmd_t *spmd)
37336+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37337 {
37338 /* If the entry's not present, there's nothing to release. */
37339 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37340diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37341index 4af12e1..0e89afe 100644
37342--- a/drivers/lguest/x86/core.c
37343+++ b/drivers/lguest/x86/core.c
37344@@ -59,7 +59,7 @@ static struct {
37345 /* Offset from where switcher.S was compiled to where we've copied it */
37346 static unsigned long switcher_offset(void)
37347 {
37348- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37349+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37350 }
37351
37352 /* This cpu's struct lguest_pages. */
37353@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37354 * These copies are pretty cheap, so we do them unconditionally: */
37355 /* Save the current Host top-level page directory.
37356 */
37357+
37358+#ifdef CONFIG_PAX_PER_CPU_PGD
37359+ pages->state.host_cr3 = read_cr3();
37360+#else
37361 pages->state.host_cr3 = __pa(current->mm->pgd);
37362+#endif
37363+
37364 /*
37365 * Set up the Guest's page tables to see this CPU's pages (and no
37366 * other CPU's pages).
37367@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37368 * compiled-in switcher code and the high-mapped copy we just made.
37369 */
37370 for (i = 0; i < IDT_ENTRIES; i++)
37371- default_idt_entries[i] += switcher_offset();
37372+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37373
37374 /*
37375 * Set up the Switcher's per-cpu areas.
37376@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37377 * it will be undisturbed when we switch. To change %cs and jump we
37378 * need this structure to feed to Intel's "lcall" instruction.
37379 */
37380- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37381+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37382 lguest_entry.segment = LGUEST_CS;
37383
37384 /*
37385diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37386index 40634b0..4f5855e 100644
37387--- a/drivers/lguest/x86/switcher_32.S
37388+++ b/drivers/lguest/x86/switcher_32.S
37389@@ -87,6 +87,7 @@
37390 #include <asm/page.h>
37391 #include <asm/segment.h>
37392 #include <asm/lguest.h>
37393+#include <asm/processor-flags.h>
37394
37395 // We mark the start of the code to copy
37396 // It's placed in .text tho it's never run here
37397@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37398 // Changes type when we load it: damn Intel!
37399 // For after we switch over our page tables
37400 // That entry will be read-only: we'd crash.
37401+
37402+#ifdef CONFIG_PAX_KERNEXEC
37403+ mov %cr0, %edx
37404+ xor $X86_CR0_WP, %edx
37405+ mov %edx, %cr0
37406+#endif
37407+
37408 movl $(GDT_ENTRY_TSS*8), %edx
37409 ltr %dx
37410
37411@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37412 // Let's clear it again for our return.
37413 // The GDT descriptor of the Host
37414 // Points to the table after two "size" bytes
37415- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37416+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37417 // Clear "used" from type field (byte 5, bit 2)
37418- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37419+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37420+
37421+#ifdef CONFIG_PAX_KERNEXEC
37422+ mov %cr0, %eax
37423+ xor $X86_CR0_WP, %eax
37424+ mov %eax, %cr0
37425+#endif
37426
37427 // Once our page table's switched, the Guest is live!
37428 // The Host fades as we run this final step.
37429@@ -295,13 +309,12 @@ deliver_to_host:
37430 // I consulted gcc, and it gave
37431 // These instructions, which I gladly credit:
37432 leal (%edx,%ebx,8), %eax
37433- movzwl (%eax),%edx
37434- movl 4(%eax), %eax
37435- xorw %ax, %ax
37436- orl %eax, %edx
37437+ movl 4(%eax), %edx
37438+ movw (%eax), %dx
37439 // Now the address of the handler's in %edx
37440 // We call it now: its "iret" drops us home.
37441- jmp *%edx
37442+ ljmp $__KERNEL_CS, $1f
37443+1: jmp *%edx
37444
37445 // Every interrupt can come to us here
37446 // But we must truly tell each apart.
37447diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
37448index 7155945..4bcc562 100644
37449--- a/drivers/md/bitmap.c
37450+++ b/drivers/md/bitmap.c
37451@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
37452 chunk_kb ? "KB" : "B");
37453 if (bitmap->storage.file) {
37454 seq_printf(seq, ", file: ");
37455- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
37456+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
37457 }
37458
37459 seq_printf(seq, "\n");
37460diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
37461index eee353d..74504c4 100644
37462--- a/drivers/md/dm-ioctl.c
37463+++ b/drivers/md/dm-ioctl.c
37464@@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
37465 cmd == DM_LIST_VERSIONS_CMD)
37466 return 0;
37467
37468- if ((cmd == DM_DEV_CREATE_CMD)) {
37469+ if (cmd == DM_DEV_CREATE_CMD) {
37470 if (!*param->name) {
37471 DMWARN("name not supplied when creating device");
37472 return -EINVAL;
37473diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
37474index 7f24190..0e18099 100644
37475--- a/drivers/md/dm-raid1.c
37476+++ b/drivers/md/dm-raid1.c
37477@@ -40,7 +40,7 @@ enum dm_raid1_error {
37478
37479 struct mirror {
37480 struct mirror_set *ms;
37481- atomic_t error_count;
37482+ atomic_unchecked_t error_count;
37483 unsigned long error_type;
37484 struct dm_dev *dev;
37485 sector_t offset;
37486@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
37487 struct mirror *m;
37488
37489 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
37490- if (!atomic_read(&m->error_count))
37491+ if (!atomic_read_unchecked(&m->error_count))
37492 return m;
37493
37494 return NULL;
37495@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
37496 * simple way to tell if a device has encountered
37497 * errors.
37498 */
37499- atomic_inc(&m->error_count);
37500+ atomic_inc_unchecked(&m->error_count);
37501
37502 if (test_and_set_bit(error_type, &m->error_type))
37503 return;
37504@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
37505 struct mirror *m = get_default_mirror(ms);
37506
37507 do {
37508- if (likely(!atomic_read(&m->error_count)))
37509+ if (likely(!atomic_read_unchecked(&m->error_count)))
37510 return m;
37511
37512 if (m-- == ms->mirror)
37513@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
37514 {
37515 struct mirror *default_mirror = get_default_mirror(m->ms);
37516
37517- return !atomic_read(&default_mirror->error_count);
37518+ return !atomic_read_unchecked(&default_mirror->error_count);
37519 }
37520
37521 static int mirror_available(struct mirror_set *ms, struct bio *bio)
37522@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
37523 */
37524 if (likely(region_in_sync(ms, region, 1)))
37525 m = choose_mirror(ms, bio->bi_sector);
37526- else if (m && atomic_read(&m->error_count))
37527+ else if (m && atomic_read_unchecked(&m->error_count))
37528 m = NULL;
37529
37530 if (likely(m))
37531@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
37532 }
37533
37534 ms->mirror[mirror].ms = ms;
37535- atomic_set(&(ms->mirror[mirror].error_count), 0);
37536+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
37537 ms->mirror[mirror].error_type = 0;
37538 ms->mirror[mirror].offset = offset;
37539
37540@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
37541 */
37542 static char device_status_char(struct mirror *m)
37543 {
37544- if (!atomic_read(&(m->error_count)))
37545+ if (!atomic_read_unchecked(&(m->error_count)))
37546 return 'A';
37547
37548 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
37549diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
37550index aaecefa..23b3026 100644
37551--- a/drivers/md/dm-stripe.c
37552+++ b/drivers/md/dm-stripe.c
37553@@ -20,7 +20,7 @@ struct stripe {
37554 struct dm_dev *dev;
37555 sector_t physical_start;
37556
37557- atomic_t error_count;
37558+ atomic_unchecked_t error_count;
37559 };
37560
37561 struct stripe_c {
37562@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
37563 kfree(sc);
37564 return r;
37565 }
37566- atomic_set(&(sc->stripe[i].error_count), 0);
37567+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
37568 }
37569
37570 ti->private = sc;
37571@@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
37572 DMEMIT("%d ", sc->stripes);
37573 for (i = 0; i < sc->stripes; i++) {
37574 DMEMIT("%s ", sc->stripe[i].dev->name);
37575- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
37576+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
37577 'D' : 'A';
37578 }
37579 buffer[i] = '\0';
37580@@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
37581 */
37582 for (i = 0; i < sc->stripes; i++)
37583 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
37584- atomic_inc(&(sc->stripe[i].error_count));
37585- if (atomic_read(&(sc->stripe[i].error_count)) <
37586+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
37587+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
37588 DM_IO_ERROR_THRESHOLD)
37589 schedule_work(&sc->trigger_event);
37590 }
37591diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
37592index daf25d0..d74f49f 100644
37593--- a/drivers/md/dm-table.c
37594+++ b/drivers/md/dm-table.c
37595@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
37596 if (!dev_size)
37597 return 0;
37598
37599- if ((start >= dev_size) || (start + len > dev_size)) {
37600+ if ((start >= dev_size) || (len > dev_size - start)) {
37601 DMWARN("%s: %s too small for target: "
37602 "start=%llu, len=%llu, dev_size=%llu",
37603 dm_device_name(ti->table->md), bdevname(bdev, b),
37604diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
37605index 4d6e853..a234157 100644
37606--- a/drivers/md/dm-thin-metadata.c
37607+++ b/drivers/md/dm-thin-metadata.c
37608@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37609 {
37610 pmd->info.tm = pmd->tm;
37611 pmd->info.levels = 2;
37612- pmd->info.value_type.context = pmd->data_sm;
37613+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37614 pmd->info.value_type.size = sizeof(__le64);
37615 pmd->info.value_type.inc = data_block_inc;
37616 pmd->info.value_type.dec = data_block_dec;
37617@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37618
37619 pmd->bl_info.tm = pmd->tm;
37620 pmd->bl_info.levels = 1;
37621- pmd->bl_info.value_type.context = pmd->data_sm;
37622+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37623 pmd->bl_info.value_type.size = sizeof(__le64);
37624 pmd->bl_info.value_type.inc = data_block_inc;
37625 pmd->bl_info.value_type.dec = data_block_dec;
37626diff --git a/drivers/md/dm.c b/drivers/md/dm.c
37627index 0d8f086..f5a91d5 100644
37628--- a/drivers/md/dm.c
37629+++ b/drivers/md/dm.c
37630@@ -170,9 +170,9 @@ struct mapped_device {
37631 /*
37632 * Event handling.
37633 */
37634- atomic_t event_nr;
37635+ atomic_unchecked_t event_nr;
37636 wait_queue_head_t eventq;
37637- atomic_t uevent_seq;
37638+ atomic_unchecked_t uevent_seq;
37639 struct list_head uevent_list;
37640 spinlock_t uevent_lock; /* Protect access to uevent_list */
37641
37642@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
37643 rwlock_init(&md->map_lock);
37644 atomic_set(&md->holders, 1);
37645 atomic_set(&md->open_count, 0);
37646- atomic_set(&md->event_nr, 0);
37647- atomic_set(&md->uevent_seq, 0);
37648+ atomic_set_unchecked(&md->event_nr, 0);
37649+ atomic_set_unchecked(&md->uevent_seq, 0);
37650 INIT_LIST_HEAD(&md->uevent_list);
37651 spin_lock_init(&md->uevent_lock);
37652
37653@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
37654
37655 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
37656
37657- atomic_inc(&md->event_nr);
37658+ atomic_inc_unchecked(&md->event_nr);
37659 wake_up(&md->eventq);
37660 }
37661
37662@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
37663
37664 uint32_t dm_next_uevent_seq(struct mapped_device *md)
37665 {
37666- return atomic_add_return(1, &md->uevent_seq);
37667+ return atomic_add_return_unchecked(1, &md->uevent_seq);
37668 }
37669
37670 uint32_t dm_get_event_nr(struct mapped_device *md)
37671 {
37672- return atomic_read(&md->event_nr);
37673+ return atomic_read_unchecked(&md->event_nr);
37674 }
37675
37676 int dm_wait_event(struct mapped_device *md, int event_nr)
37677 {
37678 return wait_event_interruptible(md->eventq,
37679- (event_nr != atomic_read(&md->event_nr)));
37680+ (event_nr != atomic_read_unchecked(&md->event_nr)));
37681 }
37682
37683 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
37684diff --git a/drivers/md/md.c b/drivers/md/md.c
37685index f363135..9b38815 100644
37686--- a/drivers/md/md.c
37687+++ b/drivers/md/md.c
37688@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
37689 * start build, activate spare
37690 */
37691 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
37692-static atomic_t md_event_count;
37693+static atomic_unchecked_t md_event_count;
37694 void md_new_event(struct mddev *mddev)
37695 {
37696- atomic_inc(&md_event_count);
37697+ atomic_inc_unchecked(&md_event_count);
37698 wake_up(&md_event_waiters);
37699 }
37700 EXPORT_SYMBOL_GPL(md_new_event);
37701@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
37702 */
37703 static void md_new_event_inintr(struct mddev *mddev)
37704 {
37705- atomic_inc(&md_event_count);
37706+ atomic_inc_unchecked(&md_event_count);
37707 wake_up(&md_event_waiters);
37708 }
37709
37710@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
37711 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
37712 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
37713 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
37714- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37715+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37716
37717 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
37718 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
37719@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
37720 else
37721 sb->resync_offset = cpu_to_le64(0);
37722
37723- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
37724+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
37725
37726 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
37727 sb->size = cpu_to_le64(mddev->dev_sectors);
37728@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
37729 static ssize_t
37730 errors_show(struct md_rdev *rdev, char *page)
37731 {
37732- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
37733+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
37734 }
37735
37736 static ssize_t
37737@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
37738 char *e;
37739 unsigned long n = simple_strtoul(buf, &e, 10);
37740 if (*buf && (*e == 0 || *e == '\n')) {
37741- atomic_set(&rdev->corrected_errors, n);
37742+ atomic_set_unchecked(&rdev->corrected_errors, n);
37743 return len;
37744 }
37745 return -EINVAL;
37746@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
37747 rdev->sb_loaded = 0;
37748 rdev->bb_page = NULL;
37749 atomic_set(&rdev->nr_pending, 0);
37750- atomic_set(&rdev->read_errors, 0);
37751- atomic_set(&rdev->corrected_errors, 0);
37752+ atomic_set_unchecked(&rdev->read_errors, 0);
37753+ atomic_set_unchecked(&rdev->corrected_errors, 0);
37754
37755 INIT_LIST_HEAD(&rdev->same_set);
37756 init_waitqueue_head(&rdev->blocked_wait);
37757@@ -6987,7 +6987,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
37758
37759 spin_unlock(&pers_lock);
37760 seq_printf(seq, "\n");
37761- seq->poll_event = atomic_read(&md_event_count);
37762+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37763 return 0;
37764 }
37765 if (v == (void*)2) {
37766@@ -7090,7 +7090,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
37767 return error;
37768
37769 seq = file->private_data;
37770- seq->poll_event = atomic_read(&md_event_count);
37771+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37772 return error;
37773 }
37774
37775@@ -7104,7 +7104,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
37776 /* always allow read */
37777 mask = POLLIN | POLLRDNORM;
37778
37779- if (seq->poll_event != atomic_read(&md_event_count))
37780+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
37781 mask |= POLLERR | POLLPRI;
37782 return mask;
37783 }
37784@@ -7148,7 +7148,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
37785 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
37786 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
37787 (int)part_stat_read(&disk->part0, sectors[1]) -
37788- atomic_read(&disk->sync_io);
37789+ atomic_read_unchecked(&disk->sync_io);
37790 /* sync IO will cause sync_io to increase before the disk_stats
37791 * as sync_io is counted when a request starts, and
37792 * disk_stats is counted when it completes.
37793diff --git a/drivers/md/md.h b/drivers/md/md.h
37794index eca59c3..7c42285 100644
37795--- a/drivers/md/md.h
37796+++ b/drivers/md/md.h
37797@@ -94,13 +94,13 @@ struct md_rdev {
37798 * only maintained for arrays that
37799 * support hot removal
37800 */
37801- atomic_t read_errors; /* number of consecutive read errors that
37802+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
37803 * we have tried to ignore.
37804 */
37805 struct timespec last_read_error; /* monotonic time since our
37806 * last read error
37807 */
37808- atomic_t corrected_errors; /* number of corrected read errors,
37809+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
37810 * for reporting to userspace and storing
37811 * in superblock.
37812 */
37813@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
37814
37815 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
37816 {
37817- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37818+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37819 }
37820
37821 struct md_personality
37822diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
37823index 1cbfc6b..56e1dbb 100644
37824--- a/drivers/md/persistent-data/dm-space-map.h
37825+++ b/drivers/md/persistent-data/dm-space-map.h
37826@@ -60,6 +60,7 @@ struct dm_space_map {
37827 int (*root_size)(struct dm_space_map *sm, size_t *result);
37828 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
37829 };
37830+typedef struct dm_space_map __no_const dm_space_map_no_const;
37831
37832 /*----------------------------------------------------------------*/
37833
37834diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
37835index 75b1f89..00ba344 100644
37836--- a/drivers/md/raid1.c
37837+++ b/drivers/md/raid1.c
37838@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
37839 if (r1_sync_page_io(rdev, sect, s,
37840 bio->bi_io_vec[idx].bv_page,
37841 READ) != 0)
37842- atomic_add(s, &rdev->corrected_errors);
37843+ atomic_add_unchecked(s, &rdev->corrected_errors);
37844 }
37845 sectors -= s;
37846 sect += s;
37847@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
37848 test_bit(In_sync, &rdev->flags)) {
37849 if (r1_sync_page_io(rdev, sect, s,
37850 conf->tmppage, READ)) {
37851- atomic_add(s, &rdev->corrected_errors);
37852+ atomic_add_unchecked(s, &rdev->corrected_errors);
37853 printk(KERN_INFO
37854 "md/raid1:%s: read error corrected "
37855 "(%d sectors at %llu on %s)\n",
37856diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
37857index 8d925dc..11d674f 100644
37858--- a/drivers/md/raid10.c
37859+++ b/drivers/md/raid10.c
37860@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
37861 /* The write handler will notice the lack of
37862 * R10BIO_Uptodate and record any errors etc
37863 */
37864- atomic_add(r10_bio->sectors,
37865+ atomic_add_unchecked(r10_bio->sectors,
37866 &conf->mirrors[d].rdev->corrected_errors);
37867
37868 /* for reconstruct, we always reschedule after a read.
37869@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
37870 {
37871 struct timespec cur_time_mon;
37872 unsigned long hours_since_last;
37873- unsigned int read_errors = atomic_read(&rdev->read_errors);
37874+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
37875
37876 ktime_get_ts(&cur_time_mon);
37877
37878@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
37879 * overflowing the shift of read_errors by hours_since_last.
37880 */
37881 if (hours_since_last >= 8 * sizeof(read_errors))
37882- atomic_set(&rdev->read_errors, 0);
37883+ atomic_set_unchecked(&rdev->read_errors, 0);
37884 else
37885- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
37886+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
37887 }
37888
37889 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
37890@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37891 return;
37892
37893 check_decay_read_errors(mddev, rdev);
37894- atomic_inc(&rdev->read_errors);
37895- if (atomic_read(&rdev->read_errors) > max_read_errors) {
37896+ atomic_inc_unchecked(&rdev->read_errors);
37897+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
37898 char b[BDEVNAME_SIZE];
37899 bdevname(rdev->bdev, b);
37900
37901@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37902 "md/raid10:%s: %s: Raid device exceeded "
37903 "read_error threshold [cur %d:max %d]\n",
37904 mdname(mddev), b,
37905- atomic_read(&rdev->read_errors), max_read_errors);
37906+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
37907 printk(KERN_NOTICE
37908 "md/raid10:%s: %s: Failing raid device\n",
37909 mdname(mddev), b);
37910@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37911 sect +
37912 choose_data_offset(r10_bio, rdev)),
37913 bdevname(rdev->bdev, b));
37914- atomic_add(s, &rdev->corrected_errors);
37915+ atomic_add_unchecked(s, &rdev->corrected_errors);
37916 }
37917
37918 rdev_dec_pending(rdev, mddev);
37919diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
37920index 19d77a0..56051b92 100644
37921--- a/drivers/md/raid5.c
37922+++ b/drivers/md/raid5.c
37923@@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
37924 mdname(conf->mddev), STRIPE_SECTORS,
37925 (unsigned long long)s,
37926 bdevname(rdev->bdev, b));
37927- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
37928+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
37929 clear_bit(R5_ReadError, &sh->dev[i].flags);
37930 clear_bit(R5_ReWrite, &sh->dev[i].flags);
37931 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
37932 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
37933
37934- if (atomic_read(&rdev->read_errors))
37935- atomic_set(&rdev->read_errors, 0);
37936+ if (atomic_read_unchecked(&rdev->read_errors))
37937+ atomic_set_unchecked(&rdev->read_errors, 0);
37938 } else {
37939 const char *bdn = bdevname(rdev->bdev, b);
37940 int retry = 0;
37941 int set_bad = 0;
37942
37943 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
37944- atomic_inc(&rdev->read_errors);
37945+ atomic_inc_unchecked(&rdev->read_errors);
37946 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
37947 printk_ratelimited(
37948 KERN_WARNING
37949@@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
37950 mdname(conf->mddev),
37951 (unsigned long long)s,
37952 bdn);
37953- } else if (atomic_read(&rdev->read_errors)
37954+ } else if (atomic_read_unchecked(&rdev->read_errors)
37955 > conf->max_nr_stripes)
37956 printk(KERN_WARNING
37957 "md/raid:%s: Too many read errors, failing device %s.\n",
37958diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
37959index d33101a..6b13069 100644
37960--- a/drivers/media/dvb-core/dvbdev.c
37961+++ b/drivers/media/dvb-core/dvbdev.c
37962@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
37963 const struct dvb_device *template, void *priv, int type)
37964 {
37965 struct dvb_device *dvbdev;
37966- struct file_operations *dvbdevfops;
37967+ file_operations_no_const *dvbdevfops;
37968 struct device *clsdev;
37969 int minor;
37970 int id;
37971diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
37972index 404f63a..4796533 100644
37973--- a/drivers/media/dvb-frontends/dib3000.h
37974+++ b/drivers/media/dvb-frontends/dib3000.h
37975@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
37976 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
37977 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
37978 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
37979-};
37980+} __no_const;
37981
37982 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
37983 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
37984diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
37985index 8e9a668..78d6310 100644
37986--- a/drivers/media/platform/omap/omap_vout.c
37987+++ b/drivers/media/platform/omap/omap_vout.c
37988@@ -63,7 +63,6 @@ enum omap_vout_channels {
37989 OMAP_VIDEO2,
37990 };
37991
37992-static struct videobuf_queue_ops video_vbq_ops;
37993 /* Variables configurable through module params*/
37994 static u32 video1_numbuffers = 3;
37995 static u32 video2_numbuffers = 3;
37996@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
37997 {
37998 struct videobuf_queue *q;
37999 struct omap_vout_device *vout = NULL;
38000+ static struct videobuf_queue_ops video_vbq_ops = {
38001+ .buf_setup = omap_vout_buffer_setup,
38002+ .buf_prepare = omap_vout_buffer_prepare,
38003+ .buf_release = omap_vout_buffer_release,
38004+ .buf_queue = omap_vout_buffer_queue,
38005+ };
38006
38007 vout = video_drvdata(file);
38008 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38009@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38010 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38011
38012 q = &vout->vbq;
38013- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38014- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38015- video_vbq_ops.buf_release = omap_vout_buffer_release;
38016- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38017 spin_lock_init(&vout->vbq_lock);
38018
38019 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38020diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38021index b671e20..34088b7 100644
38022--- a/drivers/media/platform/s5p-tv/mixer.h
38023+++ b/drivers/media/platform/s5p-tv/mixer.h
38024@@ -155,7 +155,7 @@ struct mxr_layer {
38025 /** layer index (unique identifier) */
38026 int idx;
38027 /** callbacks for layer methods */
38028- struct mxr_layer_ops ops;
38029+ struct mxr_layer_ops *ops;
38030 /** format array */
38031 const struct mxr_format **fmt_array;
38032 /** size of format array */
38033diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38034index b93a21f..2535195 100644
38035--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38036+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38037@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38038 {
38039 struct mxr_layer *layer;
38040 int ret;
38041- struct mxr_layer_ops ops = {
38042+ static struct mxr_layer_ops ops = {
38043 .release = mxr_graph_layer_release,
38044 .buffer_set = mxr_graph_buffer_set,
38045 .stream_set = mxr_graph_stream_set,
38046diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38047index 3b1670a..595c939 100644
38048--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38049+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38050@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38051 layer->update_buf = next;
38052 }
38053
38054- layer->ops.buffer_set(layer, layer->update_buf);
38055+ layer->ops->buffer_set(layer, layer->update_buf);
38056
38057 if (done && done != layer->shadow_buf)
38058 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38059diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38060index 1f3b743..e839271 100644
38061--- a/drivers/media/platform/s5p-tv/mixer_video.c
38062+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38063@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38064 layer->geo.src.height = layer->geo.src.full_height;
38065
38066 mxr_geometry_dump(mdev, &layer->geo);
38067- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38068+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38069 mxr_geometry_dump(mdev, &layer->geo);
38070 }
38071
38072@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38073 layer->geo.dst.full_width = mbus_fmt.width;
38074 layer->geo.dst.full_height = mbus_fmt.height;
38075 layer->geo.dst.field = mbus_fmt.field;
38076- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38077+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38078
38079 mxr_geometry_dump(mdev, &layer->geo);
38080 }
38081@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38082 /* set source size to highest accepted value */
38083 geo->src.full_width = max(geo->dst.full_width, pix->width);
38084 geo->src.full_height = max(geo->dst.full_height, pix->height);
38085- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38086+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38087 mxr_geometry_dump(mdev, &layer->geo);
38088 /* set cropping to total visible screen */
38089 geo->src.width = pix->width;
38090@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38091 geo->src.x_offset = 0;
38092 geo->src.y_offset = 0;
38093 /* assure consistency of geometry */
38094- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38095+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38096 mxr_geometry_dump(mdev, &layer->geo);
38097 /* set full size to lowest possible value */
38098 geo->src.full_width = 0;
38099 geo->src.full_height = 0;
38100- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38101+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38102 mxr_geometry_dump(mdev, &layer->geo);
38103
38104 /* returning results */
38105@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38106 target->width = s->r.width;
38107 target->height = s->r.height;
38108
38109- layer->ops.fix_geometry(layer, stage, s->flags);
38110+ layer->ops->fix_geometry(layer, stage, s->flags);
38111
38112 /* retrieve update selection rectangle */
38113 res.left = target->x_offset;
38114@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38115 mxr_output_get(mdev);
38116
38117 mxr_layer_update_output(layer);
38118- layer->ops.format_set(layer);
38119+ layer->ops->format_set(layer);
38120 /* enabling layer in hardware */
38121 spin_lock_irqsave(&layer->enq_slock, flags);
38122 layer->state = MXR_LAYER_STREAMING;
38123 spin_unlock_irqrestore(&layer->enq_slock, flags);
38124
38125- layer->ops.stream_set(layer, MXR_ENABLE);
38126+ layer->ops->stream_set(layer, MXR_ENABLE);
38127 mxr_streamer_get(mdev);
38128
38129 return 0;
38130@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
38131 spin_unlock_irqrestore(&layer->enq_slock, flags);
38132
38133 /* disabling layer in hardware */
38134- layer->ops.stream_set(layer, MXR_DISABLE);
38135+ layer->ops->stream_set(layer, MXR_DISABLE);
38136 /* remove one streamer */
38137 mxr_streamer_put(mdev);
38138 /* allow changes in output configuration */
38139@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38140
38141 void mxr_layer_release(struct mxr_layer *layer)
38142 {
38143- if (layer->ops.release)
38144- layer->ops.release(layer);
38145+ if (layer->ops->release)
38146+ layer->ops->release(layer);
38147 }
38148
38149 void mxr_base_layer_release(struct mxr_layer *layer)
38150@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38151
38152 layer->mdev = mdev;
38153 layer->idx = idx;
38154- layer->ops = *ops;
38155+ layer->ops = ops;
38156
38157 spin_lock_init(&layer->enq_slock);
38158 INIT_LIST_HEAD(&layer->enq_list);
38159diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38160index 3d13a63..da31bf1 100644
38161--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38162+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38163@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38164 {
38165 struct mxr_layer *layer;
38166 int ret;
38167- struct mxr_layer_ops ops = {
38168+ static struct mxr_layer_ops ops = {
38169 .release = mxr_vp_layer_release,
38170 .buffer_set = mxr_vp_buffer_set,
38171 .stream_set = mxr_vp_stream_set,
38172diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38173index 643d80a..56bb96b 100644
38174--- a/drivers/media/radio/radio-cadet.c
38175+++ b/drivers/media/radio/radio-cadet.c
38176@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38177 unsigned char readbuf[RDS_BUFFER];
38178 int i = 0;
38179
38180+ if (count > RDS_BUFFER)
38181+ return -EFAULT;
38182 mutex_lock(&dev->lock);
38183 if (dev->rdsstat == 0)
38184 cadet_start_rds(dev);
38185@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38186 while (i < count && dev->rdsin != dev->rdsout)
38187 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38188
38189- if (i && copy_to_user(data, readbuf, i))
38190+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38191 i = -EFAULT;
38192 unlock:
38193 mutex_unlock(&dev->lock);
38194diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38195index 3940bb0..fb3952a 100644
38196--- a/drivers/media/usb/dvb-usb/cxusb.c
38197+++ b/drivers/media/usb/dvb-usb/cxusb.c
38198@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38199
38200 struct dib0700_adapter_state {
38201 int (*set_param_save) (struct dvb_frontend *);
38202-};
38203+} __no_const;
38204
38205 static int dib7070_set_param_override(struct dvb_frontend *fe)
38206 {
38207diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38208index 9382895..ac8093c 100644
38209--- a/drivers/media/usb/dvb-usb/dw2102.c
38210+++ b/drivers/media/usb/dvb-usb/dw2102.c
38211@@ -95,7 +95,7 @@ struct su3000_state {
38212
38213 struct s6x0_state {
38214 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38215-};
38216+} __no_const;
38217
38218 /* debug */
38219 static int dvb_usb_dw2102_debug;
38220diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38221index aa6e7c7..4cd8061 100644
38222--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38223+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38224@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38225 struct file *file, void *fh, void *p);
38226 } u;
38227 void (*debug)(const void *arg, bool write_only);
38228-};
38229+} __do_const;
38230+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38231
38232 /* This control needs a priority check */
38233 #define INFO_FL_PRIO (1 << 0)
38234@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38235 struct video_device *vfd = video_devdata(file);
38236 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38237 bool write_only = false;
38238- struct v4l2_ioctl_info default_info;
38239+ v4l2_ioctl_info_no_const default_info;
38240 const struct v4l2_ioctl_info *info;
38241 void *fh = file->private_data;
38242 struct v4l2_fh *vfh = NULL;
38243diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38244index 29b2172..a7c5b31 100644
38245--- a/drivers/memstick/host/r592.c
38246+++ b/drivers/memstick/host/r592.c
38247@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38248 /* Executes one TPC (data is read/written from small or large fifo) */
38249 static void r592_execute_tpc(struct r592_device *dev)
38250 {
38251- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38252+ bool is_write;
38253 int len, error;
38254 u32 status, reg;
38255
38256@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38257 return;
38258 }
38259
38260+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38261 len = dev->req->long_data ?
38262 dev->req->sg.length : dev->req->data_len;
38263
38264diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38265index fb69baa..cf7ad22 100644
38266--- a/drivers/message/fusion/mptbase.c
38267+++ b/drivers/message/fusion/mptbase.c
38268@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38269 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38270 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38271
38272+#ifdef CONFIG_GRKERNSEC_HIDESYM
38273+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38274+#else
38275 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38276 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38277+#endif
38278+
38279 /*
38280 * Rounding UP to nearest 4-kB boundary here...
38281 */
38282diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38283index fa43c39..daeb158 100644
38284--- a/drivers/message/fusion/mptsas.c
38285+++ b/drivers/message/fusion/mptsas.c
38286@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38287 return 0;
38288 }
38289
38290+static inline void
38291+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38292+{
38293+ if (phy_info->port_details) {
38294+ phy_info->port_details->rphy = rphy;
38295+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38296+ ioc->name, rphy));
38297+ }
38298+
38299+ if (rphy) {
38300+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38301+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38302+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38303+ ioc->name, rphy, rphy->dev.release));
38304+ }
38305+}
38306+
38307 /* no mutex */
38308 static void
38309 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38310@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38311 return NULL;
38312 }
38313
38314-static inline void
38315-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38316-{
38317- if (phy_info->port_details) {
38318- phy_info->port_details->rphy = rphy;
38319- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38320- ioc->name, rphy));
38321- }
38322-
38323- if (rphy) {
38324- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38325- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38326- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38327- ioc->name, rphy, rphy->dev.release));
38328- }
38329-}
38330-
38331 static inline struct sas_port *
38332 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38333 {
38334diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38335index 164afa7..b6b2e74 100644
38336--- a/drivers/message/fusion/mptscsih.c
38337+++ b/drivers/message/fusion/mptscsih.c
38338@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38339
38340 h = shost_priv(SChost);
38341
38342- if (h) {
38343- if (h->info_kbuf == NULL)
38344- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38345- return h->info_kbuf;
38346- h->info_kbuf[0] = '\0';
38347+ if (!h)
38348+ return NULL;
38349
38350- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38351- h->info_kbuf[size-1] = '\0';
38352- }
38353+ if (h->info_kbuf == NULL)
38354+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38355+ return h->info_kbuf;
38356+ h->info_kbuf[0] = '\0';
38357+
38358+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38359+ h->info_kbuf[size-1] = '\0';
38360
38361 return h->info_kbuf;
38362 }
38363diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38364index 8001aa6..b137580 100644
38365--- a/drivers/message/i2o/i2o_proc.c
38366+++ b/drivers/message/i2o/i2o_proc.c
38367@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38368 "Array Controller Device"
38369 };
38370
38371-static char *chtostr(char *tmp, u8 *chars, int n)
38372-{
38373- tmp[0] = 0;
38374- return strncat(tmp, (char *)chars, n);
38375-}
38376-
38377 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38378 char *group)
38379 {
38380@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38381 } *result;
38382
38383 i2o_exec_execute_ddm_table ddm_table;
38384- char tmp[28 + 1];
38385
38386 result = kmalloc(sizeof(*result), GFP_KERNEL);
38387 if (!result)
38388@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38389
38390 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38391 seq_printf(seq, "%-#8x", ddm_table.module_id);
38392- seq_printf(seq, "%-29s",
38393- chtostr(tmp, ddm_table.module_name_version, 28));
38394+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38395 seq_printf(seq, "%9d ", ddm_table.data_size);
38396 seq_printf(seq, "%8d", ddm_table.code_size);
38397
38398@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38399
38400 i2o_driver_result_table *result;
38401 i2o_driver_store_table *dst;
38402- char tmp[28 + 1];
38403
38404 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
38405 if (result == NULL)
38406@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38407
38408 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
38409 seq_printf(seq, "%-#8x", dst->module_id);
38410- seq_printf(seq, "%-29s",
38411- chtostr(tmp, dst->module_name_version, 28));
38412- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
38413+ seq_printf(seq, "%-.28s", dst->module_name_version);
38414+ seq_printf(seq, "%-.8s", dst->date);
38415 seq_printf(seq, "%8d ", dst->module_size);
38416 seq_printf(seq, "%8d ", dst->mpb_size);
38417 seq_printf(seq, "0x%04x", dst->module_flags);
38418@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38419 // == (allow) 512d bytes (max)
38420 static u16 *work16 = (u16 *) work32;
38421 int token;
38422- char tmp[16 + 1];
38423
38424 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
38425
38426@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38427 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
38428 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
38429 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
38430- seq_printf(seq, "Vendor info : %s\n",
38431- chtostr(tmp, (u8 *) (work32 + 2), 16));
38432- seq_printf(seq, "Product info : %s\n",
38433- chtostr(tmp, (u8 *) (work32 + 6), 16));
38434- seq_printf(seq, "Description : %s\n",
38435- chtostr(tmp, (u8 *) (work32 + 10), 16));
38436- seq_printf(seq, "Product rev. : %s\n",
38437- chtostr(tmp, (u8 *) (work32 + 14), 8));
38438+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
38439+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
38440+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
38441+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
38442
38443 seq_printf(seq, "Serial number : ");
38444 print_serial_number(seq, (u8 *) (work32 + 16),
38445@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38446 u8 pad[256]; // allow up to 256 byte (max) serial number
38447 } result;
38448
38449- char tmp[24 + 1];
38450-
38451 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
38452
38453 if (token < 0) {
38454@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38455 }
38456
38457 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
38458- seq_printf(seq, "Module name : %s\n",
38459- chtostr(tmp, result.module_name, 24));
38460- seq_printf(seq, "Module revision : %s\n",
38461- chtostr(tmp, result.module_rev, 8));
38462+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
38463+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
38464
38465 seq_printf(seq, "Serial number : ");
38466 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
38467@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38468 u8 instance_number[4];
38469 } result;
38470
38471- char tmp[64 + 1];
38472-
38473 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
38474
38475 if (token < 0) {
38476@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38477 return 0;
38478 }
38479
38480- seq_printf(seq, "Device name : %s\n",
38481- chtostr(tmp, result.device_name, 64));
38482- seq_printf(seq, "Service name : %s\n",
38483- chtostr(tmp, result.service_name, 64));
38484- seq_printf(seq, "Physical name : %s\n",
38485- chtostr(tmp, result.physical_location, 64));
38486- seq_printf(seq, "Instance number : %s\n",
38487- chtostr(tmp, result.instance_number, 4));
38488+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
38489+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
38490+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
38491+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
38492
38493 return 0;
38494 }
38495diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
38496index a8c08f3..155fe3d 100644
38497--- a/drivers/message/i2o/iop.c
38498+++ b/drivers/message/i2o/iop.c
38499@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
38500
38501 spin_lock_irqsave(&c->context_list_lock, flags);
38502
38503- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
38504- atomic_inc(&c->context_list_counter);
38505+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
38506+ atomic_inc_unchecked(&c->context_list_counter);
38507
38508- entry->context = atomic_read(&c->context_list_counter);
38509+ entry->context = atomic_read_unchecked(&c->context_list_counter);
38510
38511 list_add(&entry->list, &c->context_list);
38512
38513@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
38514
38515 #if BITS_PER_LONG == 64
38516 spin_lock_init(&c->context_list_lock);
38517- atomic_set(&c->context_list_counter, 0);
38518+ atomic_set_unchecked(&c->context_list_counter, 0);
38519 INIT_LIST_HEAD(&c->context_list);
38520 #endif
38521
38522diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
38523index 45ece11..8efa218 100644
38524--- a/drivers/mfd/janz-cmodio.c
38525+++ b/drivers/mfd/janz-cmodio.c
38526@@ -13,6 +13,7 @@
38527
38528 #include <linux/kernel.h>
38529 #include <linux/module.h>
38530+#include <linux/slab.h>
38531 #include <linux/init.h>
38532 #include <linux/pci.h>
38533 #include <linux/interrupt.h>
38534diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
38535index a5f9888..1c0ed56 100644
38536--- a/drivers/mfd/twl4030-irq.c
38537+++ b/drivers/mfd/twl4030-irq.c
38538@@ -35,6 +35,7 @@
38539 #include <linux/of.h>
38540 #include <linux/irqdomain.h>
38541 #include <linux/i2c/twl.h>
38542+#include <asm/pgtable.h>
38543
38544 #include "twl-core.h"
38545
38546@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
38547 * Install an irq handler for each of the SIH modules;
38548 * clone dummy irq_chip since PIH can't *do* anything
38549 */
38550- twl4030_irq_chip = dummy_irq_chip;
38551- twl4030_irq_chip.name = "twl4030";
38552+ pax_open_kernel();
38553+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
38554+ *(const char **)&twl4030_irq_chip.name = "twl4030";
38555
38556- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38557+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38558+ pax_close_kernel();
38559
38560 for (i = irq_base; i < irq_end; i++) {
38561 irq_set_chip_and_handler(i, &twl4030_irq_chip,
38562diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
38563index 277a8db..0e0b754 100644
38564--- a/drivers/mfd/twl6030-irq.c
38565+++ b/drivers/mfd/twl6030-irq.c
38566@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
38567 * install an irq handler for each of the modules;
38568 * clone dummy irq_chip since PIH can't *do* anything
38569 */
38570- twl6030_irq_chip = dummy_irq_chip;
38571- twl6030_irq_chip.name = "twl6030";
38572- twl6030_irq_chip.irq_set_type = NULL;
38573- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38574+ pax_open_kernel();
38575+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
38576+ *(const char **)&twl6030_irq_chip.name = "twl6030";
38577+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
38578+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38579+ pax_close_kernel();
38580
38581 for (i = irq_base; i < irq_end; i++) {
38582 irq_set_chip_and_handler(i, &twl6030_irq_chip,
38583diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
38584index f428d86..274c368 100644
38585--- a/drivers/misc/c2port/core.c
38586+++ b/drivers/misc/c2port/core.c
38587@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
38588 mutex_init(&c2dev->mutex);
38589
38590 /* Create binary file */
38591- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38592+ pax_open_kernel();
38593+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38594+ pax_close_kernel();
38595 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
38596 if (unlikely(ret))
38597 goto error_device_create_bin_file;
38598diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
38599index 3aa9a96..59cf685 100644
38600--- a/drivers/misc/kgdbts.c
38601+++ b/drivers/misc/kgdbts.c
38602@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
38603 char before[BREAK_INSTR_SIZE];
38604 char after[BREAK_INSTR_SIZE];
38605
38606- probe_kernel_read(before, (char *)kgdbts_break_test,
38607+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
38608 BREAK_INSTR_SIZE);
38609 init_simple_test();
38610 ts.tst = plant_and_detach_test;
38611@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
38612 /* Activate test with initial breakpoint */
38613 if (!is_early)
38614 kgdb_breakpoint();
38615- probe_kernel_read(after, (char *)kgdbts_break_test,
38616+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
38617 BREAK_INSTR_SIZE);
38618 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
38619 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
38620diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
38621index 4a87e5c..76bdf5c 100644
38622--- a/drivers/misc/lis3lv02d/lis3lv02d.c
38623+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
38624@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
38625 * the lid is closed. This leads to interrupts as soon as a little move
38626 * is done.
38627 */
38628- atomic_inc(&lis3->count);
38629+ atomic_inc_unchecked(&lis3->count);
38630
38631 wake_up_interruptible(&lis3->misc_wait);
38632 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
38633@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
38634 if (lis3->pm_dev)
38635 pm_runtime_get_sync(lis3->pm_dev);
38636
38637- atomic_set(&lis3->count, 0);
38638+ atomic_set_unchecked(&lis3->count, 0);
38639 return 0;
38640 }
38641
38642@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
38643 add_wait_queue(&lis3->misc_wait, &wait);
38644 while (true) {
38645 set_current_state(TASK_INTERRUPTIBLE);
38646- data = atomic_xchg(&lis3->count, 0);
38647+ data = atomic_xchg_unchecked(&lis3->count, 0);
38648 if (data)
38649 break;
38650
38651@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
38652 struct lis3lv02d, miscdev);
38653
38654 poll_wait(file, &lis3->misc_wait, wait);
38655- if (atomic_read(&lis3->count))
38656+ if (atomic_read_unchecked(&lis3->count))
38657 return POLLIN | POLLRDNORM;
38658 return 0;
38659 }
38660diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
38661index c439c82..1f20f57 100644
38662--- a/drivers/misc/lis3lv02d/lis3lv02d.h
38663+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
38664@@ -297,7 +297,7 @@ struct lis3lv02d {
38665 struct input_polled_dev *idev; /* input device */
38666 struct platform_device *pdev; /* platform device */
38667 struct regulator_bulk_data regulators[2];
38668- atomic_t count; /* interrupt count after last read */
38669+ atomic_unchecked_t count; /* interrupt count after last read */
38670 union axis_conversion ac; /* hw -> logical axis */
38671 int mapped_btns[3];
38672
38673diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
38674index 2f30bad..c4c13d0 100644
38675--- a/drivers/misc/sgi-gru/gruhandles.c
38676+++ b/drivers/misc/sgi-gru/gruhandles.c
38677@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
38678 unsigned long nsec;
38679
38680 nsec = CLKS2NSEC(clks);
38681- atomic_long_inc(&mcs_op_statistics[op].count);
38682- atomic_long_add(nsec, &mcs_op_statistics[op].total);
38683+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
38684+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
38685 if (mcs_op_statistics[op].max < nsec)
38686 mcs_op_statistics[op].max = nsec;
38687 }
38688diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
38689index 950dbe9..eeef0f8 100644
38690--- a/drivers/misc/sgi-gru/gruprocfs.c
38691+++ b/drivers/misc/sgi-gru/gruprocfs.c
38692@@ -32,9 +32,9 @@
38693
38694 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
38695
38696-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
38697+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
38698 {
38699- unsigned long val = atomic_long_read(v);
38700+ unsigned long val = atomic_long_read_unchecked(v);
38701
38702 seq_printf(s, "%16lu %s\n", val, id);
38703 }
38704@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
38705
38706 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
38707 for (op = 0; op < mcsop_last; op++) {
38708- count = atomic_long_read(&mcs_op_statistics[op].count);
38709- total = atomic_long_read(&mcs_op_statistics[op].total);
38710+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
38711+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
38712 max = mcs_op_statistics[op].max;
38713 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
38714 count ? total / count : 0, max);
38715diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
38716index 5c3ce24..4915ccb 100644
38717--- a/drivers/misc/sgi-gru/grutables.h
38718+++ b/drivers/misc/sgi-gru/grutables.h
38719@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
38720 * GRU statistics.
38721 */
38722 struct gru_stats_s {
38723- atomic_long_t vdata_alloc;
38724- atomic_long_t vdata_free;
38725- atomic_long_t gts_alloc;
38726- atomic_long_t gts_free;
38727- atomic_long_t gms_alloc;
38728- atomic_long_t gms_free;
38729- atomic_long_t gts_double_allocate;
38730- atomic_long_t assign_context;
38731- atomic_long_t assign_context_failed;
38732- atomic_long_t free_context;
38733- atomic_long_t load_user_context;
38734- atomic_long_t load_kernel_context;
38735- atomic_long_t lock_kernel_context;
38736- atomic_long_t unlock_kernel_context;
38737- atomic_long_t steal_user_context;
38738- atomic_long_t steal_kernel_context;
38739- atomic_long_t steal_context_failed;
38740- atomic_long_t nopfn;
38741- atomic_long_t asid_new;
38742- atomic_long_t asid_next;
38743- atomic_long_t asid_wrap;
38744- atomic_long_t asid_reuse;
38745- atomic_long_t intr;
38746- atomic_long_t intr_cbr;
38747- atomic_long_t intr_tfh;
38748- atomic_long_t intr_spurious;
38749- atomic_long_t intr_mm_lock_failed;
38750- atomic_long_t call_os;
38751- atomic_long_t call_os_wait_queue;
38752- atomic_long_t user_flush_tlb;
38753- atomic_long_t user_unload_context;
38754- atomic_long_t user_exception;
38755- atomic_long_t set_context_option;
38756- atomic_long_t check_context_retarget_intr;
38757- atomic_long_t check_context_unload;
38758- atomic_long_t tlb_dropin;
38759- atomic_long_t tlb_preload_page;
38760- atomic_long_t tlb_dropin_fail_no_asid;
38761- atomic_long_t tlb_dropin_fail_upm;
38762- atomic_long_t tlb_dropin_fail_invalid;
38763- atomic_long_t tlb_dropin_fail_range_active;
38764- atomic_long_t tlb_dropin_fail_idle;
38765- atomic_long_t tlb_dropin_fail_fmm;
38766- atomic_long_t tlb_dropin_fail_no_exception;
38767- atomic_long_t tfh_stale_on_fault;
38768- atomic_long_t mmu_invalidate_range;
38769- atomic_long_t mmu_invalidate_page;
38770- atomic_long_t flush_tlb;
38771- atomic_long_t flush_tlb_gru;
38772- atomic_long_t flush_tlb_gru_tgh;
38773- atomic_long_t flush_tlb_gru_zero_asid;
38774+ atomic_long_unchecked_t vdata_alloc;
38775+ atomic_long_unchecked_t vdata_free;
38776+ atomic_long_unchecked_t gts_alloc;
38777+ atomic_long_unchecked_t gts_free;
38778+ atomic_long_unchecked_t gms_alloc;
38779+ atomic_long_unchecked_t gms_free;
38780+ atomic_long_unchecked_t gts_double_allocate;
38781+ atomic_long_unchecked_t assign_context;
38782+ atomic_long_unchecked_t assign_context_failed;
38783+ atomic_long_unchecked_t free_context;
38784+ atomic_long_unchecked_t load_user_context;
38785+ atomic_long_unchecked_t load_kernel_context;
38786+ atomic_long_unchecked_t lock_kernel_context;
38787+ atomic_long_unchecked_t unlock_kernel_context;
38788+ atomic_long_unchecked_t steal_user_context;
38789+ atomic_long_unchecked_t steal_kernel_context;
38790+ atomic_long_unchecked_t steal_context_failed;
38791+ atomic_long_unchecked_t nopfn;
38792+ atomic_long_unchecked_t asid_new;
38793+ atomic_long_unchecked_t asid_next;
38794+ atomic_long_unchecked_t asid_wrap;
38795+ atomic_long_unchecked_t asid_reuse;
38796+ atomic_long_unchecked_t intr;
38797+ atomic_long_unchecked_t intr_cbr;
38798+ atomic_long_unchecked_t intr_tfh;
38799+ atomic_long_unchecked_t intr_spurious;
38800+ atomic_long_unchecked_t intr_mm_lock_failed;
38801+ atomic_long_unchecked_t call_os;
38802+ atomic_long_unchecked_t call_os_wait_queue;
38803+ atomic_long_unchecked_t user_flush_tlb;
38804+ atomic_long_unchecked_t user_unload_context;
38805+ atomic_long_unchecked_t user_exception;
38806+ atomic_long_unchecked_t set_context_option;
38807+ atomic_long_unchecked_t check_context_retarget_intr;
38808+ atomic_long_unchecked_t check_context_unload;
38809+ atomic_long_unchecked_t tlb_dropin;
38810+ atomic_long_unchecked_t tlb_preload_page;
38811+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
38812+ atomic_long_unchecked_t tlb_dropin_fail_upm;
38813+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
38814+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
38815+ atomic_long_unchecked_t tlb_dropin_fail_idle;
38816+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
38817+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
38818+ atomic_long_unchecked_t tfh_stale_on_fault;
38819+ atomic_long_unchecked_t mmu_invalidate_range;
38820+ atomic_long_unchecked_t mmu_invalidate_page;
38821+ atomic_long_unchecked_t flush_tlb;
38822+ atomic_long_unchecked_t flush_tlb_gru;
38823+ atomic_long_unchecked_t flush_tlb_gru_tgh;
38824+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
38825
38826- atomic_long_t copy_gpa;
38827- atomic_long_t read_gpa;
38828+ atomic_long_unchecked_t copy_gpa;
38829+ atomic_long_unchecked_t read_gpa;
38830
38831- atomic_long_t mesq_receive;
38832- atomic_long_t mesq_receive_none;
38833- atomic_long_t mesq_send;
38834- atomic_long_t mesq_send_failed;
38835- atomic_long_t mesq_noop;
38836- atomic_long_t mesq_send_unexpected_error;
38837- atomic_long_t mesq_send_lb_overflow;
38838- atomic_long_t mesq_send_qlimit_reached;
38839- atomic_long_t mesq_send_amo_nacked;
38840- atomic_long_t mesq_send_put_nacked;
38841- atomic_long_t mesq_page_overflow;
38842- atomic_long_t mesq_qf_locked;
38843- atomic_long_t mesq_qf_noop_not_full;
38844- atomic_long_t mesq_qf_switch_head_failed;
38845- atomic_long_t mesq_qf_unexpected_error;
38846- atomic_long_t mesq_noop_unexpected_error;
38847- atomic_long_t mesq_noop_lb_overflow;
38848- atomic_long_t mesq_noop_qlimit_reached;
38849- atomic_long_t mesq_noop_amo_nacked;
38850- atomic_long_t mesq_noop_put_nacked;
38851- atomic_long_t mesq_noop_page_overflow;
38852+ atomic_long_unchecked_t mesq_receive;
38853+ atomic_long_unchecked_t mesq_receive_none;
38854+ atomic_long_unchecked_t mesq_send;
38855+ atomic_long_unchecked_t mesq_send_failed;
38856+ atomic_long_unchecked_t mesq_noop;
38857+ atomic_long_unchecked_t mesq_send_unexpected_error;
38858+ atomic_long_unchecked_t mesq_send_lb_overflow;
38859+ atomic_long_unchecked_t mesq_send_qlimit_reached;
38860+ atomic_long_unchecked_t mesq_send_amo_nacked;
38861+ atomic_long_unchecked_t mesq_send_put_nacked;
38862+ atomic_long_unchecked_t mesq_page_overflow;
38863+ atomic_long_unchecked_t mesq_qf_locked;
38864+ atomic_long_unchecked_t mesq_qf_noop_not_full;
38865+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
38866+ atomic_long_unchecked_t mesq_qf_unexpected_error;
38867+ atomic_long_unchecked_t mesq_noop_unexpected_error;
38868+ atomic_long_unchecked_t mesq_noop_lb_overflow;
38869+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
38870+ atomic_long_unchecked_t mesq_noop_amo_nacked;
38871+ atomic_long_unchecked_t mesq_noop_put_nacked;
38872+ atomic_long_unchecked_t mesq_noop_page_overflow;
38873
38874 };
38875
38876@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
38877 tghop_invalidate, mcsop_last};
38878
38879 struct mcs_op_statistic {
38880- atomic_long_t count;
38881- atomic_long_t total;
38882+ atomic_long_unchecked_t count;
38883+ atomic_long_unchecked_t total;
38884 unsigned long max;
38885 };
38886
38887@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
38888
38889 #define STAT(id) do { \
38890 if (gru_options & OPT_STATS) \
38891- atomic_long_inc(&gru_stats.id); \
38892+ atomic_long_inc_unchecked(&gru_stats.id); \
38893 } while (0)
38894
38895 #ifdef CONFIG_SGI_GRU_DEBUG
38896diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
38897index c862cd4..0d176fe 100644
38898--- a/drivers/misc/sgi-xp/xp.h
38899+++ b/drivers/misc/sgi-xp/xp.h
38900@@ -288,7 +288,7 @@ struct xpc_interface {
38901 xpc_notify_func, void *);
38902 void (*received) (short, int, void *);
38903 enum xp_retval (*partid_to_nasids) (short, void *);
38904-};
38905+} __no_const;
38906
38907 extern struct xpc_interface xpc_interface;
38908
38909diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
38910index b94d5f7..7f494c5 100644
38911--- a/drivers/misc/sgi-xp/xpc.h
38912+++ b/drivers/misc/sgi-xp/xpc.h
38913@@ -835,6 +835,7 @@ struct xpc_arch_operations {
38914 void (*received_payload) (struct xpc_channel *, void *);
38915 void (*notify_senders_of_disconnect) (struct xpc_channel *);
38916 };
38917+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
38918
38919 /* struct xpc_partition act_state values (for XPC HB) */
38920
38921@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
38922 /* found in xpc_main.c */
38923 extern struct device *xpc_part;
38924 extern struct device *xpc_chan;
38925-extern struct xpc_arch_operations xpc_arch_ops;
38926+extern xpc_arch_operations_no_const xpc_arch_ops;
38927 extern int xpc_disengage_timelimit;
38928 extern int xpc_disengage_timedout;
38929 extern int xpc_activate_IRQ_rcvd;
38930diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
38931index d971817..33bdca5 100644
38932--- a/drivers/misc/sgi-xp/xpc_main.c
38933+++ b/drivers/misc/sgi-xp/xpc_main.c
38934@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
38935 .notifier_call = xpc_system_die,
38936 };
38937
38938-struct xpc_arch_operations xpc_arch_ops;
38939+xpc_arch_operations_no_const xpc_arch_ops;
38940
38941 /*
38942 * Timer function to enforce the timelimit on the partition disengage.
38943@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
38944
38945 if (((die_args->trapnr == X86_TRAP_MF) ||
38946 (die_args->trapnr == X86_TRAP_XF)) &&
38947- !user_mode_vm(die_args->regs))
38948+ !user_mode(die_args->regs))
38949 xpc_die_deactivate();
38950
38951 break;
38952diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
38953index 6d8f701..35b6369 100644
38954--- a/drivers/mmc/core/mmc_ops.c
38955+++ b/drivers/mmc/core/mmc_ops.c
38956@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
38957 void *data_buf;
38958 int is_on_stack;
38959
38960- is_on_stack = object_is_on_stack(buf);
38961+ is_on_stack = object_starts_on_stack(buf);
38962 if (is_on_stack) {
38963 /*
38964 * dma onto stack is unsafe/nonportable, but callers to this
38965diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
38966index 53b8fd9..615b462 100644
38967--- a/drivers/mmc/host/dw_mmc.h
38968+++ b/drivers/mmc/host/dw_mmc.h
38969@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
38970 int (*parse_dt)(struct dw_mci *host);
38971 int (*setup_bus)(struct dw_mci *host,
38972 struct device_node *slot_np, u8 bus_width);
38973-};
38974+} __do_const;
38975 #endif /* _DW_MMC_H_ */
38976diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
38977index 82a8de1..3c56ccb 100644
38978--- a/drivers/mmc/host/sdhci-s3c.c
38979+++ b/drivers/mmc/host/sdhci-s3c.c
38980@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
38981 * we can use overriding functions instead of default.
38982 */
38983 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
38984- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
38985- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
38986- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
38987+ pax_open_kernel();
38988+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
38989+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
38990+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
38991+ pax_close_kernel();
38992 }
38993
38994 /* It supports additional host capabilities if needed */
38995diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
38996index a4eb8b5..8c0628f 100644
38997--- a/drivers/mtd/devices/doc2000.c
38998+++ b/drivers/mtd/devices/doc2000.c
38999@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39000
39001 /* The ECC will not be calculated correctly if less than 512 is written */
39002 /* DBB-
39003- if (len != 0x200 && eccbuf)
39004+ if (len != 0x200)
39005 printk(KERN_WARNING
39006 "ECC needs a full sector write (adr: %lx size %lx)\n",
39007 (long) to, (long) len);
39008diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39009index 0c8bb6b..6f35deb 100644
39010--- a/drivers/mtd/nand/denali.c
39011+++ b/drivers/mtd/nand/denali.c
39012@@ -24,6 +24,7 @@
39013 #include <linux/slab.h>
39014 #include <linux/mtd/mtd.h>
39015 #include <linux/module.h>
39016+#include <linux/slab.h>
39017
39018 #include "denali.h"
39019
39020diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39021index 51b9d6a..52af9a7 100644
39022--- a/drivers/mtd/nftlmount.c
39023+++ b/drivers/mtd/nftlmount.c
39024@@ -24,6 +24,7 @@
39025 #include <asm/errno.h>
39026 #include <linux/delay.h>
39027 #include <linux/slab.h>
39028+#include <linux/sched.h>
39029 #include <linux/mtd/mtd.h>
39030 #include <linux/mtd/nand.h>
39031 #include <linux/mtd/nftl.h>
39032diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39033index 8dd6ba5..419cc1d 100644
39034--- a/drivers/mtd/sm_ftl.c
39035+++ b/drivers/mtd/sm_ftl.c
39036@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39037 #define SM_CIS_VENDOR_OFFSET 0x59
39038 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39039 {
39040- struct attribute_group *attr_group;
39041+ attribute_group_no_const *attr_group;
39042 struct attribute **attributes;
39043 struct sm_sysfs_attribute *vendor_attribute;
39044
39045diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39046index b7d45f3..b5c89d9 100644
39047--- a/drivers/net/bonding/bond_main.c
39048+++ b/drivers/net/bonding/bond_main.c
39049@@ -4861,7 +4861,7 @@ static unsigned int bond_get_num_tx_queues(void)
39050 return tx_queues;
39051 }
39052
39053-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39054+static struct rtnl_link_ops bond_link_ops = {
39055 .kind = "bond",
39056 .priv_size = sizeof(struct bonding),
39057 .setup = bond_setup,
39058diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39059index 70dba5d..11a0919 100644
39060--- a/drivers/net/ethernet/8390/ax88796.c
39061+++ b/drivers/net/ethernet/8390/ax88796.c
39062@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39063 if (ax->plat->reg_offsets)
39064 ei_local->reg_offset = ax->plat->reg_offsets;
39065 else {
39066+ resource_size_t _mem_size = mem_size;
39067+ do_div(_mem_size, 0x18);
39068 ei_local->reg_offset = ax->reg_offsets;
39069 for (ret = 0; ret < 0x18; ret++)
39070- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39071+ ax->reg_offsets[ret] = _mem_size * ret;
39072 }
39073
39074 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39075diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39076index 0991534..8098e92 100644
39077--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39078+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39079@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39080 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39081 {
39082 /* RX_MODE controlling object */
39083- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39084+ bnx2x_init_rx_mode_obj(bp);
39085
39086 /* multicast configuration controlling object */
39087 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39088diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39089index 09b625e..15b16fe 100644
39090--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39091+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39092@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39093 return rc;
39094 }
39095
39096-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39097- struct bnx2x_rx_mode_obj *o)
39098+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39099 {
39100 if (CHIP_IS_E1x(bp)) {
39101- o->wait_comp = bnx2x_empty_rx_mode_wait;
39102- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39103+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39104+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39105 } else {
39106- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39107- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39108+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39109+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39110 }
39111 }
39112
39113diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39114index adbd91b..58ec94a 100644
39115--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39116+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39117@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39118
39119 /********************* RX MODE ****************/
39120
39121-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39122- struct bnx2x_rx_mode_obj *o);
39123+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39124
39125 /**
39126 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39127diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39128index d330e81..ce1fb9a 100644
39129--- a/drivers/net/ethernet/broadcom/tg3.h
39130+++ b/drivers/net/ethernet/broadcom/tg3.h
39131@@ -146,6 +146,7 @@
39132 #define CHIPREV_ID_5750_A0 0x4000
39133 #define CHIPREV_ID_5750_A1 0x4001
39134 #define CHIPREV_ID_5750_A3 0x4003
39135+#define CHIPREV_ID_5750_C1 0x4201
39136 #define CHIPREV_ID_5750_C2 0x4202
39137 #define CHIPREV_ID_5752_A0_HW 0x5000
39138 #define CHIPREV_ID_5752_A0 0x6000
39139diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39140index 8cffcdf..aadf043 100644
39141--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39142+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39143@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39144 */
39145 struct l2t_skb_cb {
39146 arp_failure_handler_func arp_failure_handler;
39147-};
39148+} __no_const;
39149
39150 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39151
39152diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39153index 4c83003..2a2a5b9 100644
39154--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39155+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39156@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39157 for (i=0; i<ETH_ALEN; i++) {
39158 tmp.addr[i] = dev->dev_addr[i];
39159 }
39160- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39161+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39162 break;
39163
39164 case DE4X5_SET_HWADDR: /* Set the hardware address */
39165@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39166 spin_lock_irqsave(&lp->lock, flags);
39167 memcpy(&statbuf, &lp->pktStats, ioc->len);
39168 spin_unlock_irqrestore(&lp->lock, flags);
39169- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39170+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39171 return -EFAULT;
39172 break;
39173 }
39174diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39175index 4d6f3c5..6169e60 100644
39176--- a/drivers/net/ethernet/emulex/benet/be_main.c
39177+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39178@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39179
39180 if (wrapped)
39181 newacc += 65536;
39182- ACCESS_ONCE(*acc) = newacc;
39183+ ACCESS_ONCE_RW(*acc) = newacc;
39184 }
39185
39186 void be_parse_stats(struct be_adapter *adapter)
39187diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39188index 74d749e..eefb1bd 100644
39189--- a/drivers/net/ethernet/faraday/ftgmac100.c
39190+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39191@@ -31,6 +31,8 @@
39192 #include <linux/netdevice.h>
39193 #include <linux/phy.h>
39194 #include <linux/platform_device.h>
39195+#include <linux/interrupt.h>
39196+#include <linux/irqreturn.h>
39197 #include <net/ip.h>
39198
39199 #include "ftgmac100.h"
39200diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39201index b901a01..1ff32ee 100644
39202--- a/drivers/net/ethernet/faraday/ftmac100.c
39203+++ b/drivers/net/ethernet/faraday/ftmac100.c
39204@@ -31,6 +31,8 @@
39205 #include <linux/module.h>
39206 #include <linux/netdevice.h>
39207 #include <linux/platform_device.h>
39208+#include <linux/interrupt.h>
39209+#include <linux/irqreturn.h>
39210
39211 #include "ftmac100.h"
39212
39213diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39214index bb9256a..56d8752 100644
39215--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39216+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39217@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
39218 }
39219
39220 /* update the base incval used to calculate frequency adjustment */
39221- ACCESS_ONCE(adapter->base_incval) = incval;
39222+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
39223 smp_mb();
39224
39225 /* need lock to prevent incorrect read while modifying cyclecounter */
39226diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39227index fbe5363..266b4e3 100644
39228--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
39229+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39230@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39231 struct __vxge_hw_fifo *fifo;
39232 struct vxge_hw_fifo_config *config;
39233 u32 txdl_size, txdl_per_memblock;
39234- struct vxge_hw_mempool_cbs fifo_mp_callback;
39235+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
39236+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
39237+ };
39238+
39239 struct __vxge_hw_virtualpath *vpath;
39240
39241 if ((vp == NULL) || (attr == NULL)) {
39242@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39243 goto exit;
39244 }
39245
39246- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
39247-
39248 fifo->mempool =
39249 __vxge_hw_mempool_create(vpath->hldev,
39250 fifo->config->memblock_size,
39251diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
39252index 998974f..ecd26db 100644
39253--- a/drivers/net/ethernet/realtek/r8169.c
39254+++ b/drivers/net/ethernet/realtek/r8169.c
39255@@ -741,22 +741,22 @@ struct rtl8169_private {
39256 struct mdio_ops {
39257 void (*write)(struct rtl8169_private *, int, int);
39258 int (*read)(struct rtl8169_private *, int);
39259- } mdio_ops;
39260+ } __no_const mdio_ops;
39261
39262 struct pll_power_ops {
39263 void (*down)(struct rtl8169_private *);
39264 void (*up)(struct rtl8169_private *);
39265- } pll_power_ops;
39266+ } __no_const pll_power_ops;
39267
39268 struct jumbo_ops {
39269 void (*enable)(struct rtl8169_private *);
39270 void (*disable)(struct rtl8169_private *);
39271- } jumbo_ops;
39272+ } __no_const jumbo_ops;
39273
39274 struct csi_ops {
39275 void (*write)(struct rtl8169_private *, int, int);
39276 u32 (*read)(struct rtl8169_private *, int);
39277- } csi_ops;
39278+ } __no_const csi_ops;
39279
39280 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
39281 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
39282diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
39283index 0767043f..08c2553 100644
39284--- a/drivers/net/ethernet/sfc/ptp.c
39285+++ b/drivers/net/ethernet/sfc/ptp.c
39286@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
39287 (u32)((u64)ptp->start.dma_addr >> 32));
39288
39289 /* Clear flag that signals MC ready */
39290- ACCESS_ONCE(*start) = 0;
39291+ ACCESS_ONCE_RW(*start) = 0;
39292 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
39293 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
39294
39295diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39296index 0c74a70..3bc6f68 100644
39297--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39298+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39299@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
39300
39301 writel(value, ioaddr + MMC_CNTRL);
39302
39303- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39304- MMC_CNTRL, value);
39305+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39306+// MMC_CNTRL, value);
39307 }
39308
39309 /* To mask all all interrupts.*/
39310diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
39311index e6fe0d8..2b7d752 100644
39312--- a/drivers/net/hyperv/hyperv_net.h
39313+++ b/drivers/net/hyperv/hyperv_net.h
39314@@ -101,7 +101,7 @@ struct rndis_device {
39315
39316 enum rndis_device_state state;
39317 bool link_state;
39318- atomic_t new_req_id;
39319+ atomic_unchecked_t new_req_id;
39320
39321 spinlock_t request_lock;
39322 struct list_head req_list;
39323diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
39324index 2b657d4..9903bc0 100644
39325--- a/drivers/net/hyperv/rndis_filter.c
39326+++ b/drivers/net/hyperv/rndis_filter.c
39327@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
39328 * template
39329 */
39330 set = &rndis_msg->msg.set_req;
39331- set->req_id = atomic_inc_return(&dev->new_req_id);
39332+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39333
39334 /* Add to the request list */
39335 spin_lock_irqsave(&dev->request_lock, flags);
39336@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
39337
39338 /* Setup the rndis set */
39339 halt = &request->request_msg.msg.halt_req;
39340- halt->req_id = atomic_inc_return(&dev->new_req_id);
39341+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39342
39343 /* Ignore return since this msg is optional. */
39344 rndis_filter_send_request(dev, request);
39345diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
39346index 1e9cb0b..7839125 100644
39347--- a/drivers/net/ieee802154/fakehard.c
39348+++ b/drivers/net/ieee802154/fakehard.c
39349@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
39350 phy->transmit_power = 0xbf;
39351
39352 dev->netdev_ops = &fake_ops;
39353- dev->ml_priv = &fake_mlme;
39354+ dev->ml_priv = (void *)&fake_mlme;
39355
39356 priv = netdev_priv(dev);
39357 priv->phy = phy;
39358diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39359index d3fb97d..19520c7 100644
39360--- a/drivers/net/macvlan.c
39361+++ b/drivers/net/macvlan.c
39362@@ -851,13 +851,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39363 int macvlan_link_register(struct rtnl_link_ops *ops)
39364 {
39365 /* common fields */
39366- ops->priv_size = sizeof(struct macvlan_dev);
39367- ops->validate = macvlan_validate;
39368- ops->maxtype = IFLA_MACVLAN_MAX;
39369- ops->policy = macvlan_policy;
39370- ops->changelink = macvlan_changelink;
39371- ops->get_size = macvlan_get_size;
39372- ops->fill_info = macvlan_fill_info;
39373+ pax_open_kernel();
39374+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39375+ *(void **)&ops->validate = macvlan_validate;
39376+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39377+ *(const void **)&ops->policy = macvlan_policy;
39378+ *(void **)&ops->changelink = macvlan_changelink;
39379+ *(void **)&ops->get_size = macvlan_get_size;
39380+ *(void **)&ops->fill_info = macvlan_fill_info;
39381+ pax_close_kernel();
39382
39383 return rtnl_link_register(ops);
39384 };
39385@@ -913,7 +915,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39386 return NOTIFY_DONE;
39387 }
39388
39389-static struct notifier_block macvlan_notifier_block __read_mostly = {
39390+static struct notifier_block macvlan_notifier_block = {
39391 .notifier_call = macvlan_device_event,
39392 };
39393
39394diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39395index 0f0f9ce..0ca5819 100644
39396--- a/drivers/net/macvtap.c
39397+++ b/drivers/net/macvtap.c
39398@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39399 return NOTIFY_DONE;
39400 }
39401
39402-static struct notifier_block macvtap_notifier_block __read_mostly = {
39403+static struct notifier_block macvtap_notifier_block = {
39404 .notifier_call = macvtap_device_event,
39405 };
39406
39407diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39408index daec9b0..6428fcb 100644
39409--- a/drivers/net/phy/mdio-bitbang.c
39410+++ b/drivers/net/phy/mdio-bitbang.c
39411@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39412 struct mdiobb_ctrl *ctrl = bus->priv;
39413
39414 module_put(ctrl->ops->owner);
39415+ mdiobus_unregister(bus);
39416 mdiobus_free(bus);
39417 }
39418 EXPORT_SYMBOL(free_mdio_bitbang);
39419diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39420index 508570e..f706dc7 100644
39421--- a/drivers/net/ppp/ppp_generic.c
39422+++ b/drivers/net/ppp/ppp_generic.c
39423@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39424 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39425 struct ppp_stats stats;
39426 struct ppp_comp_stats cstats;
39427- char *vers;
39428
39429 switch (cmd) {
39430 case SIOCGPPPSTATS:
39431@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39432 break;
39433
39434 case SIOCGPPPVER:
39435- vers = PPP_VERSION;
39436- if (copy_to_user(addr, vers, strlen(vers) + 1))
39437+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39438 break;
39439 err = 0;
39440 break;
39441diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
39442index ad86660..9fd0884 100644
39443--- a/drivers/net/team/team.c
39444+++ b/drivers/net/team/team.c
39445@@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
39446 return NOTIFY_DONE;
39447 }
39448
39449-static struct notifier_block team_notifier_block __read_mostly = {
39450+static struct notifier_block team_notifier_block = {
39451 .notifier_call = team_device_event,
39452 };
39453
39454diff --git a/drivers/net/tun.c b/drivers/net/tun.c
39455index 2917a86..edd463f 100644
39456--- a/drivers/net/tun.c
39457+++ b/drivers/net/tun.c
39458@@ -1836,7 +1836,7 @@ unlock:
39459 }
39460
39461 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39462- unsigned long arg, int ifreq_len)
39463+ unsigned long arg, size_t ifreq_len)
39464 {
39465 struct tun_file *tfile = file->private_data;
39466 struct tun_struct *tun;
39467@@ -1848,6 +1848,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39468 int vnet_hdr_sz;
39469 int ret;
39470
39471+ if (ifreq_len > sizeof ifr)
39472+ return -EFAULT;
39473+
39474 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
39475 if (copy_from_user(&ifr, argp, ifreq_len))
39476 return -EFAULT;
39477diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39478index cd8ccb2..cff5144 100644
39479--- a/drivers/net/usb/hso.c
39480+++ b/drivers/net/usb/hso.c
39481@@ -71,7 +71,7 @@
39482 #include <asm/byteorder.h>
39483 #include <linux/serial_core.h>
39484 #include <linux/serial.h>
39485-
39486+#include <asm/local.h>
39487
39488 #define MOD_AUTHOR "Option Wireless"
39489 #define MOD_DESCRIPTION "USB High Speed Option driver"
39490@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39491 struct urb *urb;
39492
39493 urb = serial->rx_urb[0];
39494- if (serial->port.count > 0) {
39495+ if (atomic_read(&serial->port.count) > 0) {
39496 count = put_rxbuf_data(urb, serial);
39497 if (count == -1)
39498 return;
39499@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39500 DUMP1(urb->transfer_buffer, urb->actual_length);
39501
39502 /* Anyone listening? */
39503- if (serial->port.count == 0)
39504+ if (atomic_read(&serial->port.count) == 0)
39505 return;
39506
39507 if (status == 0) {
39508@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39509 tty_port_tty_set(&serial->port, tty);
39510
39511 /* check for port already opened, if not set the termios */
39512- serial->port.count++;
39513- if (serial->port.count == 1) {
39514+ if (atomic_inc_return(&serial->port.count) == 1) {
39515 serial->rx_state = RX_IDLE;
39516 /* Force default termio settings */
39517 _hso_serial_set_termios(tty, NULL);
39518@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39519 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39520 if (result) {
39521 hso_stop_serial_device(serial->parent);
39522- serial->port.count--;
39523+ atomic_dec(&serial->port.count);
39524 kref_put(&serial->parent->ref, hso_serial_ref_free);
39525 }
39526 } else {
39527@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39528
39529 /* reset the rts and dtr */
39530 /* do the actual close */
39531- serial->port.count--;
39532+ atomic_dec(&serial->port.count);
39533
39534- if (serial->port.count <= 0) {
39535- serial->port.count = 0;
39536+ if (atomic_read(&serial->port.count) <= 0) {
39537+ atomic_set(&serial->port.count, 0);
39538 tty_port_tty_set(&serial->port, NULL);
39539 if (!usb_gone)
39540 hso_stop_serial_device(serial->parent);
39541@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39542
39543 /* the actual setup */
39544 spin_lock_irqsave(&serial->serial_lock, flags);
39545- if (serial->port.count)
39546+ if (atomic_read(&serial->port.count))
39547 _hso_serial_set_termios(tty, old);
39548 else
39549 tty->termios = *old;
39550@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
39551 D1("Pending read interrupt on port %d\n", i);
39552 spin_lock(&serial->serial_lock);
39553 if (serial->rx_state == RX_IDLE &&
39554- serial->port.count > 0) {
39555+ atomic_read(&serial->port.count) > 0) {
39556 /* Setup and send a ctrl req read on
39557 * port i */
39558 if (!serial->rx_urb_filled[0]) {
39559@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
39560 /* Start all serial ports */
39561 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39562 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39563- if (dev2ser(serial_table[i])->port.count) {
39564+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
39565 result =
39566 hso_start_serial_device(serial_table[i], GFP_NOIO);
39567 hso_kick_transmit(dev2ser(serial_table[i]));
39568diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
39569index 656230e..15525a8 100644
39570--- a/drivers/net/vxlan.c
39571+++ b/drivers/net/vxlan.c
39572@@ -1428,7 +1428,7 @@ nla_put_failure:
39573 return -EMSGSIZE;
39574 }
39575
39576-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
39577+static struct rtnl_link_ops vxlan_link_ops = {
39578 .kind = "vxlan",
39579 .maxtype = IFLA_VXLAN_MAX,
39580 .policy = vxlan_policy,
39581diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
39582index 77fa428..996b355 100644
39583--- a/drivers/net/wireless/at76c50x-usb.c
39584+++ b/drivers/net/wireless/at76c50x-usb.c
39585@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
39586 }
39587
39588 /* Convert timeout from the DFU status to jiffies */
39589-static inline unsigned long at76_get_timeout(struct dfu_status *s)
39590+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
39591 {
39592 return msecs_to_jiffies((s->poll_timeout[2] << 16)
39593 | (s->poll_timeout[1] << 8)
39594diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39595index 8d78253..bebbb68 100644
39596--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39597+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39598@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39599 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
39600 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
39601
39602- ACCESS_ONCE(ads->ds_link) = i->link;
39603- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
39604+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
39605+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
39606
39607 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
39608 ctl6 = SM(i->keytype, AR_EncrType);
39609@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39610
39611 if ((i->is_first || i->is_last) &&
39612 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
39613- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
39614+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
39615 | set11nTries(i->rates, 1)
39616 | set11nTries(i->rates, 2)
39617 | set11nTries(i->rates, 3)
39618 | (i->dur_update ? AR_DurUpdateEna : 0)
39619 | SM(0, AR_BurstDur);
39620
39621- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
39622+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
39623 | set11nRate(i->rates, 1)
39624 | set11nRate(i->rates, 2)
39625 | set11nRate(i->rates, 3);
39626 } else {
39627- ACCESS_ONCE(ads->ds_ctl2) = 0;
39628- ACCESS_ONCE(ads->ds_ctl3) = 0;
39629+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
39630+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
39631 }
39632
39633 if (!i->is_first) {
39634- ACCESS_ONCE(ads->ds_ctl0) = 0;
39635- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39636- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39637+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
39638+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39639+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39640 return;
39641 }
39642
39643@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39644 break;
39645 }
39646
39647- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39648+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39649 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39650 | SM(i->txpower, AR_XmitPower)
39651 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39652@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39653 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
39654 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
39655
39656- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39657- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39658+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39659+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39660
39661 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
39662 return;
39663
39664- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39665+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39666 | set11nPktDurRTSCTS(i->rates, 1);
39667
39668- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39669+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39670 | set11nPktDurRTSCTS(i->rates, 3);
39671
39672- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39673+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39674 | set11nRateFlags(i->rates, 1)
39675 | set11nRateFlags(i->rates, 2)
39676 | set11nRateFlags(i->rates, 3)
39677diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39678index 301bf72..3f5654f 100644
39679--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39680+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39681@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39682 (i->qcu << AR_TxQcuNum_S) | desc_len;
39683
39684 checksum += val;
39685- ACCESS_ONCE(ads->info) = val;
39686+ ACCESS_ONCE_RW(ads->info) = val;
39687
39688 checksum += i->link;
39689- ACCESS_ONCE(ads->link) = i->link;
39690+ ACCESS_ONCE_RW(ads->link) = i->link;
39691
39692 checksum += i->buf_addr[0];
39693- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
39694+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
39695 checksum += i->buf_addr[1];
39696- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
39697+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
39698 checksum += i->buf_addr[2];
39699- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
39700+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
39701 checksum += i->buf_addr[3];
39702- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
39703+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
39704
39705 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
39706- ACCESS_ONCE(ads->ctl3) = val;
39707+ ACCESS_ONCE_RW(ads->ctl3) = val;
39708 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
39709- ACCESS_ONCE(ads->ctl5) = val;
39710+ ACCESS_ONCE_RW(ads->ctl5) = val;
39711 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
39712- ACCESS_ONCE(ads->ctl7) = val;
39713+ ACCESS_ONCE_RW(ads->ctl7) = val;
39714 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
39715- ACCESS_ONCE(ads->ctl9) = val;
39716+ ACCESS_ONCE_RW(ads->ctl9) = val;
39717
39718 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
39719- ACCESS_ONCE(ads->ctl10) = checksum;
39720+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
39721
39722 if (i->is_first || i->is_last) {
39723- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
39724+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
39725 | set11nTries(i->rates, 1)
39726 | set11nTries(i->rates, 2)
39727 | set11nTries(i->rates, 3)
39728 | (i->dur_update ? AR_DurUpdateEna : 0)
39729 | SM(0, AR_BurstDur);
39730
39731- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
39732+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
39733 | set11nRate(i->rates, 1)
39734 | set11nRate(i->rates, 2)
39735 | set11nRate(i->rates, 3);
39736 } else {
39737- ACCESS_ONCE(ads->ctl13) = 0;
39738- ACCESS_ONCE(ads->ctl14) = 0;
39739+ ACCESS_ONCE_RW(ads->ctl13) = 0;
39740+ ACCESS_ONCE_RW(ads->ctl14) = 0;
39741 }
39742
39743 ads->ctl20 = 0;
39744@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39745
39746 ctl17 = SM(i->keytype, AR_EncrType);
39747 if (!i->is_first) {
39748- ACCESS_ONCE(ads->ctl11) = 0;
39749- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39750- ACCESS_ONCE(ads->ctl15) = 0;
39751- ACCESS_ONCE(ads->ctl16) = 0;
39752- ACCESS_ONCE(ads->ctl17) = ctl17;
39753- ACCESS_ONCE(ads->ctl18) = 0;
39754- ACCESS_ONCE(ads->ctl19) = 0;
39755+ ACCESS_ONCE_RW(ads->ctl11) = 0;
39756+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39757+ ACCESS_ONCE_RW(ads->ctl15) = 0;
39758+ ACCESS_ONCE_RW(ads->ctl16) = 0;
39759+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39760+ ACCESS_ONCE_RW(ads->ctl18) = 0;
39761+ ACCESS_ONCE_RW(ads->ctl19) = 0;
39762 return;
39763 }
39764
39765- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39766+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39767 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39768 | SM(i->txpower, AR_XmitPower)
39769 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39770@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39771 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
39772 ctl12 |= SM(val, AR_PAPRDChainMask);
39773
39774- ACCESS_ONCE(ads->ctl12) = ctl12;
39775- ACCESS_ONCE(ads->ctl17) = ctl17;
39776+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
39777+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39778
39779- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39780+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39781 | set11nPktDurRTSCTS(i->rates, 1);
39782
39783- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39784+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39785 | set11nPktDurRTSCTS(i->rates, 3);
39786
39787- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
39788+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
39789 | set11nRateFlags(i->rates, 1)
39790 | set11nRateFlags(i->rates, 2)
39791 | set11nRateFlags(i->rates, 3)
39792 | SM(i->rtscts_rate, AR_RTSCTSRate);
39793
39794- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
39795+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
39796 }
39797
39798 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
39799diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
39800index 9d26fc5..60d9f14 100644
39801--- a/drivers/net/wireless/ath/ath9k/hw.h
39802+++ b/drivers/net/wireless/ath/ath9k/hw.h
39803@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
39804
39805 /* ANI */
39806 void (*ani_cache_ini_regs)(struct ath_hw *ah);
39807-};
39808+} __no_const;
39809
39810 /**
39811 * struct ath_hw_ops - callbacks used by hardware code and driver code
39812@@ -688,7 +688,7 @@ struct ath_hw_ops {
39813 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
39814 struct ath_hw_antcomb_conf *antconf);
39815 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
39816-};
39817+} __no_const;
39818
39819 struct ath_nf_limits {
39820 s16 max;
39821diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
39822index 3726cd6..b655808 100644
39823--- a/drivers/net/wireless/iwlegacy/3945-mac.c
39824+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
39825@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39826 */
39827 if (il3945_mod_params.disable_hw_scan) {
39828 D_INFO("Disabling hw_scan\n");
39829- il3945_mac_ops.hw_scan = NULL;
39830+ pax_open_kernel();
39831+ *(void **)&il3945_mac_ops.hw_scan = NULL;
39832+ pax_close_kernel();
39833 }
39834
39835 D_INFO("*** LOAD DRIVER ***\n");
39836diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39837index 5b9533e..7733880 100644
39838--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39839+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39840@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
39841 {
39842 struct iwl_priv *priv = file->private_data;
39843 char buf[64];
39844- int buf_size;
39845+ size_t buf_size;
39846 u32 offset, len;
39847
39848 memset(buf, 0, sizeof(buf));
39849@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
39850 struct iwl_priv *priv = file->private_data;
39851
39852 char buf[8];
39853- int buf_size;
39854+ size_t buf_size;
39855 u32 reset_flag;
39856
39857 memset(buf, 0, sizeof(buf));
39858@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
39859 {
39860 struct iwl_priv *priv = file->private_data;
39861 char buf[8];
39862- int buf_size;
39863+ size_t buf_size;
39864 int ht40;
39865
39866 memset(buf, 0, sizeof(buf));
39867@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
39868 {
39869 struct iwl_priv *priv = file->private_data;
39870 char buf[8];
39871- int buf_size;
39872+ size_t buf_size;
39873 int value;
39874
39875 memset(buf, 0, sizeof(buf));
39876@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
39877 {
39878 struct iwl_priv *priv = file->private_data;
39879 char buf[8];
39880- int buf_size;
39881+ size_t buf_size;
39882 int clear;
39883
39884 memset(buf, 0, sizeof(buf));
39885@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
39886 {
39887 struct iwl_priv *priv = file->private_data;
39888 char buf[8];
39889- int buf_size;
39890+ size_t buf_size;
39891 int trace;
39892
39893 memset(buf, 0, sizeof(buf));
39894@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
39895 {
39896 struct iwl_priv *priv = file->private_data;
39897 char buf[8];
39898- int buf_size;
39899+ size_t buf_size;
39900 int missed;
39901
39902 memset(buf, 0, sizeof(buf));
39903@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
39904
39905 struct iwl_priv *priv = file->private_data;
39906 char buf[8];
39907- int buf_size;
39908+ size_t buf_size;
39909 int plcp;
39910
39911 memset(buf, 0, sizeof(buf));
39912@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
39913
39914 struct iwl_priv *priv = file->private_data;
39915 char buf[8];
39916- int buf_size;
39917+ size_t buf_size;
39918 int flush;
39919
39920 memset(buf, 0, sizeof(buf));
39921@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
39922
39923 struct iwl_priv *priv = file->private_data;
39924 char buf[8];
39925- int buf_size;
39926+ size_t buf_size;
39927 int rts;
39928
39929 if (!priv->cfg->ht_params)
39930@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
39931 {
39932 struct iwl_priv *priv = file->private_data;
39933 char buf[8];
39934- int buf_size;
39935+ size_t buf_size;
39936
39937 memset(buf, 0, sizeof(buf));
39938 buf_size = min(count, sizeof(buf) - 1);
39939@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
39940 struct iwl_priv *priv = file->private_data;
39941 u32 event_log_flag;
39942 char buf[8];
39943- int buf_size;
39944+ size_t buf_size;
39945
39946 /* check that the interface is up */
39947 if (!iwl_is_ready(priv))
39948@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
39949 struct iwl_priv *priv = file->private_data;
39950 char buf[8];
39951 u32 calib_disabled;
39952- int buf_size;
39953+ size_t buf_size;
39954
39955 memset(buf, 0, sizeof(buf));
39956 buf_size = min(count, sizeof(buf) - 1);
39957diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
39958index 35708b9..31f7754 100644
39959--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
39960+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
39961@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
39962 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
39963
39964 char buf[8];
39965- int buf_size;
39966+ size_t buf_size;
39967 u32 reset_flag;
39968
39969 memset(buf, 0, sizeof(buf));
39970@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
39971 {
39972 struct iwl_trans *trans = file->private_data;
39973 char buf[8];
39974- int buf_size;
39975+ size_t buf_size;
39976 int csr;
39977
39978 memset(buf, 0, sizeof(buf));
39979diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
39980index ff90855..e46d223 100644
39981--- a/drivers/net/wireless/mac80211_hwsim.c
39982+++ b/drivers/net/wireless/mac80211_hwsim.c
39983@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
39984
39985 if (channels > 1) {
39986 hwsim_if_comb.num_different_channels = channels;
39987- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
39988- mac80211_hwsim_ops.cancel_hw_scan =
39989- mac80211_hwsim_cancel_hw_scan;
39990- mac80211_hwsim_ops.sw_scan_start = NULL;
39991- mac80211_hwsim_ops.sw_scan_complete = NULL;
39992- mac80211_hwsim_ops.remain_on_channel =
39993- mac80211_hwsim_roc;
39994- mac80211_hwsim_ops.cancel_remain_on_channel =
39995- mac80211_hwsim_croc;
39996- mac80211_hwsim_ops.add_chanctx =
39997- mac80211_hwsim_add_chanctx;
39998- mac80211_hwsim_ops.remove_chanctx =
39999- mac80211_hwsim_remove_chanctx;
40000- mac80211_hwsim_ops.change_chanctx =
40001- mac80211_hwsim_change_chanctx;
40002- mac80211_hwsim_ops.assign_vif_chanctx =
40003- mac80211_hwsim_assign_vif_chanctx;
40004- mac80211_hwsim_ops.unassign_vif_chanctx =
40005- mac80211_hwsim_unassign_vif_chanctx;
40006+ pax_open_kernel();
40007+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40008+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40009+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40010+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40011+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40012+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40013+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40014+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40015+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40016+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40017+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40018+ pax_close_kernel();
40019 }
40020
40021 spin_lock_init(&hwsim_radio_lock);
40022diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40023index abe1d03..fb02c22 100644
40024--- a/drivers/net/wireless/rndis_wlan.c
40025+++ b/drivers/net/wireless/rndis_wlan.c
40026@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40027
40028 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40029
40030- if (rts_threshold < 0 || rts_threshold > 2347)
40031+ if (rts_threshold > 2347)
40032 rts_threshold = 2347;
40033
40034 tmp = cpu_to_le32(rts_threshold);
40035diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40036index 0751b35..246ba3e 100644
40037--- a/drivers/net/wireless/rt2x00/rt2x00.h
40038+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40039@@ -398,7 +398,7 @@ struct rt2x00_intf {
40040 * for hardware which doesn't support hardware
40041 * sequence counting.
40042 */
40043- atomic_t seqno;
40044+ atomic_unchecked_t seqno;
40045 };
40046
40047 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40048diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40049index e488b94..14b6a0c 100644
40050--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40051+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40052@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40053 * sequence counter given by mac80211.
40054 */
40055 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40056- seqno = atomic_add_return(0x10, &intf->seqno);
40057+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40058 else
40059- seqno = atomic_read(&intf->seqno);
40060+ seqno = atomic_read_unchecked(&intf->seqno);
40061
40062 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40063 hdr->seq_ctrl |= cpu_to_le16(seqno);
40064diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40065index e57ee48..541cf6c 100644
40066--- a/drivers/net/wireless/ti/wl1251/sdio.c
40067+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40068@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40069
40070 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40071
40072- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40073- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40074+ pax_open_kernel();
40075+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40076+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40077+ pax_close_kernel();
40078
40079 wl1251_info("using dedicated interrupt line");
40080 } else {
40081- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40082- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40083+ pax_open_kernel();
40084+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40085+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40086+ pax_close_kernel();
40087
40088 wl1251_info("using SDIO interrupt");
40089 }
40090diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
40091index e5f5f8f..fdf15b7 100644
40092--- a/drivers/net/wireless/ti/wl12xx/main.c
40093+++ b/drivers/net/wireless/ti/wl12xx/main.c
40094@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40095 sizeof(wl->conf.mem));
40096
40097 /* read data preparation is only needed by wl127x */
40098- wl->ops->prepare_read = wl127x_prepare_read;
40099+ pax_open_kernel();
40100+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40101+ pax_close_kernel();
40102
40103 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40104 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40105@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40106 sizeof(wl->conf.mem));
40107
40108 /* read data preparation is only needed by wl127x */
40109- wl->ops->prepare_read = wl127x_prepare_read;
40110+ pax_open_kernel();
40111+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40112+ pax_close_kernel();
40113
40114 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
40115 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
40116diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
40117index 8d8c1f8..e754844 100644
40118--- a/drivers/net/wireless/ti/wl18xx/main.c
40119+++ b/drivers/net/wireless/ti/wl18xx/main.c
40120@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
40121 }
40122
40123 if (!checksum_param) {
40124- wl18xx_ops.set_rx_csum = NULL;
40125- wl18xx_ops.init_vif = NULL;
40126+ pax_open_kernel();
40127+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
40128+ *(void **)&wl18xx_ops.init_vif = NULL;
40129+ pax_close_kernel();
40130 }
40131
40132 /* Enable 11a Band only if we have 5G antennas */
40133diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
40134index d93b2b6..ae50401 100644
40135--- a/drivers/oprofile/buffer_sync.c
40136+++ b/drivers/oprofile/buffer_sync.c
40137@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
40138 if (cookie == NO_COOKIE)
40139 offset = pc;
40140 if (cookie == INVALID_COOKIE) {
40141- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40142+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40143 offset = pc;
40144 }
40145 if (cookie != last_cookie) {
40146@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
40147 /* add userspace sample */
40148
40149 if (!mm) {
40150- atomic_inc(&oprofile_stats.sample_lost_no_mm);
40151+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
40152 return 0;
40153 }
40154
40155 cookie = lookup_dcookie(mm, s->eip, &offset);
40156
40157 if (cookie == INVALID_COOKIE) {
40158- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40159+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40160 return 0;
40161 }
40162
40163@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
40164 /* ignore backtraces if failed to add a sample */
40165 if (state == sb_bt_start) {
40166 state = sb_bt_ignore;
40167- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
40168+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
40169 }
40170 }
40171 release_mm(mm);
40172diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
40173index c0cc4e7..44d4e54 100644
40174--- a/drivers/oprofile/event_buffer.c
40175+++ b/drivers/oprofile/event_buffer.c
40176@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
40177 }
40178
40179 if (buffer_pos == buffer_size) {
40180- atomic_inc(&oprofile_stats.event_lost_overflow);
40181+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
40182 return;
40183 }
40184
40185diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
40186index ed2c3ec..deda85a 100644
40187--- a/drivers/oprofile/oprof.c
40188+++ b/drivers/oprofile/oprof.c
40189@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
40190 if (oprofile_ops.switch_events())
40191 return;
40192
40193- atomic_inc(&oprofile_stats.multiplex_counter);
40194+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
40195 start_switch_worker();
40196 }
40197
40198diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
40199index 84a208d..d61b0a1 100644
40200--- a/drivers/oprofile/oprofile_files.c
40201+++ b/drivers/oprofile/oprofile_files.c
40202@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
40203
40204 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
40205
40206-static ssize_t timeout_read(struct file *file, char __user *buf,
40207+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
40208 size_t count, loff_t *offset)
40209 {
40210 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
40211diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
40212index 917d28e..d62d981 100644
40213--- a/drivers/oprofile/oprofile_stats.c
40214+++ b/drivers/oprofile/oprofile_stats.c
40215@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
40216 cpu_buf->sample_invalid_eip = 0;
40217 }
40218
40219- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
40220- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
40221- atomic_set(&oprofile_stats.event_lost_overflow, 0);
40222- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
40223- atomic_set(&oprofile_stats.multiplex_counter, 0);
40224+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
40225+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
40226+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
40227+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
40228+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
40229 }
40230
40231
40232diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
40233index 38b6fc0..b5cbfce 100644
40234--- a/drivers/oprofile/oprofile_stats.h
40235+++ b/drivers/oprofile/oprofile_stats.h
40236@@ -13,11 +13,11 @@
40237 #include <linux/atomic.h>
40238
40239 struct oprofile_stat_struct {
40240- atomic_t sample_lost_no_mm;
40241- atomic_t sample_lost_no_mapping;
40242- atomic_t bt_lost_no_mapping;
40243- atomic_t event_lost_overflow;
40244- atomic_t multiplex_counter;
40245+ atomic_unchecked_t sample_lost_no_mm;
40246+ atomic_unchecked_t sample_lost_no_mapping;
40247+ atomic_unchecked_t bt_lost_no_mapping;
40248+ atomic_unchecked_t event_lost_overflow;
40249+ atomic_unchecked_t multiplex_counter;
40250 };
40251
40252 extern struct oprofile_stat_struct oprofile_stats;
40253diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
40254index 849357c..b83c1e0 100644
40255--- a/drivers/oprofile/oprofilefs.c
40256+++ b/drivers/oprofile/oprofilefs.c
40257@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
40258
40259
40260 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
40261- char const *name, atomic_t *val)
40262+ char const *name, atomic_unchecked_t *val)
40263 {
40264 return __oprofilefs_create_file(sb, root, name,
40265 &atomic_ro_fops, 0444, val);
40266diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
40267index 93404f7..4a313d8 100644
40268--- a/drivers/oprofile/timer_int.c
40269+++ b/drivers/oprofile/timer_int.c
40270@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
40271 return NOTIFY_OK;
40272 }
40273
40274-static struct notifier_block __refdata oprofile_cpu_notifier = {
40275+static struct notifier_block oprofile_cpu_notifier = {
40276 .notifier_call = oprofile_cpu_notify,
40277 };
40278
40279diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
40280index 3f56bc0..707d642 100644
40281--- a/drivers/parport/procfs.c
40282+++ b/drivers/parport/procfs.c
40283@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
40284
40285 *ppos += len;
40286
40287- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
40288+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
40289 }
40290
40291 #ifdef CONFIG_PARPORT_1284
40292@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
40293
40294 *ppos += len;
40295
40296- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
40297+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
40298 }
40299 #endif /* IEEE1284.3 support. */
40300
40301diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
40302index c35e8ad..fc33beb 100644
40303--- a/drivers/pci/hotplug/acpiphp_ibm.c
40304+++ b/drivers/pci/hotplug/acpiphp_ibm.c
40305@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
40306 goto init_cleanup;
40307 }
40308
40309- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40310+ pax_open_kernel();
40311+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40312+ pax_close_kernel();
40313 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
40314
40315 return retval;
40316diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
40317index a6a71c4..c91097b 100644
40318--- a/drivers/pci/hotplug/cpcihp_generic.c
40319+++ b/drivers/pci/hotplug/cpcihp_generic.c
40320@@ -73,7 +73,6 @@ static u16 port;
40321 static unsigned int enum_bit;
40322 static u8 enum_mask;
40323
40324-static struct cpci_hp_controller_ops generic_hpc_ops;
40325 static struct cpci_hp_controller generic_hpc;
40326
40327 static int __init validate_parameters(void)
40328@@ -139,6 +138,10 @@ static int query_enum(void)
40329 return ((value & enum_mask) == enum_mask);
40330 }
40331
40332+static struct cpci_hp_controller_ops generic_hpc_ops = {
40333+ .query_enum = query_enum,
40334+};
40335+
40336 static int __init cpcihp_generic_init(void)
40337 {
40338 int status;
40339@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
40340 pci_dev_put(dev);
40341
40342 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
40343- generic_hpc_ops.query_enum = query_enum;
40344 generic_hpc.ops = &generic_hpc_ops;
40345
40346 status = cpci_hp_register_controller(&generic_hpc);
40347diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
40348index 449b4bb..257e2e8 100644
40349--- a/drivers/pci/hotplug/cpcihp_zt5550.c
40350+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
40351@@ -59,7 +59,6 @@
40352 /* local variables */
40353 static bool debug;
40354 static bool poll;
40355-static struct cpci_hp_controller_ops zt5550_hpc_ops;
40356 static struct cpci_hp_controller zt5550_hpc;
40357
40358 /* Primary cPCI bus bridge device */
40359@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
40360 return 0;
40361 }
40362
40363+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
40364+ .query_enum = zt5550_hc_query_enum,
40365+};
40366+
40367 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
40368 {
40369 int status;
40370@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
40371 dbg("returned from zt5550_hc_config");
40372
40373 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
40374- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
40375 zt5550_hpc.ops = &zt5550_hpc_ops;
40376 if(!poll) {
40377 zt5550_hpc.irq = hc_dev->irq;
40378 zt5550_hpc.irq_flags = IRQF_SHARED;
40379 zt5550_hpc.dev_id = hc_dev;
40380
40381- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40382- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40383- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40384+ pax_open_kernel();
40385+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40386+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40387+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40388+ pax_open_kernel();
40389 } else {
40390 info("using ENUM# polling mode");
40391 }
40392diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
40393index 76ba8a1..20ca857 100644
40394--- a/drivers/pci/hotplug/cpqphp_nvram.c
40395+++ b/drivers/pci/hotplug/cpqphp_nvram.c
40396@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
40397
40398 void compaq_nvram_init (void __iomem *rom_start)
40399 {
40400+
40401+#ifndef CONFIG_PAX_KERNEXEC
40402 if (rom_start) {
40403 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
40404 }
40405+#endif
40406+
40407 dbg("int15 entry = %p\n", compaq_int15_entry_point);
40408
40409 /* initialize our int15 lock */
40410diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
40411index 202f4a9..8ee47d0 100644
40412--- a/drivers/pci/hotplug/pci_hotplug_core.c
40413+++ b/drivers/pci/hotplug/pci_hotplug_core.c
40414@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
40415 return -EINVAL;
40416 }
40417
40418- slot->ops->owner = owner;
40419- slot->ops->mod_name = mod_name;
40420+ pax_open_kernel();
40421+ *(struct module **)&slot->ops->owner = owner;
40422+ *(const char **)&slot->ops->mod_name = mod_name;
40423+ pax_close_kernel();
40424
40425 mutex_lock(&pci_hp_mutex);
40426 /*
40427diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
40428index 939bd1d..a1459c9 100644
40429--- a/drivers/pci/hotplug/pciehp_core.c
40430+++ b/drivers/pci/hotplug/pciehp_core.c
40431@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
40432 struct slot *slot = ctrl->slot;
40433 struct hotplug_slot *hotplug = NULL;
40434 struct hotplug_slot_info *info = NULL;
40435- struct hotplug_slot_ops *ops = NULL;
40436+ hotplug_slot_ops_no_const *ops = NULL;
40437 char name[SLOT_NAME_SIZE];
40438 int retval = -ENOMEM;
40439
40440diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
40441index 9c6e9bb..2916736 100644
40442--- a/drivers/pci/pci-sysfs.c
40443+++ b/drivers/pci/pci-sysfs.c
40444@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
40445 {
40446 /* allocate attribute structure, piggyback attribute name */
40447 int name_len = write_combine ? 13 : 10;
40448- struct bin_attribute *res_attr;
40449+ bin_attribute_no_const *res_attr;
40450 int retval;
40451
40452 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
40453@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
40454 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
40455 {
40456 int retval;
40457- struct bin_attribute *attr;
40458+ bin_attribute_no_const *attr;
40459
40460 /* If the device has VPD, try to expose it in sysfs. */
40461 if (dev->vpd) {
40462@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
40463 {
40464 int retval;
40465 int rom_size = 0;
40466- struct bin_attribute *attr;
40467+ bin_attribute_no_const *attr;
40468
40469 if (!sysfs_initialized)
40470 return -EACCES;
40471diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
40472index e851829..a1a7196 100644
40473--- a/drivers/pci/pci.h
40474+++ b/drivers/pci/pci.h
40475@@ -98,7 +98,7 @@ struct pci_vpd_ops {
40476 struct pci_vpd {
40477 unsigned int len;
40478 const struct pci_vpd_ops *ops;
40479- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
40480+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
40481 };
40482
40483 extern int pci_vpd_pci22_init(struct pci_dev *dev);
40484diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
40485index 8474b6a..ee81993 100644
40486--- a/drivers/pci/pcie/aspm.c
40487+++ b/drivers/pci/pcie/aspm.c
40488@@ -27,9 +27,9 @@
40489 #define MODULE_PARAM_PREFIX "pcie_aspm."
40490
40491 /* Note: those are not register definitions */
40492-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
40493-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
40494-#define ASPM_STATE_L1 (4) /* L1 state */
40495+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
40496+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
40497+#define ASPM_STATE_L1 (4U) /* L1 state */
40498 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
40499 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
40500
40501diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
40502index 6186f03..1a78714 100644
40503--- a/drivers/pci/probe.c
40504+++ b/drivers/pci/probe.c
40505@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
40506 struct pci_bus_region region;
40507 bool bar_too_big = false, bar_disabled = false;
40508
40509- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
40510+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
40511
40512 /* No printks while decoding is disabled! */
40513 if (!dev->mmio_always_on) {
40514diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
40515index 9b8505c..f00870a 100644
40516--- a/drivers/pci/proc.c
40517+++ b/drivers/pci/proc.c
40518@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40519 static int __init pci_proc_init(void)
40520 {
40521 struct pci_dev *dev = NULL;
40522+
40523+#ifdef CONFIG_GRKERNSEC_PROC_ADD
40524+#ifdef CONFIG_GRKERNSEC_PROC_USER
40525+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40526+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40527+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40528+#endif
40529+#else
40530 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40531+#endif
40532 proc_create("devices", 0, proc_bus_pci_dir,
40533 &proc_bus_pci_dev_operations);
40534 proc_initialized = 1;
40535diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40536index 2111dbb..79e434b 100644
40537--- a/drivers/platform/x86/msi-laptop.c
40538+++ b/drivers/platform/x86/msi-laptop.c
40539@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
40540 int result;
40541
40542 /* allow userland write sysfs file */
40543- dev_attr_bluetooth.store = store_bluetooth;
40544- dev_attr_wlan.store = store_wlan;
40545- dev_attr_threeg.store = store_threeg;
40546- dev_attr_bluetooth.attr.mode |= S_IWUSR;
40547- dev_attr_wlan.attr.mode |= S_IWUSR;
40548- dev_attr_threeg.attr.mode |= S_IWUSR;
40549+ pax_open_kernel();
40550+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
40551+ *(void **)&dev_attr_wlan.store = store_wlan;
40552+ *(void **)&dev_attr_threeg.store = store_threeg;
40553+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
40554+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
40555+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
40556+ pax_close_kernel();
40557
40558 /* disable hardware control by fn key */
40559 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
40560diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40561index 0fe987f..6f3d5c3 100644
40562--- a/drivers/platform/x86/sony-laptop.c
40563+++ b/drivers/platform/x86/sony-laptop.c
40564@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
40565 }
40566
40567 /* High speed charging function */
40568-static struct device_attribute *hsc_handle;
40569+static device_attribute_no_const *hsc_handle;
40570
40571 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
40572 struct device_attribute *attr,
40573diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40574index f946ca7..f25c833 100644
40575--- a/drivers/platform/x86/thinkpad_acpi.c
40576+++ b/drivers/platform/x86/thinkpad_acpi.c
40577@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
40578 return 0;
40579 }
40580
40581-void static hotkey_mask_warn_incomplete_mask(void)
40582+static void hotkey_mask_warn_incomplete_mask(void)
40583 {
40584 /* log only what the user can fix... */
40585 const u32 wantedmask = hotkey_driver_mask &
40586@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
40587 }
40588 }
40589
40590-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40591- struct tp_nvram_state *newn,
40592- const u32 event_mask)
40593-{
40594-
40595 #define TPACPI_COMPARE_KEY(__scancode, __member) \
40596 do { \
40597 if ((event_mask & (1 << __scancode)) && \
40598@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40599 tpacpi_hotkey_send_key(__scancode); \
40600 } while (0)
40601
40602- void issue_volchange(const unsigned int oldvol,
40603- const unsigned int newvol)
40604- {
40605- unsigned int i = oldvol;
40606+static void issue_volchange(const unsigned int oldvol,
40607+ const unsigned int newvol,
40608+ const u32 event_mask)
40609+{
40610+ unsigned int i = oldvol;
40611
40612- while (i > newvol) {
40613- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40614- i--;
40615- }
40616- while (i < newvol) {
40617- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40618- i++;
40619- }
40620+ while (i > newvol) {
40621+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40622+ i--;
40623 }
40624+ while (i < newvol) {
40625+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40626+ i++;
40627+ }
40628+}
40629
40630- void issue_brightnesschange(const unsigned int oldbrt,
40631- const unsigned int newbrt)
40632- {
40633- unsigned int i = oldbrt;
40634+static void issue_brightnesschange(const unsigned int oldbrt,
40635+ const unsigned int newbrt,
40636+ const u32 event_mask)
40637+{
40638+ unsigned int i = oldbrt;
40639
40640- while (i > newbrt) {
40641- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40642- i--;
40643- }
40644- while (i < newbrt) {
40645- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40646- i++;
40647- }
40648+ while (i > newbrt) {
40649+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40650+ i--;
40651+ }
40652+ while (i < newbrt) {
40653+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40654+ i++;
40655 }
40656+}
40657
40658+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40659+ struct tp_nvram_state *newn,
40660+ const u32 event_mask)
40661+{
40662 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
40663 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
40664 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
40665@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40666 oldn->volume_level != newn->volume_level) {
40667 /* recently muted, or repeated mute keypress, or
40668 * multiple presses ending in mute */
40669- issue_volchange(oldn->volume_level, newn->volume_level);
40670+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40671 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
40672 }
40673 } else {
40674@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40675 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40676 }
40677 if (oldn->volume_level != newn->volume_level) {
40678- issue_volchange(oldn->volume_level, newn->volume_level);
40679+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40680 } else if (oldn->volume_toggle != newn->volume_toggle) {
40681 /* repeated vol up/down keypress at end of scale ? */
40682 if (newn->volume_level == 0)
40683@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40684 /* handle brightness */
40685 if (oldn->brightness_level != newn->brightness_level) {
40686 issue_brightnesschange(oldn->brightness_level,
40687- newn->brightness_level);
40688+ newn->brightness_level,
40689+ event_mask);
40690 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
40691 /* repeated key presses that didn't change state */
40692 if (newn->brightness_level == 0)
40693@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40694 && !tp_features.bright_unkfw)
40695 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40696 }
40697+}
40698
40699 #undef TPACPI_COMPARE_KEY
40700 #undef TPACPI_MAY_SEND_KEY
40701-}
40702
40703 /*
40704 * Polling driver
40705diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40706index 769d265..a3a05ca 100644
40707--- a/drivers/pnp/pnpbios/bioscalls.c
40708+++ b/drivers/pnp/pnpbios/bioscalls.c
40709@@ -58,7 +58,7 @@ do { \
40710 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40711 } while(0)
40712
40713-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40714+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40715 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40716
40717 /*
40718@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40719
40720 cpu = get_cpu();
40721 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40722+
40723+ pax_open_kernel();
40724 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40725+ pax_close_kernel();
40726
40727 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40728 spin_lock_irqsave(&pnp_bios_lock, flags);
40729@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40730 :"memory");
40731 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40732
40733+ pax_open_kernel();
40734 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40735+ pax_close_kernel();
40736+
40737 put_cpu();
40738
40739 /* If we get here and this is set then the PnP BIOS faulted on us. */
40740@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40741 return status;
40742 }
40743
40744-void pnpbios_calls_init(union pnp_bios_install_struct *header)
40745+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40746 {
40747 int i;
40748
40749@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40750 pnp_bios_callpoint.offset = header->fields.pm16offset;
40751 pnp_bios_callpoint.segment = PNP_CS16;
40752
40753+ pax_open_kernel();
40754+
40755 for_each_possible_cpu(i) {
40756 struct desc_struct *gdt = get_cpu_gdt_table(i);
40757 if (!gdt)
40758@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40759 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40760 (unsigned long)__va(header->fields.pm16dseg));
40761 }
40762+
40763+ pax_close_kernel();
40764 }
40765diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40766index 3e6db1c..1fbbdae 100644
40767--- a/drivers/pnp/resource.c
40768+++ b/drivers/pnp/resource.c
40769@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40770 return 1;
40771
40772 /* check if the resource is valid */
40773- if (*irq < 0 || *irq > 15)
40774+ if (*irq > 15)
40775 return 0;
40776
40777 /* check if the resource is reserved */
40778@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40779 return 1;
40780
40781 /* check if the resource is valid */
40782- if (*dma < 0 || *dma == 4 || *dma > 7)
40783+ if (*dma == 4 || *dma > 7)
40784 return 0;
40785
40786 /* check if the resource is reserved */
40787diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
40788index 7df7c5f..bd48c47 100644
40789--- a/drivers/power/pda_power.c
40790+++ b/drivers/power/pda_power.c
40791@@ -37,7 +37,11 @@ static int polling;
40792
40793 #ifdef CONFIG_USB_OTG_UTILS
40794 static struct usb_phy *transceiver;
40795-static struct notifier_block otg_nb;
40796+static int otg_handle_notification(struct notifier_block *nb,
40797+ unsigned long event, void *unused);
40798+static struct notifier_block otg_nb = {
40799+ .notifier_call = otg_handle_notification
40800+};
40801 #endif
40802
40803 static struct regulator *ac_draw;
40804@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
40805
40806 #ifdef CONFIG_USB_OTG_UTILS
40807 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
40808- otg_nb.notifier_call = otg_handle_notification;
40809 ret = usb_register_notifier(transceiver, &otg_nb);
40810 if (ret) {
40811 dev_err(dev, "failure to register otg notifier\n");
40812diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
40813index cc439fd..8fa30df 100644
40814--- a/drivers/power/power_supply.h
40815+++ b/drivers/power/power_supply.h
40816@@ -16,12 +16,12 @@ struct power_supply;
40817
40818 #ifdef CONFIG_SYSFS
40819
40820-extern void power_supply_init_attrs(struct device_type *dev_type);
40821+extern void power_supply_init_attrs(void);
40822 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
40823
40824 #else
40825
40826-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
40827+static inline void power_supply_init_attrs(void) {}
40828 #define power_supply_uevent NULL
40829
40830 #endif /* CONFIG_SYSFS */
40831diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
40832index 8a7cfb3..72e6e9b 100644
40833--- a/drivers/power/power_supply_core.c
40834+++ b/drivers/power/power_supply_core.c
40835@@ -24,7 +24,10 @@
40836 struct class *power_supply_class;
40837 EXPORT_SYMBOL_GPL(power_supply_class);
40838
40839-static struct device_type power_supply_dev_type;
40840+extern const struct attribute_group *power_supply_attr_groups[];
40841+static struct device_type power_supply_dev_type = {
40842+ .groups = power_supply_attr_groups,
40843+};
40844
40845 static int __power_supply_changed_work(struct device *dev, void *data)
40846 {
40847@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
40848 return PTR_ERR(power_supply_class);
40849
40850 power_supply_class->dev_uevent = power_supply_uevent;
40851- power_supply_init_attrs(&power_supply_dev_type);
40852+ power_supply_init_attrs();
40853
40854 return 0;
40855 }
40856diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
40857index 40fa3b7..d9c2e0e 100644
40858--- a/drivers/power/power_supply_sysfs.c
40859+++ b/drivers/power/power_supply_sysfs.c
40860@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
40861 .is_visible = power_supply_attr_is_visible,
40862 };
40863
40864-static const struct attribute_group *power_supply_attr_groups[] = {
40865+const struct attribute_group *power_supply_attr_groups[] = {
40866 &power_supply_attr_group,
40867 NULL,
40868 };
40869
40870-void power_supply_init_attrs(struct device_type *dev_type)
40871+void power_supply_init_attrs(void)
40872 {
40873 int i;
40874
40875- dev_type->groups = power_supply_attr_groups;
40876-
40877 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
40878 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
40879 }
40880diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
40881index 4d7c635..9860196 100644
40882--- a/drivers/regulator/max8660.c
40883+++ b/drivers/regulator/max8660.c
40884@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
40885 max8660->shadow_regs[MAX8660_OVER1] = 5;
40886 } else {
40887 /* Otherwise devices can be toggled via software */
40888- max8660_dcdc_ops.enable = max8660_dcdc_enable;
40889- max8660_dcdc_ops.disable = max8660_dcdc_disable;
40890+ pax_open_kernel();
40891+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
40892+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
40893+ pax_close_kernel();
40894 }
40895
40896 /*
40897diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
40898index 9a8ea91..c483dd9 100644
40899--- a/drivers/regulator/max8973-regulator.c
40900+++ b/drivers/regulator/max8973-regulator.c
40901@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
40902 if (!pdata->enable_ext_control) {
40903 max->desc.enable_reg = MAX8973_VOUT;
40904 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
40905- max8973_dcdc_ops.enable = regulator_enable_regmap;
40906- max8973_dcdc_ops.disable = regulator_disable_regmap;
40907- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
40908+ pax_open_kernel();
40909+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
40910+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
40911+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
40912+ pax_close_kernel();
40913 }
40914
40915 max->enable_external_control = pdata->enable_ext_control;
40916diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
40917index 0d84b1f..c2da6ac 100644
40918--- a/drivers/regulator/mc13892-regulator.c
40919+++ b/drivers/regulator/mc13892-regulator.c
40920@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
40921 }
40922 mc13xxx_unlock(mc13892);
40923
40924- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
40925+ pax_open_kernel();
40926+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
40927 = mc13892_vcam_set_mode;
40928- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
40929+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
40930 = mc13892_vcam_get_mode;
40931+ pax_close_kernel();
40932
40933 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
40934 ARRAY_SIZE(mc13892_regulators));
40935diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
40936index 16630aa..6afc992 100644
40937--- a/drivers/rtc/rtc-cmos.c
40938+++ b/drivers/rtc/rtc-cmos.c
40939@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
40940 hpet_rtc_timer_init();
40941
40942 /* export at least the first block of NVRAM */
40943- nvram.size = address_space - NVRAM_OFFSET;
40944+ pax_open_kernel();
40945+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
40946+ pax_close_kernel();
40947 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
40948 if (retval < 0) {
40949 dev_dbg(dev, "can't create nvram file? %d\n", retval);
40950diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
40951index 9a86b4b..3a383dc 100644
40952--- a/drivers/rtc/rtc-dev.c
40953+++ b/drivers/rtc/rtc-dev.c
40954@@ -14,6 +14,7 @@
40955 #include <linux/module.h>
40956 #include <linux/rtc.h>
40957 #include <linux/sched.h>
40958+#include <linux/grsecurity.h>
40959 #include "rtc-core.h"
40960
40961 static dev_t rtc_devt;
40962@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
40963 if (copy_from_user(&tm, uarg, sizeof(tm)))
40964 return -EFAULT;
40965
40966+ gr_log_timechange();
40967+
40968 return rtc_set_time(rtc, &tm);
40969
40970 case RTC_PIE_ON:
40971diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
40972index e0d0ba4..3c65868 100644
40973--- a/drivers/rtc/rtc-ds1307.c
40974+++ b/drivers/rtc/rtc-ds1307.c
40975@@ -106,7 +106,7 @@ struct ds1307 {
40976 u8 offset; /* register's offset */
40977 u8 regs[11];
40978 u16 nvram_offset;
40979- struct bin_attribute *nvram;
40980+ bin_attribute_no_const *nvram;
40981 enum ds_type type;
40982 unsigned long flags;
40983 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
40984diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
40985index 130f29a..6179d03 100644
40986--- a/drivers/rtc/rtc-m48t59.c
40987+++ b/drivers/rtc/rtc-m48t59.c
40988@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
40989 goto out;
40990 }
40991
40992- m48t59_nvram_attr.size = pdata->offset;
40993+ pax_open_kernel();
40994+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
40995+ pax_close_kernel();
40996
40997 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
40998 if (ret) {
40999diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41000index e693af6..2e525b6 100644
41001--- a/drivers/scsi/bfa/bfa_fcpim.h
41002+++ b/drivers/scsi/bfa/bfa_fcpim.h
41003@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41004
41005 struct bfa_itn_s {
41006 bfa_isr_func_t isr;
41007-};
41008+} __no_const;
41009
41010 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41011 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41012diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41013index 23a90e7..9cf04ee 100644
41014--- a/drivers/scsi/bfa/bfa_ioc.h
41015+++ b/drivers/scsi/bfa/bfa_ioc.h
41016@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41017 bfa_ioc_disable_cbfn_t disable_cbfn;
41018 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41019 bfa_ioc_reset_cbfn_t reset_cbfn;
41020-};
41021+} __no_const;
41022
41023 /*
41024 * IOC event notification mechanism.
41025@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41026 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41027 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41028 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41029-};
41030+} __no_const;
41031
41032 /*
41033 * Queue element to wait for room in request queue. FIFO order is
41034diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41035index 593085a..47aa999 100644
41036--- a/drivers/scsi/hosts.c
41037+++ b/drivers/scsi/hosts.c
41038@@ -42,7 +42,7 @@
41039 #include "scsi_logging.h"
41040
41041
41042-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41043+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41044
41045
41046 static void scsi_host_cls_release(struct device *dev)
41047@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41048 * subtract one because we increment first then return, but we need to
41049 * know what the next host number was before increment
41050 */
41051- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41052+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41053 shost->dma_channel = 0xff;
41054
41055 /* These three are default values which can be overridden */
41056diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41057index 4f33806..afd6f60 100644
41058--- a/drivers/scsi/hpsa.c
41059+++ b/drivers/scsi/hpsa.c
41060@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
41061 unsigned long flags;
41062
41063 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
41064- return h->access.command_completed(h, q);
41065+ return h->access->command_completed(h, q);
41066
41067 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
41068 a = rq->head[rq->current_entry];
41069@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
41070 while (!list_empty(&h->reqQ)) {
41071 c = list_entry(h->reqQ.next, struct CommandList, list);
41072 /* can't do anything if fifo is full */
41073- if ((h->access.fifo_full(h))) {
41074+ if ((h->access->fifo_full(h))) {
41075 dev_warn(&h->pdev->dev, "fifo full\n");
41076 break;
41077 }
41078@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
41079
41080 /* Tell the controller execute command */
41081 spin_unlock_irqrestore(&h->lock, flags);
41082- h->access.submit_command(h, c);
41083+ h->access->submit_command(h, c);
41084 spin_lock_irqsave(&h->lock, flags);
41085 }
41086 spin_unlock_irqrestore(&h->lock, flags);
41087@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
41088
41089 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
41090 {
41091- return h->access.command_completed(h, q);
41092+ return h->access->command_completed(h, q);
41093 }
41094
41095 static inline bool interrupt_pending(struct ctlr_info *h)
41096 {
41097- return h->access.intr_pending(h);
41098+ return h->access->intr_pending(h);
41099 }
41100
41101 static inline long interrupt_not_for_us(struct ctlr_info *h)
41102 {
41103- return (h->access.intr_pending(h) == 0) ||
41104+ return (h->access->intr_pending(h) == 0) ||
41105 (h->interrupts_enabled == 0);
41106 }
41107
41108@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
41109 if (prod_index < 0)
41110 return -ENODEV;
41111 h->product_name = products[prod_index].product_name;
41112- h->access = *(products[prod_index].access);
41113+ h->access = products[prod_index].access;
41114
41115 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
41116 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
41117@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
41118
41119 assert_spin_locked(&lockup_detector_lock);
41120 remove_ctlr_from_lockup_detector_list(h);
41121- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41122+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41123 spin_lock_irqsave(&h->lock, flags);
41124 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
41125 spin_unlock_irqrestore(&h->lock, flags);
41126@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
41127 }
41128
41129 /* make sure the board interrupts are off */
41130- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41131+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41132
41133 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
41134 goto clean2;
41135@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
41136 * fake ones to scoop up any residual completions.
41137 */
41138 spin_lock_irqsave(&h->lock, flags);
41139- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41140+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41141 spin_unlock_irqrestore(&h->lock, flags);
41142 free_irqs(h);
41143 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
41144@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
41145 dev_info(&h->pdev->dev, "Board READY.\n");
41146 dev_info(&h->pdev->dev,
41147 "Waiting for stale completions to drain.\n");
41148- h->access.set_intr_mask(h, HPSA_INTR_ON);
41149+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41150 msleep(10000);
41151- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41152+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41153
41154 rc = controller_reset_failed(h->cfgtable);
41155 if (rc)
41156@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
41157 }
41158
41159 /* Turn the interrupts on so we can service requests */
41160- h->access.set_intr_mask(h, HPSA_INTR_ON);
41161+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41162
41163 hpsa_hba_inquiry(h);
41164 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
41165@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
41166 * To write all data in the battery backed cache to disks
41167 */
41168 hpsa_flush_cache(h);
41169- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41170+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41171 hpsa_free_irqs_and_disable_msix(h);
41172 }
41173
41174@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
41175 return;
41176 }
41177 /* Change the access methods to the performant access methods */
41178- h->access = SA5_performant_access;
41179+ h->access = &SA5_performant_access;
41180 h->transMethod = CFGTBL_Trans_Performant;
41181 }
41182
41183diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
41184index 9816479..c5d4e97 100644
41185--- a/drivers/scsi/hpsa.h
41186+++ b/drivers/scsi/hpsa.h
41187@@ -79,7 +79,7 @@ struct ctlr_info {
41188 unsigned int msix_vector;
41189 unsigned int msi_vector;
41190 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
41191- struct access_method access;
41192+ struct access_method *access;
41193
41194 /* queue and queue Info */
41195 struct list_head reqQ;
41196diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
41197index c772d8d..35c362c 100644
41198--- a/drivers/scsi/libfc/fc_exch.c
41199+++ b/drivers/scsi/libfc/fc_exch.c
41200@@ -100,12 +100,12 @@ struct fc_exch_mgr {
41201 u16 pool_max_index;
41202
41203 struct {
41204- atomic_t no_free_exch;
41205- atomic_t no_free_exch_xid;
41206- atomic_t xid_not_found;
41207- atomic_t xid_busy;
41208- atomic_t seq_not_found;
41209- atomic_t non_bls_resp;
41210+ atomic_unchecked_t no_free_exch;
41211+ atomic_unchecked_t no_free_exch_xid;
41212+ atomic_unchecked_t xid_not_found;
41213+ atomic_unchecked_t xid_busy;
41214+ atomic_unchecked_t seq_not_found;
41215+ atomic_unchecked_t non_bls_resp;
41216 } stats;
41217 };
41218
41219@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
41220 /* allocate memory for exchange */
41221 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
41222 if (!ep) {
41223- atomic_inc(&mp->stats.no_free_exch);
41224+ atomic_inc_unchecked(&mp->stats.no_free_exch);
41225 goto out;
41226 }
41227 memset(ep, 0, sizeof(*ep));
41228@@ -786,7 +786,7 @@ out:
41229 return ep;
41230 err:
41231 spin_unlock_bh(&pool->lock);
41232- atomic_inc(&mp->stats.no_free_exch_xid);
41233+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
41234 mempool_free(ep, mp->ep_pool);
41235 return NULL;
41236 }
41237@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41238 xid = ntohs(fh->fh_ox_id); /* we originated exch */
41239 ep = fc_exch_find(mp, xid);
41240 if (!ep) {
41241- atomic_inc(&mp->stats.xid_not_found);
41242+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41243 reject = FC_RJT_OX_ID;
41244 goto out;
41245 }
41246@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41247 ep = fc_exch_find(mp, xid);
41248 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
41249 if (ep) {
41250- atomic_inc(&mp->stats.xid_busy);
41251+ atomic_inc_unchecked(&mp->stats.xid_busy);
41252 reject = FC_RJT_RX_ID;
41253 goto rel;
41254 }
41255@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41256 }
41257 xid = ep->xid; /* get our XID */
41258 } else if (!ep) {
41259- atomic_inc(&mp->stats.xid_not_found);
41260+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41261 reject = FC_RJT_RX_ID; /* XID not found */
41262 goto out;
41263 }
41264@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41265 } else {
41266 sp = &ep->seq;
41267 if (sp->id != fh->fh_seq_id) {
41268- atomic_inc(&mp->stats.seq_not_found);
41269+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41270 if (f_ctl & FC_FC_END_SEQ) {
41271 /*
41272 * Update sequence_id based on incoming last
41273@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41274
41275 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
41276 if (!ep) {
41277- atomic_inc(&mp->stats.xid_not_found);
41278+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41279 goto out;
41280 }
41281 if (ep->esb_stat & ESB_ST_COMPLETE) {
41282- atomic_inc(&mp->stats.xid_not_found);
41283+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41284 goto rel;
41285 }
41286 if (ep->rxid == FC_XID_UNKNOWN)
41287 ep->rxid = ntohs(fh->fh_rx_id);
41288 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
41289- atomic_inc(&mp->stats.xid_not_found);
41290+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41291 goto rel;
41292 }
41293 if (ep->did != ntoh24(fh->fh_s_id) &&
41294 ep->did != FC_FID_FLOGI) {
41295- atomic_inc(&mp->stats.xid_not_found);
41296+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41297 goto rel;
41298 }
41299 sof = fr_sof(fp);
41300@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41301 sp->ssb_stat |= SSB_ST_RESP;
41302 sp->id = fh->fh_seq_id;
41303 } else if (sp->id != fh->fh_seq_id) {
41304- atomic_inc(&mp->stats.seq_not_found);
41305+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41306 goto rel;
41307 }
41308
41309@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41310 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
41311
41312 if (!sp)
41313- atomic_inc(&mp->stats.xid_not_found);
41314+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41315 else
41316- atomic_inc(&mp->stats.non_bls_resp);
41317+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
41318
41319 fc_frame_free(fp);
41320 }
41321@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
41322
41323 list_for_each_entry(ema, &lport->ema_list, ema_list) {
41324 mp = ema->mp;
41325- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
41326+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
41327 st->fc_no_free_exch_xid +=
41328- atomic_read(&mp->stats.no_free_exch_xid);
41329- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
41330- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
41331- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
41332- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
41333+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
41334+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
41335+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
41336+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
41337+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
41338 }
41339 }
41340 EXPORT_SYMBOL(fc_exch_update_stats);
41341diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
41342index bdb81cd..d3c7c2c 100644
41343--- a/drivers/scsi/libsas/sas_ata.c
41344+++ b/drivers/scsi/libsas/sas_ata.c
41345@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
41346 .postreset = ata_std_postreset,
41347 .error_handler = ata_std_error_handler,
41348 .post_internal_cmd = sas_ata_post_internal,
41349- .qc_defer = ata_std_qc_defer,
41350+ .qc_defer = ata_std_qc_defer,
41351 .qc_prep = ata_noop_qc_prep,
41352 .qc_issue = sas_ata_qc_issue,
41353 .qc_fill_rtf = sas_ata_qc_fill_rtf,
41354diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
41355index df4c13a..a51e90c 100644
41356--- a/drivers/scsi/lpfc/lpfc.h
41357+++ b/drivers/scsi/lpfc/lpfc.h
41358@@ -424,7 +424,7 @@ struct lpfc_vport {
41359 struct dentry *debug_nodelist;
41360 struct dentry *vport_debugfs_root;
41361 struct lpfc_debugfs_trc *disc_trc;
41362- atomic_t disc_trc_cnt;
41363+ atomic_unchecked_t disc_trc_cnt;
41364 #endif
41365 uint8_t stat_data_enabled;
41366 uint8_t stat_data_blocked;
41367@@ -842,8 +842,8 @@ struct lpfc_hba {
41368 struct timer_list fabric_block_timer;
41369 unsigned long bit_flags;
41370 #define FABRIC_COMANDS_BLOCKED 0
41371- atomic_t num_rsrc_err;
41372- atomic_t num_cmd_success;
41373+ atomic_unchecked_t num_rsrc_err;
41374+ atomic_unchecked_t num_cmd_success;
41375 unsigned long last_rsrc_error_time;
41376 unsigned long last_ramp_down_time;
41377 unsigned long last_ramp_up_time;
41378@@ -879,7 +879,7 @@ struct lpfc_hba {
41379
41380 struct dentry *debug_slow_ring_trc;
41381 struct lpfc_debugfs_trc *slow_ring_trc;
41382- atomic_t slow_ring_trc_cnt;
41383+ atomic_unchecked_t slow_ring_trc_cnt;
41384 /* iDiag debugfs sub-directory */
41385 struct dentry *idiag_root;
41386 struct dentry *idiag_pci_cfg;
41387diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41388index f63f5ff..de29189 100644
41389--- a/drivers/scsi/lpfc/lpfc_debugfs.c
41390+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41391@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
41392
41393 #include <linux/debugfs.h>
41394
41395-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41396+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41397 static unsigned long lpfc_debugfs_start_time = 0L;
41398
41399 /* iDiag */
41400@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41401 lpfc_debugfs_enable = 0;
41402
41403 len = 0;
41404- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41405+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41406 (lpfc_debugfs_max_disc_trc - 1);
41407 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41408 dtp = vport->disc_trc + i;
41409@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41410 lpfc_debugfs_enable = 0;
41411
41412 len = 0;
41413- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41414+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41415 (lpfc_debugfs_max_slow_ring_trc - 1);
41416 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41417 dtp = phba->slow_ring_trc + i;
41418@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
41419 !vport || !vport->disc_trc)
41420 return;
41421
41422- index = atomic_inc_return(&vport->disc_trc_cnt) &
41423+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
41424 (lpfc_debugfs_max_disc_trc - 1);
41425 dtp = vport->disc_trc + index;
41426 dtp->fmt = fmt;
41427 dtp->data1 = data1;
41428 dtp->data2 = data2;
41429 dtp->data3 = data3;
41430- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41431+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41432 dtp->jif = jiffies;
41433 #endif
41434 return;
41435@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
41436 !phba || !phba->slow_ring_trc)
41437 return;
41438
41439- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
41440+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
41441 (lpfc_debugfs_max_slow_ring_trc - 1);
41442 dtp = phba->slow_ring_trc + index;
41443 dtp->fmt = fmt;
41444 dtp->data1 = data1;
41445 dtp->data2 = data2;
41446 dtp->data3 = data3;
41447- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41448+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41449 dtp->jif = jiffies;
41450 #endif
41451 return;
41452@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41453 "slow_ring buffer\n");
41454 goto debug_failed;
41455 }
41456- atomic_set(&phba->slow_ring_trc_cnt, 0);
41457+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41458 memset(phba->slow_ring_trc, 0,
41459 (sizeof(struct lpfc_debugfs_trc) *
41460 lpfc_debugfs_max_slow_ring_trc));
41461@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41462 "buffer\n");
41463 goto debug_failed;
41464 }
41465- atomic_set(&vport->disc_trc_cnt, 0);
41466+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41467
41468 snprintf(name, sizeof(name), "discovery_trace");
41469 vport->debug_disc_trc =
41470diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41471index 89ad558..76956c4 100644
41472--- a/drivers/scsi/lpfc/lpfc_init.c
41473+++ b/drivers/scsi/lpfc/lpfc_init.c
41474@@ -10618,8 +10618,10 @@ lpfc_init(void)
41475 "misc_register returned with status %d", error);
41476
41477 if (lpfc_enable_npiv) {
41478- lpfc_transport_functions.vport_create = lpfc_vport_create;
41479- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41480+ pax_open_kernel();
41481+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41482+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41483+ pax_close_kernel();
41484 }
41485 lpfc_transport_template =
41486 fc_attach_transport(&lpfc_transport_functions);
41487diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41488index 60e5a17..ff7a793 100644
41489--- a/drivers/scsi/lpfc/lpfc_scsi.c
41490+++ b/drivers/scsi/lpfc/lpfc_scsi.c
41491@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41492 uint32_t evt_posted;
41493
41494 spin_lock_irqsave(&phba->hbalock, flags);
41495- atomic_inc(&phba->num_rsrc_err);
41496+ atomic_inc_unchecked(&phba->num_rsrc_err);
41497 phba->last_rsrc_error_time = jiffies;
41498
41499 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41500@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41501 unsigned long flags;
41502 struct lpfc_hba *phba = vport->phba;
41503 uint32_t evt_posted;
41504- atomic_inc(&phba->num_cmd_success);
41505+ atomic_inc_unchecked(&phba->num_cmd_success);
41506
41507 if (vport->cfg_lun_queue_depth <= queue_depth)
41508 return;
41509@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41510 unsigned long num_rsrc_err, num_cmd_success;
41511 int i;
41512
41513- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41514- num_cmd_success = atomic_read(&phba->num_cmd_success);
41515+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41516+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41517
41518 /*
41519 * The error and success command counters are global per
41520@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41521 }
41522 }
41523 lpfc_destroy_vport_work_array(phba, vports);
41524- atomic_set(&phba->num_rsrc_err, 0);
41525- atomic_set(&phba->num_cmd_success, 0);
41526+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41527+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41528 }
41529
41530 /**
41531@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41532 }
41533 }
41534 lpfc_destroy_vport_work_array(phba, vports);
41535- atomic_set(&phba->num_rsrc_err, 0);
41536- atomic_set(&phba->num_cmd_success, 0);
41537+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41538+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41539 }
41540
41541 /**
41542diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41543index b46f5e9..c4c4ccb 100644
41544--- a/drivers/scsi/pmcraid.c
41545+++ b/drivers/scsi/pmcraid.c
41546@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41547 res->scsi_dev = scsi_dev;
41548 scsi_dev->hostdata = res;
41549 res->change_detected = 0;
41550- atomic_set(&res->read_failures, 0);
41551- atomic_set(&res->write_failures, 0);
41552+ atomic_set_unchecked(&res->read_failures, 0);
41553+ atomic_set_unchecked(&res->write_failures, 0);
41554 rc = 0;
41555 }
41556 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41557@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41558
41559 /* If this was a SCSI read/write command keep count of errors */
41560 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41561- atomic_inc(&res->read_failures);
41562+ atomic_inc_unchecked(&res->read_failures);
41563 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41564- atomic_inc(&res->write_failures);
41565+ atomic_inc_unchecked(&res->write_failures);
41566
41567 if (!RES_IS_GSCSI(res->cfg_entry) &&
41568 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41569@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
41570 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41571 * hrrq_id assigned here in queuecommand
41572 */
41573- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41574+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41575 pinstance->num_hrrq;
41576 cmd->cmd_done = pmcraid_io_done;
41577
41578@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
41579 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41580 * hrrq_id assigned here in queuecommand
41581 */
41582- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41583+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41584 pinstance->num_hrrq;
41585
41586 if (request_size) {
41587@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41588
41589 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41590 /* add resources only after host is added into system */
41591- if (!atomic_read(&pinstance->expose_resources))
41592+ if (!atomic_read_unchecked(&pinstance->expose_resources))
41593 return;
41594
41595 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
41596@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
41597 init_waitqueue_head(&pinstance->reset_wait_q);
41598
41599 atomic_set(&pinstance->outstanding_cmds, 0);
41600- atomic_set(&pinstance->last_message_id, 0);
41601- atomic_set(&pinstance->expose_resources, 0);
41602+ atomic_set_unchecked(&pinstance->last_message_id, 0);
41603+ atomic_set_unchecked(&pinstance->expose_resources, 0);
41604
41605 INIT_LIST_HEAD(&pinstance->free_res_q);
41606 INIT_LIST_HEAD(&pinstance->used_res_q);
41607@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
41608 /* Schedule worker thread to handle CCN and take care of adding and
41609 * removing devices to OS
41610 */
41611- atomic_set(&pinstance->expose_resources, 1);
41612+ atomic_set_unchecked(&pinstance->expose_resources, 1);
41613 schedule_work(&pinstance->worker_q);
41614 return rc;
41615
41616diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41617index e1d150f..6c6df44 100644
41618--- a/drivers/scsi/pmcraid.h
41619+++ b/drivers/scsi/pmcraid.h
41620@@ -748,7 +748,7 @@ struct pmcraid_instance {
41621 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
41622
41623 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
41624- atomic_t last_message_id;
41625+ atomic_unchecked_t last_message_id;
41626
41627 /* configuration table */
41628 struct pmcraid_config_table *cfg_table;
41629@@ -777,7 +777,7 @@ struct pmcraid_instance {
41630 atomic_t outstanding_cmds;
41631
41632 /* should add/delete resources to mid-layer now ?*/
41633- atomic_t expose_resources;
41634+ atomic_unchecked_t expose_resources;
41635
41636
41637
41638@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
41639 struct pmcraid_config_table_entry_ext cfg_entry_ext;
41640 };
41641 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41642- atomic_t read_failures; /* count of failed READ commands */
41643- atomic_t write_failures; /* count of failed WRITE commands */
41644+ atomic_unchecked_t read_failures; /* count of failed READ commands */
41645+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41646
41647 /* To indicate add/delete/modify during CCN */
41648 u8 change_detected;
41649diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
41650index 83d7984..a27d947 100644
41651--- a/drivers/scsi/qla2xxx/qla_attr.c
41652+++ b/drivers/scsi/qla2xxx/qla_attr.c
41653@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
41654 return 0;
41655 }
41656
41657-struct fc_function_template qla2xxx_transport_functions = {
41658+fc_function_template_no_const qla2xxx_transport_functions = {
41659
41660 .show_host_node_name = 1,
41661 .show_host_port_name = 1,
41662@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
41663 .bsg_timeout = qla24xx_bsg_timeout,
41664 };
41665
41666-struct fc_function_template qla2xxx_transport_vport_functions = {
41667+fc_function_template_no_const qla2xxx_transport_vport_functions = {
41668
41669 .show_host_node_name = 1,
41670 .show_host_port_name = 1,
41671diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
41672index 2411d1a..4673766 100644
41673--- a/drivers/scsi/qla2xxx/qla_gbl.h
41674+++ b/drivers/scsi/qla2xxx/qla_gbl.h
41675@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
41676 struct device_attribute;
41677 extern struct device_attribute *qla2x00_host_attrs[];
41678 struct fc_function_template;
41679-extern struct fc_function_template qla2xxx_transport_functions;
41680-extern struct fc_function_template qla2xxx_transport_vport_functions;
41681+extern fc_function_template_no_const qla2xxx_transport_functions;
41682+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
41683 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
41684 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
41685 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
41686diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
41687index 10d23f8..a7d5d4c 100644
41688--- a/drivers/scsi/qla2xxx/qla_os.c
41689+++ b/drivers/scsi/qla2xxx/qla_os.c
41690@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
41691 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
41692 /* Ok, a 64bit DMA mask is applicable. */
41693 ha->flags.enable_64bit_addressing = 1;
41694- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41695- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41696+ pax_open_kernel();
41697+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41698+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41699+ pax_close_kernel();
41700 return;
41701 }
41702 }
41703diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41704index 329d553..f20d31d 100644
41705--- a/drivers/scsi/qla4xxx/ql4_def.h
41706+++ b/drivers/scsi/qla4xxx/ql4_def.h
41707@@ -273,7 +273,7 @@ struct ddb_entry {
41708 * (4000 only) */
41709 atomic_t relogin_timer; /* Max Time to wait for
41710 * relogin to complete */
41711- atomic_t relogin_retry_count; /* Num of times relogin has been
41712+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41713 * retried */
41714 uint32_t default_time2wait; /* Default Min time between
41715 * relogins (+aens) */
41716diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41717index 4cec123..7c1329f 100644
41718--- a/drivers/scsi/qla4xxx/ql4_os.c
41719+++ b/drivers/scsi/qla4xxx/ql4_os.c
41720@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
41721 */
41722 if (!iscsi_is_session_online(cls_sess)) {
41723 /* Reset retry relogin timer */
41724- atomic_inc(&ddb_entry->relogin_retry_count);
41725+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41726 DEBUG2(ql4_printk(KERN_INFO, ha,
41727 "%s: index[%d] relogin timed out-retrying"
41728 " relogin (%d), retry (%d)\n", __func__,
41729 ddb_entry->fw_ddb_index,
41730- atomic_read(&ddb_entry->relogin_retry_count),
41731+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
41732 ddb_entry->default_time2wait + 4));
41733 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
41734 atomic_set(&ddb_entry->retry_relogin_timer,
41735@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
41736
41737 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41738 atomic_set(&ddb_entry->relogin_timer, 0);
41739- atomic_set(&ddb_entry->relogin_retry_count, 0);
41740+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41741 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
41742 ddb_entry->default_relogin_timeout =
41743 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
41744diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41745index 2c0d0ec..4e8681a 100644
41746--- a/drivers/scsi/scsi.c
41747+++ b/drivers/scsi/scsi.c
41748@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41749 unsigned long timeout;
41750 int rtn = 0;
41751
41752- atomic_inc(&cmd->device->iorequest_cnt);
41753+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41754
41755 /* check if the device is still usable */
41756 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41757diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41758index f1bf5af..f67e943 100644
41759--- a/drivers/scsi/scsi_lib.c
41760+++ b/drivers/scsi/scsi_lib.c
41761@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41762 shost = sdev->host;
41763 scsi_init_cmd_errh(cmd);
41764 cmd->result = DID_NO_CONNECT << 16;
41765- atomic_inc(&cmd->device->iorequest_cnt);
41766+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41767
41768 /*
41769 * SCSI request completion path will do scsi_device_unbusy(),
41770@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
41771
41772 INIT_LIST_HEAD(&cmd->eh_entry);
41773
41774- atomic_inc(&cmd->device->iodone_cnt);
41775+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
41776 if (cmd->result)
41777- atomic_inc(&cmd->device->ioerr_cnt);
41778+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41779
41780 disposition = scsi_decide_disposition(cmd);
41781 if (disposition != SUCCESS &&
41782diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41783index 931a7d9..0c2a754 100644
41784--- a/drivers/scsi/scsi_sysfs.c
41785+++ b/drivers/scsi/scsi_sysfs.c
41786@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41787 char *buf) \
41788 { \
41789 struct scsi_device *sdev = to_scsi_device(dev); \
41790- unsigned long long count = atomic_read(&sdev->field); \
41791+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
41792 return snprintf(buf, 20, "0x%llx\n", count); \
41793 } \
41794 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41795diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41796index 84a1fdf..693b0d6 100644
41797--- a/drivers/scsi/scsi_tgt_lib.c
41798+++ b/drivers/scsi/scsi_tgt_lib.c
41799@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41800 int err;
41801
41802 dprintk("%lx %u\n", uaddr, len);
41803- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41804+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41805 if (err) {
41806 /*
41807 * TODO: need to fixup sg_tablesize, max_segment_size,
41808diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41809index e894ca7..de9d7660 100644
41810--- a/drivers/scsi/scsi_transport_fc.c
41811+++ b/drivers/scsi/scsi_transport_fc.c
41812@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
41813 * Netlink Infrastructure
41814 */
41815
41816-static atomic_t fc_event_seq;
41817+static atomic_unchecked_t fc_event_seq;
41818
41819 /**
41820 * fc_get_event_number - Obtain the next sequential FC event number
41821@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
41822 u32
41823 fc_get_event_number(void)
41824 {
41825- return atomic_add_return(1, &fc_event_seq);
41826+ return atomic_add_return_unchecked(1, &fc_event_seq);
41827 }
41828 EXPORT_SYMBOL(fc_get_event_number);
41829
41830@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
41831 {
41832 int error;
41833
41834- atomic_set(&fc_event_seq, 0);
41835+ atomic_set_unchecked(&fc_event_seq, 0);
41836
41837 error = transport_class_register(&fc_host_class);
41838 if (error)
41839@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
41840 char *cp;
41841
41842 *val = simple_strtoul(buf, &cp, 0);
41843- if ((*cp && (*cp != '\n')) || (*val < 0))
41844+ if (*cp && (*cp != '\n'))
41845 return -EINVAL;
41846 /*
41847 * Check for overflow; dev_loss_tmo is u32
41848diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41849index 31969f2..2b348f0 100644
41850--- a/drivers/scsi/scsi_transport_iscsi.c
41851+++ b/drivers/scsi/scsi_transport_iscsi.c
41852@@ -79,7 +79,7 @@ struct iscsi_internal {
41853 struct transport_container session_cont;
41854 };
41855
41856-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
41857+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
41858 static struct workqueue_struct *iscsi_eh_timer_workq;
41859
41860 static DEFINE_IDA(iscsi_sess_ida);
41861@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
41862 int err;
41863
41864 ihost = shost->shost_data;
41865- session->sid = atomic_add_return(1, &iscsi_session_nr);
41866+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
41867
41868 if (target_id == ISCSI_MAX_TARGET) {
41869 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
41870@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
41871 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
41872 ISCSI_TRANSPORT_VERSION);
41873
41874- atomic_set(&iscsi_session_nr, 0);
41875+ atomic_set_unchecked(&iscsi_session_nr, 0);
41876
41877 err = class_register(&iscsi_transport_class);
41878 if (err)
41879diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
41880index f379c7f..e8fc69c 100644
41881--- a/drivers/scsi/scsi_transport_srp.c
41882+++ b/drivers/scsi/scsi_transport_srp.c
41883@@ -33,7 +33,7 @@
41884 #include "scsi_transport_srp_internal.h"
41885
41886 struct srp_host_attrs {
41887- atomic_t next_port_id;
41888+ atomic_unchecked_t next_port_id;
41889 };
41890 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
41891
41892@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
41893 struct Scsi_Host *shost = dev_to_shost(dev);
41894 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
41895
41896- atomic_set(&srp_host->next_port_id, 0);
41897+ atomic_set_unchecked(&srp_host->next_port_id, 0);
41898 return 0;
41899 }
41900
41901@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
41902 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
41903 rport->roles = ids->roles;
41904
41905- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
41906+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
41907 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
41908
41909 transport_setup_device(&rport->dev);
41910diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
41911index 7992635..609faf8 100644
41912--- a/drivers/scsi/sd.c
41913+++ b/drivers/scsi/sd.c
41914@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
41915 sdkp->disk = gd;
41916 sdkp->index = index;
41917 atomic_set(&sdkp->openers, 0);
41918- atomic_set(&sdkp->device->ioerr_cnt, 0);
41919+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
41920
41921 if (!sdp->request_queue->rq_timeout) {
41922 if (sdp->type != TYPE_MOD)
41923diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
41924index be2c9a6..275525c 100644
41925--- a/drivers/scsi/sg.c
41926+++ b/drivers/scsi/sg.c
41927@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
41928 sdp->disk->disk_name,
41929 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
41930 NULL,
41931- (char *)arg);
41932+ (char __user *)arg);
41933 case BLKTRACESTART:
41934 return blk_trace_startstop(sdp->device->request_queue, 1);
41935 case BLKTRACESTOP:
41936diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
41937index 19ee901..6e8c2ef 100644
41938--- a/drivers/spi/spi.c
41939+++ b/drivers/spi/spi.c
41940@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
41941 EXPORT_SYMBOL_GPL(spi_bus_unlock);
41942
41943 /* portable code must never pass more than 32 bytes */
41944-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
41945+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
41946
41947 static u8 *buf;
41948
41949diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
41950index c7a5f97..71ecd35 100644
41951--- a/drivers/staging/iio/iio_hwmon.c
41952+++ b/drivers/staging/iio/iio_hwmon.c
41953@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
41954 static int iio_hwmon_probe(struct platform_device *pdev)
41955 {
41956 struct iio_hwmon_state *st;
41957- struct sensor_device_attribute *a;
41958+ sensor_device_attribute_no_const *a;
41959 int ret, i;
41960 int in_i = 1, temp_i = 1, curr_i = 1;
41961 enum iio_chan_type type;
41962diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
41963index 34afc16..ffe44dd 100644
41964--- a/drivers/staging/octeon/ethernet-rx.c
41965+++ b/drivers/staging/octeon/ethernet-rx.c
41966@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
41967 /* Increment RX stats for virtual ports */
41968 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
41969 #ifdef CONFIG_64BIT
41970- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
41971- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
41972+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
41973+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
41974 #else
41975- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
41976- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
41977+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
41978+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
41979 #endif
41980 }
41981 netif_receive_skb(skb);
41982@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
41983 dev->name);
41984 */
41985 #ifdef CONFIG_64BIT
41986- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
41987+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41988 #else
41989- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
41990+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
41991 #endif
41992 dev_kfree_skb_irq(skb);
41993 }
41994diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
41995index ef32dc1..a159d68 100644
41996--- a/drivers/staging/octeon/ethernet.c
41997+++ b/drivers/staging/octeon/ethernet.c
41998@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
41999 * since the RX tasklet also increments it.
42000 */
42001 #ifdef CONFIG_64BIT
42002- atomic64_add(rx_status.dropped_packets,
42003- (atomic64_t *)&priv->stats.rx_dropped);
42004+ atomic64_add_unchecked(rx_status.dropped_packets,
42005+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42006 #else
42007- atomic_add(rx_status.dropped_packets,
42008- (atomic_t *)&priv->stats.rx_dropped);
42009+ atomic_add_unchecked(rx_status.dropped_packets,
42010+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42011 #endif
42012 }
42013
42014diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
42015index a2b7e03..aaf3630 100644
42016--- a/drivers/staging/ramster/tmem.c
42017+++ b/drivers/staging/ramster/tmem.c
42018@@ -50,25 +50,25 @@
42019 * A tmem host implementation must use this function to register callbacks
42020 * for memory allocation.
42021 */
42022-static struct tmem_hostops tmem_hostops;
42023+static struct tmem_hostops *tmem_hostops;
42024
42025 static void tmem_objnode_tree_init(void);
42026
42027 void tmem_register_hostops(struct tmem_hostops *m)
42028 {
42029 tmem_objnode_tree_init();
42030- tmem_hostops = *m;
42031+ tmem_hostops = m;
42032 }
42033
42034 /*
42035 * A tmem host implementation must use this function to register
42036 * callbacks for a page-accessible memory (PAM) implementation.
42037 */
42038-static struct tmem_pamops tmem_pamops;
42039+static struct tmem_pamops *tmem_pamops;
42040
42041 void tmem_register_pamops(struct tmem_pamops *m)
42042 {
42043- tmem_pamops = *m;
42044+ tmem_pamops = m;
42045 }
42046
42047 /*
42048@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
42049 obj->pampd_count = 0;
42050 #ifdef CONFIG_RAMSTER
42051 if (tmem_pamops.new_obj != NULL)
42052- (*tmem_pamops.new_obj)(obj);
42053+ (tmem_pamops->new_obj)(obj);
42054 #endif
42055 SET_SENTINEL(obj, OBJ);
42056
42057@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
42058 rbnode = rb_next(rbnode);
42059 tmem_pampd_destroy_all_in_obj(obj, true);
42060 tmem_obj_free(obj, hb);
42061- (*tmem_hostops.obj_free)(obj, pool);
42062+ (tmem_hostops->obj_free)(obj, pool);
42063 }
42064 spin_unlock(&hb->lock);
42065 }
42066@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
42067 ASSERT_SENTINEL(obj, OBJ);
42068 BUG_ON(obj->pool == NULL);
42069 ASSERT_SENTINEL(obj->pool, POOL);
42070- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
42071+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
42072 if (unlikely(objnode == NULL))
42073 goto out;
42074 objnode->obj = obj;
42075@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
42076 ASSERT_SENTINEL(pool, POOL);
42077 objnode->obj->objnode_count--;
42078 objnode->obj = NULL;
42079- (*tmem_hostops.objnode_free)(objnode, pool);
42080+ (tmem_hostops->objnode_free)(objnode, pool);
42081 }
42082
42083 /*
42084@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
42085 void *old_pampd = *(void **)slot;
42086 *(void **)slot = new_pampd;
42087 if (!no_free)
42088- (*tmem_pamops.free)(old_pampd, obj->pool,
42089+ (tmem_pamops->free)(old_pampd, obj->pool,
42090 NULL, 0, false);
42091 ret = new_pampd;
42092 }
42093@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
42094 if (objnode->slots[i]) {
42095 if (ht == 1) {
42096 obj->pampd_count--;
42097- (*tmem_pamops.free)(objnode->slots[i],
42098+ (tmem_pamops->free)(objnode->slots[i],
42099 obj->pool, NULL, 0, true);
42100 objnode->slots[i] = NULL;
42101 continue;
42102@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
42103 return;
42104 if (obj->objnode_tree_height == 0) {
42105 obj->pampd_count--;
42106- (*tmem_pamops.free)(obj->objnode_tree_root,
42107+ (tmem_pamops->free)(obj->objnode_tree_root,
42108 obj->pool, NULL, 0, true);
42109 } else {
42110 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
42111@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
42112 obj->objnode_tree_root = NULL;
42113 #ifdef CONFIG_RAMSTER
42114 if (tmem_pamops.free_obj != NULL)
42115- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
42116+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
42117 #endif
42118 }
42119
42120@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42121 /* if found, is a dup put, flush the old one */
42122 pampd_del = tmem_pampd_delete_from_obj(obj, index);
42123 BUG_ON(pampd_del != pampd);
42124- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
42125+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
42126 if (obj->pampd_count == 0) {
42127 objnew = obj;
42128 objfound = NULL;
42129@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42130 pampd = NULL;
42131 }
42132 } else {
42133- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
42134+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
42135 if (unlikely(obj == NULL)) {
42136 ret = -ENOMEM;
42137 goto out;
42138@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42139 if (unlikely(ret == -ENOMEM))
42140 /* may have partially built objnode tree ("stump") */
42141 goto delete_and_free;
42142- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
42143+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
42144 goto out;
42145
42146 delete_and_free:
42147 (void)tmem_pampd_delete_from_obj(obj, index);
42148 if (pampd)
42149- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
42150+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
42151 if (objnew) {
42152 tmem_obj_free(objnew, hb);
42153- (*tmem_hostops.obj_free)(objnew, pool);
42154+ (tmem_hostops->obj_free)(objnew, pool);
42155 }
42156 out:
42157 spin_unlock(&hb->lock);
42158@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
42159 if (pampd != NULL) {
42160 BUG_ON(obj == NULL);
42161 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
42162- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
42163+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
42164 } else if (delete) {
42165 BUG_ON(obj == NULL);
42166 (void)tmem_pampd_delete_from_obj(obj, index);
42167@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
42168 int ret = 0;
42169
42170 if (!is_ephemeral(pool))
42171- new_pampd = (*tmem_pamops.repatriate_preload)(
42172+ new_pampd = (tmem_pamops->repatriate_preload)(
42173 old_pampd, pool, oidp, index, &intransit);
42174 if (intransit)
42175 ret = -EAGAIN;
42176@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
42177 /* must release the hb->lock else repatriate can't sleep */
42178 spin_unlock(&hb->lock);
42179 if (!intransit)
42180- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
42181+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
42182 oidp, index, free, data);
42183 if (ret == -EAGAIN) {
42184 /* rare I think, but should cond_resched()??? */
42185@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
42186 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
42187 /* if we bug here, pamops wasn't properly set up for ramster */
42188 BUG_ON(tmem_pamops.replace_in_obj == NULL);
42189- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
42190+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
42191 out:
42192 spin_unlock(&hb->lock);
42193 return ret;
42194@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
42195 if (free) {
42196 if (obj->pampd_count == 0) {
42197 tmem_obj_free(obj, hb);
42198- (*tmem_hostops.obj_free)(obj, pool);
42199+ (tmem_hostops->obj_free)(obj, pool);
42200 obj = NULL;
42201 }
42202 }
42203 if (free)
42204- ret = (*tmem_pamops.get_data_and_free)(
42205+ ret = (tmem_pamops->get_data_and_free)(
42206 data, sizep, raw, pampd, pool, oidp, index);
42207 else
42208- ret = (*tmem_pamops.get_data)(
42209+ ret = (tmem_pamops->get_data)(
42210 data, sizep, raw, pampd, pool, oidp, index);
42211 if (ret < 0)
42212 goto out;
42213@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
42214 pampd = tmem_pampd_delete_from_obj(obj, index);
42215 if (pampd == NULL)
42216 goto out;
42217- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
42218+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
42219 if (obj->pampd_count == 0) {
42220 tmem_obj_free(obj, hb);
42221- (*tmem_hostops.obj_free)(obj, pool);
42222+ (tmem_hostops->obj_free)(obj, pool);
42223 }
42224 ret = 0;
42225
42226@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
42227 goto out;
42228 tmem_pampd_destroy_all_in_obj(obj, false);
42229 tmem_obj_free(obj, hb);
42230- (*tmem_hostops.obj_free)(obj, pool);
42231+ (tmem_hostops->obj_free)(obj, pool);
42232 ret = 0;
42233
42234 out:
42235diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
42236index dc23395..cf7e9b1 100644
42237--- a/drivers/staging/rtl8712/rtl871x_io.h
42238+++ b/drivers/staging/rtl8712/rtl871x_io.h
42239@@ -108,7 +108,7 @@ struct _io_ops {
42240 u8 *pmem);
42241 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
42242 u8 *pmem);
42243-};
42244+} __no_const;
42245
42246 struct io_req {
42247 struct list_head list;
42248diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
42249index 1f5088b..0e59820 100644
42250--- a/drivers/staging/sbe-2t3e3/netdev.c
42251+++ b/drivers/staging/sbe-2t3e3/netdev.c
42252@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42253 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
42254
42255 if (rlen)
42256- if (copy_to_user(data, &resp, rlen))
42257+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
42258 return -EFAULT;
42259
42260 return 0;
42261diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42262index 5dddc4d..34fcb2f 100644
42263--- a/drivers/staging/usbip/vhci.h
42264+++ b/drivers/staging/usbip/vhci.h
42265@@ -83,7 +83,7 @@ struct vhci_hcd {
42266 unsigned resuming:1;
42267 unsigned long re_timeout;
42268
42269- atomic_t seqnum;
42270+ atomic_unchecked_t seqnum;
42271
42272 /*
42273 * NOTE:
42274diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42275index c3aa219..bf8b3de 100644
42276--- a/drivers/staging/usbip/vhci_hcd.c
42277+++ b/drivers/staging/usbip/vhci_hcd.c
42278@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
42279 return;
42280 }
42281
42282- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42283+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42284 if (priv->seqnum == 0xffff)
42285 dev_info(&urb->dev->dev, "seqnum max\n");
42286
42287@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42288 return -ENOMEM;
42289 }
42290
42291- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42292+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42293 if (unlink->seqnum == 0xffff)
42294 pr_info("seqnum max\n");
42295
42296@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
42297 vdev->rhport = rhport;
42298 }
42299
42300- atomic_set(&vhci->seqnum, 0);
42301+ atomic_set_unchecked(&vhci->seqnum, 0);
42302 spin_lock_init(&vhci->lock);
42303
42304 hcd->power_budget = 0; /* no limit */
42305diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42306index ba5f1c0..11d8122 100644
42307--- a/drivers/staging/usbip/vhci_rx.c
42308+++ b/drivers/staging/usbip/vhci_rx.c
42309@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42310 if (!urb) {
42311 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
42312 pr_info("max seqnum %d\n",
42313- atomic_read(&the_controller->seqnum));
42314+ atomic_read_unchecked(&the_controller->seqnum));
42315 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42316 return;
42317 }
42318diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42319index 5f13890..36a044b 100644
42320--- a/drivers/staging/vt6655/hostap.c
42321+++ b/drivers/staging/vt6655/hostap.c
42322@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
42323 *
42324 */
42325
42326+static net_device_ops_no_const apdev_netdev_ops;
42327+
42328 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42329 {
42330 PSDevice apdev_priv;
42331 struct net_device *dev = pDevice->dev;
42332 int ret;
42333- const struct net_device_ops apdev_netdev_ops = {
42334- .ndo_start_xmit = pDevice->tx_80211,
42335- };
42336
42337 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42338
42339@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42340 *apdev_priv = *pDevice;
42341 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42342
42343+ /* only half broken now */
42344+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42345 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42346
42347 pDevice->apdev->type = ARPHRD_IEEE80211;
42348diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42349index 26a7d0e..897b083 100644
42350--- a/drivers/staging/vt6656/hostap.c
42351+++ b/drivers/staging/vt6656/hostap.c
42352@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
42353 *
42354 */
42355
42356+static net_device_ops_no_const apdev_netdev_ops;
42357+
42358 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42359 {
42360 PSDevice apdev_priv;
42361 struct net_device *dev = pDevice->dev;
42362 int ret;
42363- const struct net_device_ops apdev_netdev_ops = {
42364- .ndo_start_xmit = pDevice->tx_80211,
42365- };
42366
42367 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42368
42369@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42370 *apdev_priv = *pDevice;
42371 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42372
42373+ /* only half broken now */
42374+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42375 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42376
42377 pDevice->apdev->type = ARPHRD_IEEE80211;
42378diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
42379index 56c8e60..1920c63 100644
42380--- a/drivers/staging/zcache/tmem.c
42381+++ b/drivers/staging/zcache/tmem.c
42382@@ -39,7 +39,7 @@
42383 * A tmem host implementation must use this function to register callbacks
42384 * for memory allocation.
42385 */
42386-static struct tmem_hostops tmem_hostops;
42387+static tmem_hostops_no_const tmem_hostops;
42388
42389 static void tmem_objnode_tree_init(void);
42390
42391@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42392 * A tmem host implementation must use this function to register
42393 * callbacks for a page-accessible memory (PAM) implementation
42394 */
42395-static struct tmem_pamops tmem_pamops;
42396+static tmem_pamops_no_const tmem_pamops;
42397
42398 void tmem_register_pamops(struct tmem_pamops *m)
42399 {
42400diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42401index 0d4aa82..f7832d4 100644
42402--- a/drivers/staging/zcache/tmem.h
42403+++ b/drivers/staging/zcache/tmem.h
42404@@ -180,6 +180,7 @@ struct tmem_pamops {
42405 void (*new_obj)(struct tmem_obj *);
42406 int (*replace_in_obj)(void *, struct tmem_obj *);
42407 };
42408+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42409 extern void tmem_register_pamops(struct tmem_pamops *m);
42410
42411 /* memory allocation methods provided by the host implementation */
42412@@ -189,6 +190,7 @@ struct tmem_hostops {
42413 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42414 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42415 };
42416+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42417 extern void tmem_register_hostops(struct tmem_hostops *m);
42418
42419 /* core tmem accessor functions */
42420diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42421index 96f4981..4daaa7e 100644
42422--- a/drivers/target/target_core_device.c
42423+++ b/drivers/target/target_core_device.c
42424@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42425 spin_lock_init(&dev->se_port_lock);
42426 spin_lock_init(&dev->se_tmr_lock);
42427 spin_lock_init(&dev->qf_cmd_lock);
42428- atomic_set(&dev->dev_ordered_id, 0);
42429+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
42430 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42431 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42432 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42433diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42434index bd587b7..173daf3 100644
42435--- a/drivers/target/target_core_transport.c
42436+++ b/drivers/target/target_core_transport.c
42437@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42438 * Used to determine when ORDERED commands should go from
42439 * Dormant to Active status.
42440 */
42441- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42442+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42443 smp_mb__after_atomic_inc();
42444 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42445 cmd->se_ordered_id, cmd->sam_task_attr,
42446diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42447index b09c8d1f..c4225c0 100644
42448--- a/drivers/tty/cyclades.c
42449+++ b/drivers/tty/cyclades.c
42450@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42451 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42452 info->port.count);
42453 #endif
42454- info->port.count++;
42455+ atomic_inc(&info->port.count);
42456 #ifdef CY_DEBUG_COUNT
42457 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42458- current->pid, info->port.count);
42459+ current->pid, atomic_read(&info->port.count));
42460 #endif
42461
42462 /*
42463@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42464 for (j = 0; j < cy_card[i].nports; j++) {
42465 info = &cy_card[i].ports[j];
42466
42467- if (info->port.count) {
42468+ if (atomic_read(&info->port.count)) {
42469 /* XXX is the ldisc num worth this? */
42470 struct tty_struct *tty;
42471 struct tty_ldisc *ld;
42472diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42473index 13ee53b..418d164 100644
42474--- a/drivers/tty/hvc/hvc_console.c
42475+++ b/drivers/tty/hvc/hvc_console.c
42476@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42477
42478 spin_lock_irqsave(&hp->port.lock, flags);
42479 /* Check and then increment for fast path open. */
42480- if (hp->port.count++ > 0) {
42481+ if (atomic_inc_return(&hp->port.count) > 1) {
42482 spin_unlock_irqrestore(&hp->port.lock, flags);
42483 hvc_kick();
42484 return 0;
42485@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42486
42487 spin_lock_irqsave(&hp->port.lock, flags);
42488
42489- if (--hp->port.count == 0) {
42490+ if (atomic_dec_return(&hp->port.count) == 0) {
42491 spin_unlock_irqrestore(&hp->port.lock, flags);
42492 /* We are done with the tty pointer now. */
42493 tty_port_tty_set(&hp->port, NULL);
42494@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42495 */
42496 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42497 } else {
42498- if (hp->port.count < 0)
42499+ if (atomic_read(&hp->port.count) < 0)
42500 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42501- hp->vtermno, hp->port.count);
42502+ hp->vtermno, atomic_read(&hp->port.count));
42503 spin_unlock_irqrestore(&hp->port.lock, flags);
42504 }
42505 }
42506@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42507 * open->hangup case this can be called after the final close so prevent
42508 * that from happening for now.
42509 */
42510- if (hp->port.count <= 0) {
42511+ if (atomic_read(&hp->port.count) <= 0) {
42512 spin_unlock_irqrestore(&hp->port.lock, flags);
42513 return;
42514 }
42515
42516- hp->port.count = 0;
42517+ atomic_set(&hp->port.count, 0);
42518 spin_unlock_irqrestore(&hp->port.lock, flags);
42519 tty_port_tty_set(&hp->port, NULL);
42520
42521@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42522 return -EPIPE;
42523
42524 /* FIXME what's this (unprotected) check for? */
42525- if (hp->port.count <= 0)
42526+ if (atomic_read(&hp->port.count) <= 0)
42527 return -EIO;
42528
42529 spin_lock_irqsave(&hp->lock, flags);
42530diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42531index 8776357..b2d4afd 100644
42532--- a/drivers/tty/hvc/hvcs.c
42533+++ b/drivers/tty/hvc/hvcs.c
42534@@ -83,6 +83,7 @@
42535 #include <asm/hvcserver.h>
42536 #include <asm/uaccess.h>
42537 #include <asm/vio.h>
42538+#include <asm/local.h>
42539
42540 /*
42541 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
42542@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
42543
42544 spin_lock_irqsave(&hvcsd->lock, flags);
42545
42546- if (hvcsd->port.count > 0) {
42547+ if (atomic_read(&hvcsd->port.count) > 0) {
42548 spin_unlock_irqrestore(&hvcsd->lock, flags);
42549 printk(KERN_INFO "HVCS: vterm state unchanged. "
42550 "The hvcs device node is still in use.\n");
42551@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
42552 }
42553 }
42554
42555- hvcsd->port.count = 0;
42556+ atomic_set(&hvcsd->port.count, 0);
42557 hvcsd->port.tty = tty;
42558 tty->driver_data = hvcsd;
42559
42560@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
42561 unsigned long flags;
42562
42563 spin_lock_irqsave(&hvcsd->lock, flags);
42564- hvcsd->port.count++;
42565+ atomic_inc(&hvcsd->port.count);
42566 hvcsd->todo_mask |= HVCS_SCHED_READ;
42567 spin_unlock_irqrestore(&hvcsd->lock, flags);
42568
42569@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42570 hvcsd = tty->driver_data;
42571
42572 spin_lock_irqsave(&hvcsd->lock, flags);
42573- if (--hvcsd->port.count == 0) {
42574+ if (atomic_dec_and_test(&hvcsd->port.count)) {
42575
42576 vio_disable_interrupts(hvcsd->vdev);
42577
42578@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42579
42580 free_irq(irq, hvcsd);
42581 return;
42582- } else if (hvcsd->port.count < 0) {
42583+ } else if (atomic_read(&hvcsd->port.count) < 0) {
42584 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
42585 " is missmanaged.\n",
42586- hvcsd->vdev->unit_address, hvcsd->port.count);
42587+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
42588 }
42589
42590 spin_unlock_irqrestore(&hvcsd->lock, flags);
42591@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42592
42593 spin_lock_irqsave(&hvcsd->lock, flags);
42594 /* Preserve this so that we know how many kref refs to put */
42595- temp_open_count = hvcsd->port.count;
42596+ temp_open_count = atomic_read(&hvcsd->port.count);
42597
42598 /*
42599 * Don't kref put inside the spinlock because the destruction
42600@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42601 tty->driver_data = NULL;
42602 hvcsd->port.tty = NULL;
42603
42604- hvcsd->port.count = 0;
42605+ atomic_set(&hvcsd->port.count, 0);
42606
42607 /* This will drop any buffered data on the floor which is OK in a hangup
42608 * scenario. */
42609@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
42610 * the middle of a write operation? This is a crummy place to do this
42611 * but we want to keep it all in the spinlock.
42612 */
42613- if (hvcsd->port.count <= 0) {
42614+ if (atomic_read(&hvcsd->port.count) <= 0) {
42615 spin_unlock_irqrestore(&hvcsd->lock, flags);
42616 return -ENODEV;
42617 }
42618@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
42619 {
42620 struct hvcs_struct *hvcsd = tty->driver_data;
42621
42622- if (!hvcsd || hvcsd->port.count <= 0)
42623+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
42624 return 0;
42625
42626 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
42627diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
42628index 2cde13d..645d78f 100644
42629--- a/drivers/tty/ipwireless/tty.c
42630+++ b/drivers/tty/ipwireless/tty.c
42631@@ -29,6 +29,7 @@
42632 #include <linux/tty_driver.h>
42633 #include <linux/tty_flip.h>
42634 #include <linux/uaccess.h>
42635+#include <asm/local.h>
42636
42637 #include "tty.h"
42638 #include "network.h"
42639@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42640 mutex_unlock(&tty->ipw_tty_mutex);
42641 return -ENODEV;
42642 }
42643- if (tty->port.count == 0)
42644+ if (atomic_read(&tty->port.count) == 0)
42645 tty->tx_bytes_queued = 0;
42646
42647- tty->port.count++;
42648+ atomic_inc(&tty->port.count);
42649
42650 tty->port.tty = linux_tty;
42651 linux_tty->driver_data = tty;
42652@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42653
42654 static void do_ipw_close(struct ipw_tty *tty)
42655 {
42656- tty->port.count--;
42657-
42658- if (tty->port.count == 0) {
42659+ if (atomic_dec_return(&tty->port.count) == 0) {
42660 struct tty_struct *linux_tty = tty->port.tty;
42661
42662 if (linux_tty != NULL) {
42663@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
42664 return;
42665
42666 mutex_lock(&tty->ipw_tty_mutex);
42667- if (tty->port.count == 0) {
42668+ if (atomic_read(&tty->port.count) == 0) {
42669 mutex_unlock(&tty->ipw_tty_mutex);
42670 return;
42671 }
42672@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
42673 return;
42674 }
42675
42676- if (!tty->port.count) {
42677+ if (!atomic_read(&tty->port.count)) {
42678 mutex_unlock(&tty->ipw_tty_mutex);
42679 return;
42680 }
42681@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
42682 return -ENODEV;
42683
42684 mutex_lock(&tty->ipw_tty_mutex);
42685- if (!tty->port.count) {
42686+ if (!atomic_read(&tty->port.count)) {
42687 mutex_unlock(&tty->ipw_tty_mutex);
42688 return -EINVAL;
42689 }
42690@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
42691 if (!tty)
42692 return -ENODEV;
42693
42694- if (!tty->port.count)
42695+ if (!atomic_read(&tty->port.count))
42696 return -EINVAL;
42697
42698 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
42699@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
42700 if (!tty)
42701 return 0;
42702
42703- if (!tty->port.count)
42704+ if (!atomic_read(&tty->port.count))
42705 return 0;
42706
42707 return tty->tx_bytes_queued;
42708@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
42709 if (!tty)
42710 return -ENODEV;
42711
42712- if (!tty->port.count)
42713+ if (!atomic_read(&tty->port.count))
42714 return -EINVAL;
42715
42716 return get_control_lines(tty);
42717@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
42718 if (!tty)
42719 return -ENODEV;
42720
42721- if (!tty->port.count)
42722+ if (!atomic_read(&tty->port.count))
42723 return -EINVAL;
42724
42725 return set_control_lines(tty, set, clear);
42726@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
42727 if (!tty)
42728 return -ENODEV;
42729
42730- if (!tty->port.count)
42731+ if (!atomic_read(&tty->port.count))
42732 return -EINVAL;
42733
42734 /* FIXME: Exactly how is the tty object locked here .. */
42735@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
42736 * are gone */
42737 mutex_lock(&ttyj->ipw_tty_mutex);
42738 }
42739- while (ttyj->port.count)
42740+ while (atomic_read(&ttyj->port.count))
42741 do_ipw_close(ttyj);
42742 ipwireless_disassociate_network_ttys(network,
42743 ttyj->channel_idx);
42744diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
42745index f9d2850..b006f04 100644
42746--- a/drivers/tty/moxa.c
42747+++ b/drivers/tty/moxa.c
42748@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
42749 }
42750
42751 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
42752- ch->port.count++;
42753+ atomic_inc(&ch->port.count);
42754 tty->driver_data = ch;
42755 tty_port_tty_set(&ch->port, tty);
42756 mutex_lock(&ch->port.mutex);
42757diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
42758index bfd6771..e0d93c4 100644
42759--- a/drivers/tty/n_gsm.c
42760+++ b/drivers/tty/n_gsm.c
42761@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
42762 spin_lock_init(&dlci->lock);
42763 mutex_init(&dlci->mutex);
42764 dlci->fifo = &dlci->_fifo;
42765- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
42766+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
42767 kfree(dlci);
42768 return NULL;
42769 }
42770@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
42771 struct gsm_dlci *dlci = tty->driver_data;
42772 struct tty_port *port = &dlci->port;
42773
42774- port->count++;
42775+ atomic_inc(&port->count);
42776 dlci_get(dlci);
42777 dlci_get(dlci->gsm->dlci[0]);
42778 mux_get(dlci->gsm);
42779diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
42780index 19083ef..6e34e97 100644
42781--- a/drivers/tty/n_tty.c
42782+++ b/drivers/tty/n_tty.c
42783@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
42784 {
42785 *ops = tty_ldisc_N_TTY;
42786 ops->owner = NULL;
42787- ops->refcount = ops->flags = 0;
42788+ atomic_set(&ops->refcount, 0);
42789+ ops->flags = 0;
42790 }
42791 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
42792diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
42793index 79ff3a5..1fe9399 100644
42794--- a/drivers/tty/pty.c
42795+++ b/drivers/tty/pty.c
42796@@ -791,8 +791,10 @@ static void __init unix98_pty_init(void)
42797 panic("Couldn't register Unix98 pts driver");
42798
42799 /* Now create the /dev/ptmx special device */
42800+ pax_open_kernel();
42801 tty_default_fops(&ptmx_fops);
42802- ptmx_fops.open = ptmx_open;
42803+ *(void **)&ptmx_fops.open = ptmx_open;
42804+ pax_close_kernel();
42805
42806 cdev_init(&ptmx_cdev, &ptmx_fops);
42807 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
42808diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
42809index e42009a..566a036 100644
42810--- a/drivers/tty/rocket.c
42811+++ b/drivers/tty/rocket.c
42812@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42813 tty->driver_data = info;
42814 tty_port_tty_set(port, tty);
42815
42816- if (port->count++ == 0) {
42817+ if (atomic_inc_return(&port->count) == 1) {
42818 atomic_inc(&rp_num_ports_open);
42819
42820 #ifdef ROCKET_DEBUG_OPEN
42821@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42822 #endif
42823 }
42824 #ifdef ROCKET_DEBUG_OPEN
42825- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
42826+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
42827 #endif
42828
42829 /*
42830@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
42831 spin_unlock_irqrestore(&info->port.lock, flags);
42832 return;
42833 }
42834- if (info->port.count)
42835+ if (atomic_read(&info->port.count))
42836 atomic_dec(&rp_num_ports_open);
42837 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
42838 spin_unlock_irqrestore(&info->port.lock, flags);
42839diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
42840index 1002054..dd644a8 100644
42841--- a/drivers/tty/serial/kgdboc.c
42842+++ b/drivers/tty/serial/kgdboc.c
42843@@ -24,8 +24,9 @@
42844 #define MAX_CONFIG_LEN 40
42845
42846 static struct kgdb_io kgdboc_io_ops;
42847+static struct kgdb_io kgdboc_io_ops_console;
42848
42849-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
42850+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
42851 static int configured = -1;
42852
42853 static char config[MAX_CONFIG_LEN];
42854@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
42855 kgdboc_unregister_kbd();
42856 if (configured == 1)
42857 kgdb_unregister_io_module(&kgdboc_io_ops);
42858+ else if (configured == 2)
42859+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
42860 }
42861
42862 static int configure_kgdboc(void)
42863@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
42864 int err;
42865 char *cptr = config;
42866 struct console *cons;
42867+ int is_console = 0;
42868
42869 err = kgdboc_option_setup(config);
42870 if (err || !strlen(config) || isspace(config[0]))
42871 goto noconfig;
42872
42873 err = -ENODEV;
42874- kgdboc_io_ops.is_console = 0;
42875 kgdb_tty_driver = NULL;
42876
42877 kgdboc_use_kms = 0;
42878@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
42879 int idx;
42880 if (cons->device && cons->device(cons, &idx) == p &&
42881 idx == tty_line) {
42882- kgdboc_io_ops.is_console = 1;
42883+ is_console = 1;
42884 break;
42885 }
42886 cons = cons->next;
42887@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
42888 kgdb_tty_line = tty_line;
42889
42890 do_register:
42891- err = kgdb_register_io_module(&kgdboc_io_ops);
42892+ if (is_console) {
42893+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
42894+ configured = 2;
42895+ } else {
42896+ err = kgdb_register_io_module(&kgdboc_io_ops);
42897+ configured = 1;
42898+ }
42899 if (err)
42900 goto noconfig;
42901
42902@@ -205,8 +214,6 @@ do_register:
42903 if (err)
42904 goto nmi_con_failed;
42905
42906- configured = 1;
42907-
42908 return 0;
42909
42910 nmi_con_failed:
42911@@ -223,7 +230,7 @@ noconfig:
42912 static int __init init_kgdboc(void)
42913 {
42914 /* Already configured? */
42915- if (configured == 1)
42916+ if (configured >= 1)
42917 return 0;
42918
42919 return configure_kgdboc();
42920@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
42921 if (config[len - 1] == '\n')
42922 config[len - 1] = '\0';
42923
42924- if (configured == 1)
42925+ if (configured >= 1)
42926 cleanup_kgdboc();
42927
42928 /* Go and configure with the new params. */
42929@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
42930 .post_exception = kgdboc_post_exp_handler,
42931 };
42932
42933+static struct kgdb_io kgdboc_io_ops_console = {
42934+ .name = "kgdboc",
42935+ .read_char = kgdboc_get_char,
42936+ .write_char = kgdboc_put_char,
42937+ .pre_exception = kgdboc_pre_exp_handler,
42938+ .post_exception = kgdboc_post_exp_handler,
42939+ .is_console = 1
42940+};
42941+
42942 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
42943 /* This is only available if kgdboc is a built in for early debugging */
42944 static int __init kgdboc_early_init(char *opt)
42945diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
42946index e514b3a..c73d614 100644
42947--- a/drivers/tty/serial/samsung.c
42948+++ b/drivers/tty/serial/samsung.c
42949@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
42950 }
42951 }
42952
42953+static int s3c64xx_serial_startup(struct uart_port *port);
42954 static int s3c24xx_serial_startup(struct uart_port *port)
42955 {
42956 struct s3c24xx_uart_port *ourport = to_ourport(port);
42957 int ret;
42958
42959+ /* Startup sequence is different for s3c64xx and higher SoC's */
42960+ if (s3c24xx_serial_has_interrupt_mask(port))
42961+ return s3c64xx_serial_startup(port);
42962+
42963 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
42964 port->mapbase, port->membase);
42965
42966@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
42967 /* setup info for port */
42968 port->dev = &platdev->dev;
42969
42970- /* Startup sequence is different for s3c64xx and higher SoC's */
42971- if (s3c24xx_serial_has_interrupt_mask(port))
42972- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
42973-
42974 port->uartclk = 1;
42975
42976 if (cfg->uart_flags & UPF_CONS_FLOW) {
42977diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
42978index 2c7230a..2104f16 100644
42979--- a/drivers/tty/serial/serial_core.c
42980+++ b/drivers/tty/serial/serial_core.c
42981@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
42982 uart_flush_buffer(tty);
42983 uart_shutdown(tty, state);
42984 spin_lock_irqsave(&port->lock, flags);
42985- port->count = 0;
42986+ atomic_set(&port->count, 0);
42987 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
42988 spin_unlock_irqrestore(&port->lock, flags);
42989 tty_port_tty_set(port, NULL);
42990@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42991 goto end;
42992 }
42993
42994- port->count++;
42995+ atomic_inc(&port->count);
42996 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
42997 retval = -ENXIO;
42998 goto err_dec_count;
42999@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43000 /*
43001 * Make sure the device is in D0 state.
43002 */
43003- if (port->count == 1)
43004+ if (atomic_read(&port->count) == 1)
43005 uart_change_pm(state, 0);
43006
43007 /*
43008@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43009 end:
43010 return retval;
43011 err_dec_count:
43012- port->count--;
43013+ atomic_inc(&port->count);
43014 mutex_unlock(&port->mutex);
43015 goto end;
43016 }
43017diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43018index 9e071f6..f30ae69 100644
43019--- a/drivers/tty/synclink.c
43020+++ b/drivers/tty/synclink.c
43021@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43022
43023 if (debug_level >= DEBUG_LEVEL_INFO)
43024 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43025- __FILE__,__LINE__, info->device_name, info->port.count);
43026+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43027
43028 if (tty_port_close_start(&info->port, tty, filp) == 0)
43029 goto cleanup;
43030@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43031 cleanup:
43032 if (debug_level >= DEBUG_LEVEL_INFO)
43033 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43034- tty->driver->name, info->port.count);
43035+ tty->driver->name, atomic_read(&info->port.count));
43036
43037 } /* end of mgsl_close() */
43038
43039@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43040
43041 mgsl_flush_buffer(tty);
43042 shutdown(info);
43043-
43044- info->port.count = 0;
43045+
43046+ atomic_set(&info->port.count, 0);
43047 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43048 info->port.tty = NULL;
43049
43050@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43051
43052 if (debug_level >= DEBUG_LEVEL_INFO)
43053 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43054- __FILE__,__LINE__, tty->driver->name, port->count );
43055+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43056
43057 spin_lock_irqsave(&info->irq_spinlock, flags);
43058 if (!tty_hung_up_p(filp)) {
43059 extra_count = true;
43060- port->count--;
43061+ atomic_dec(&port->count);
43062 }
43063 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43064 port->blocked_open++;
43065@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43066
43067 if (debug_level >= DEBUG_LEVEL_INFO)
43068 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43069- __FILE__,__LINE__, tty->driver->name, port->count );
43070+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43071
43072 tty_unlock(tty);
43073 schedule();
43074@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43075
43076 /* FIXME: Racy on hangup during close wait */
43077 if (extra_count)
43078- port->count++;
43079+ atomic_inc(&port->count);
43080 port->blocked_open--;
43081
43082 if (debug_level >= DEBUG_LEVEL_INFO)
43083 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43084- __FILE__,__LINE__, tty->driver->name, port->count );
43085+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43086
43087 if (!retval)
43088 port->flags |= ASYNC_NORMAL_ACTIVE;
43089@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43090
43091 if (debug_level >= DEBUG_LEVEL_INFO)
43092 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43093- __FILE__,__LINE__,tty->driver->name, info->port.count);
43094+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43095
43096 /* If port is closing, signal caller to try again */
43097 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43098@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43099 spin_unlock_irqrestore(&info->netlock, flags);
43100 goto cleanup;
43101 }
43102- info->port.count++;
43103+ atomic_inc(&info->port.count);
43104 spin_unlock_irqrestore(&info->netlock, flags);
43105
43106- if (info->port.count == 1) {
43107+ if (atomic_read(&info->port.count) == 1) {
43108 /* 1st open on this device, init hardware */
43109 retval = startup(info);
43110 if (retval < 0)
43111@@ -3451,8 +3451,8 @@ cleanup:
43112 if (retval) {
43113 if (tty->count == 1)
43114 info->port.tty = NULL; /* tty layer will release tty struct */
43115- if(info->port.count)
43116- info->port.count--;
43117+ if (atomic_read(&info->port.count))
43118+ atomic_dec(&info->port.count);
43119 }
43120
43121 return retval;
43122@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43123 unsigned short new_crctype;
43124
43125 /* return error if TTY interface open */
43126- if (info->port.count)
43127+ if (atomic_read(&info->port.count))
43128 return -EBUSY;
43129
43130 switch (encoding)
43131@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
43132
43133 /* arbitrate between network and tty opens */
43134 spin_lock_irqsave(&info->netlock, flags);
43135- if (info->port.count != 0 || info->netcount != 0) {
43136+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43137 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43138 spin_unlock_irqrestore(&info->netlock, flags);
43139 return -EBUSY;
43140@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43141 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43142
43143 /* return error if TTY interface open */
43144- if (info->port.count)
43145+ if (atomic_read(&info->port.count))
43146 return -EBUSY;
43147
43148 if (cmd != SIOCWANDEV)
43149diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
43150index aba1e59..877ac33 100644
43151--- a/drivers/tty/synclink_gt.c
43152+++ b/drivers/tty/synclink_gt.c
43153@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43154 tty->driver_data = info;
43155 info->port.tty = tty;
43156
43157- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
43158+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
43159
43160 /* If port is closing, signal caller to try again */
43161 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43162@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43163 mutex_unlock(&info->port.mutex);
43164 goto cleanup;
43165 }
43166- info->port.count++;
43167+ atomic_inc(&info->port.count);
43168 spin_unlock_irqrestore(&info->netlock, flags);
43169
43170- if (info->port.count == 1) {
43171+ if (atomic_read(&info->port.count) == 1) {
43172 /* 1st open on this device, init hardware */
43173 retval = startup(info);
43174 if (retval < 0) {
43175@@ -716,8 +716,8 @@ cleanup:
43176 if (retval) {
43177 if (tty->count == 1)
43178 info->port.tty = NULL; /* tty layer will release tty struct */
43179- if(info->port.count)
43180- info->port.count--;
43181+ if(atomic_read(&info->port.count))
43182+ atomic_dec(&info->port.count);
43183 }
43184
43185 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
43186@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43187
43188 if (sanity_check(info, tty->name, "close"))
43189 return;
43190- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
43191+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
43192
43193 if (tty_port_close_start(&info->port, tty, filp) == 0)
43194 goto cleanup;
43195@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43196 tty_port_close_end(&info->port, tty);
43197 info->port.tty = NULL;
43198 cleanup:
43199- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
43200+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
43201 }
43202
43203 static void hangup(struct tty_struct *tty)
43204@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
43205 shutdown(info);
43206
43207 spin_lock_irqsave(&info->port.lock, flags);
43208- info->port.count = 0;
43209+ atomic_set(&info->port.count, 0);
43210 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43211 info->port.tty = NULL;
43212 spin_unlock_irqrestore(&info->port.lock, flags);
43213@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43214 unsigned short new_crctype;
43215
43216 /* return error if TTY interface open */
43217- if (info->port.count)
43218+ if (atomic_read(&info->port.count))
43219 return -EBUSY;
43220
43221 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
43222@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
43223
43224 /* arbitrate between network and tty opens */
43225 spin_lock_irqsave(&info->netlock, flags);
43226- if (info->port.count != 0 || info->netcount != 0) {
43227+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43228 DBGINFO(("%s hdlc_open busy\n", dev->name));
43229 spin_unlock_irqrestore(&info->netlock, flags);
43230 return -EBUSY;
43231@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43232 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
43233
43234 /* return error if TTY interface open */
43235- if (info->port.count)
43236+ if (atomic_read(&info->port.count))
43237 return -EBUSY;
43238
43239 if (cmd != SIOCWANDEV)
43240@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
43241 if (port == NULL)
43242 continue;
43243 spin_lock(&port->lock);
43244- if ((port->port.count || port->netcount) &&
43245+ if ((atomic_read(&port->port.count) || port->netcount) &&
43246 port->pending_bh && !port->bh_running &&
43247 !port->bh_requested) {
43248 DBGISR(("%s bh queued\n", port->device_name));
43249@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43250 spin_lock_irqsave(&info->lock, flags);
43251 if (!tty_hung_up_p(filp)) {
43252 extra_count = true;
43253- port->count--;
43254+ atomic_dec(&port->count);
43255 }
43256 spin_unlock_irqrestore(&info->lock, flags);
43257 port->blocked_open++;
43258@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43259 remove_wait_queue(&port->open_wait, &wait);
43260
43261 if (extra_count)
43262- port->count++;
43263+ atomic_inc(&port->count);
43264 port->blocked_open--;
43265
43266 if (!retval)
43267diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
43268index fd43fb6..34704ad 100644
43269--- a/drivers/tty/synclinkmp.c
43270+++ b/drivers/tty/synclinkmp.c
43271@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43272
43273 if (debug_level >= DEBUG_LEVEL_INFO)
43274 printk("%s(%d):%s open(), old ref count = %d\n",
43275- __FILE__,__LINE__,tty->driver->name, info->port.count);
43276+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43277
43278 /* If port is closing, signal caller to try again */
43279 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43280@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43281 spin_unlock_irqrestore(&info->netlock, flags);
43282 goto cleanup;
43283 }
43284- info->port.count++;
43285+ atomic_inc(&info->port.count);
43286 spin_unlock_irqrestore(&info->netlock, flags);
43287
43288- if (info->port.count == 1) {
43289+ if (atomic_read(&info->port.count) == 1) {
43290 /* 1st open on this device, init hardware */
43291 retval = startup(info);
43292 if (retval < 0)
43293@@ -797,8 +797,8 @@ cleanup:
43294 if (retval) {
43295 if (tty->count == 1)
43296 info->port.tty = NULL; /* tty layer will release tty struct */
43297- if(info->port.count)
43298- info->port.count--;
43299+ if(atomic_read(&info->port.count))
43300+ atomic_dec(&info->port.count);
43301 }
43302
43303 return retval;
43304@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43305
43306 if (debug_level >= DEBUG_LEVEL_INFO)
43307 printk("%s(%d):%s close() entry, count=%d\n",
43308- __FILE__,__LINE__, info->device_name, info->port.count);
43309+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43310
43311 if (tty_port_close_start(&info->port, tty, filp) == 0)
43312 goto cleanup;
43313@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43314 cleanup:
43315 if (debug_level >= DEBUG_LEVEL_INFO)
43316 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
43317- tty->driver->name, info->port.count);
43318+ tty->driver->name, atomic_read(&info->port.count));
43319 }
43320
43321 /* Called by tty_hangup() when a hangup is signaled.
43322@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
43323 shutdown(info);
43324
43325 spin_lock_irqsave(&info->port.lock, flags);
43326- info->port.count = 0;
43327+ atomic_set(&info->port.count, 0);
43328 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43329 info->port.tty = NULL;
43330 spin_unlock_irqrestore(&info->port.lock, flags);
43331@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43332 unsigned short new_crctype;
43333
43334 /* return error if TTY interface open */
43335- if (info->port.count)
43336+ if (atomic_read(&info->port.count))
43337 return -EBUSY;
43338
43339 switch (encoding)
43340@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
43341
43342 /* arbitrate between network and tty opens */
43343 spin_lock_irqsave(&info->netlock, flags);
43344- if (info->port.count != 0 || info->netcount != 0) {
43345+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43346 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43347 spin_unlock_irqrestore(&info->netlock, flags);
43348 return -EBUSY;
43349@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43350 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43351
43352 /* return error if TTY interface open */
43353- if (info->port.count)
43354+ if (atomic_read(&info->port.count))
43355 return -EBUSY;
43356
43357 if (cmd != SIOCWANDEV)
43358@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
43359 * do not request bottom half processing if the
43360 * device is not open in a normal mode.
43361 */
43362- if ( port && (port->port.count || port->netcount) &&
43363+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
43364 port->pending_bh && !port->bh_running &&
43365 !port->bh_requested ) {
43366 if ( debug_level >= DEBUG_LEVEL_ISR )
43367@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43368
43369 if (debug_level >= DEBUG_LEVEL_INFO)
43370 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
43371- __FILE__,__LINE__, tty->driver->name, port->count );
43372+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43373
43374 spin_lock_irqsave(&info->lock, flags);
43375 if (!tty_hung_up_p(filp)) {
43376 extra_count = true;
43377- port->count--;
43378+ atomic_dec(&port->count);
43379 }
43380 spin_unlock_irqrestore(&info->lock, flags);
43381 port->blocked_open++;
43382@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43383
43384 if (debug_level >= DEBUG_LEVEL_INFO)
43385 printk("%s(%d):%s block_til_ready() count=%d\n",
43386- __FILE__,__LINE__, tty->driver->name, port->count );
43387+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43388
43389 tty_unlock(tty);
43390 schedule();
43391@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43392 remove_wait_queue(&port->open_wait, &wait);
43393
43394 if (extra_count)
43395- port->count++;
43396+ atomic_inc(&port->count);
43397 port->blocked_open--;
43398
43399 if (debug_level >= DEBUG_LEVEL_INFO)
43400 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43401- __FILE__,__LINE__, tty->driver->name, port->count );
43402+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43403
43404 if (!retval)
43405 port->flags |= ASYNC_NORMAL_ACTIVE;
43406diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43407index b3c4a25..723916f 100644
43408--- a/drivers/tty/sysrq.c
43409+++ b/drivers/tty/sysrq.c
43410@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43411 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43412 size_t count, loff_t *ppos)
43413 {
43414- if (count) {
43415+ if (count && capable(CAP_SYS_ADMIN)) {
43416 char c;
43417
43418 if (get_user(c, buf))
43419diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43420index da9fde8..c07975f 100644
43421--- a/drivers/tty/tty_io.c
43422+++ b/drivers/tty/tty_io.c
43423@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43424
43425 void tty_default_fops(struct file_operations *fops)
43426 {
43427- *fops = tty_fops;
43428+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43429 }
43430
43431 /*
43432diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43433index c578229..45aa9ee 100644
43434--- a/drivers/tty/tty_ldisc.c
43435+++ b/drivers/tty/tty_ldisc.c
43436@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43437 if (atomic_dec_and_test(&ld->users)) {
43438 struct tty_ldisc_ops *ldo = ld->ops;
43439
43440- ldo->refcount--;
43441+ atomic_dec(&ldo->refcount);
43442 module_put(ldo->owner);
43443 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43444
43445@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43446 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43447 tty_ldiscs[disc] = new_ldisc;
43448 new_ldisc->num = disc;
43449- new_ldisc->refcount = 0;
43450+ atomic_set(&new_ldisc->refcount, 0);
43451 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43452
43453 return ret;
43454@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
43455 return -EINVAL;
43456
43457 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43458- if (tty_ldiscs[disc]->refcount)
43459+ if (atomic_read(&tty_ldiscs[disc]->refcount))
43460 ret = -EBUSY;
43461 else
43462 tty_ldiscs[disc] = NULL;
43463@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43464 if (ldops) {
43465 ret = ERR_PTR(-EAGAIN);
43466 if (try_module_get(ldops->owner)) {
43467- ldops->refcount++;
43468+ atomic_inc(&ldops->refcount);
43469 ret = ldops;
43470 }
43471 }
43472@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43473 unsigned long flags;
43474
43475 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43476- ldops->refcount--;
43477+ atomic_dec(&ldops->refcount);
43478 module_put(ldops->owner);
43479 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43480 }
43481diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43482index b7ff59d..7c6105e 100644
43483--- a/drivers/tty/tty_port.c
43484+++ b/drivers/tty/tty_port.c
43485@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43486 unsigned long flags;
43487
43488 spin_lock_irqsave(&port->lock, flags);
43489- port->count = 0;
43490+ atomic_set(&port->count, 0);
43491 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43492 if (port->tty) {
43493 set_bit(TTY_IO_ERROR, &port->tty->flags);
43494@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43495 /* The port lock protects the port counts */
43496 spin_lock_irqsave(&port->lock, flags);
43497 if (!tty_hung_up_p(filp))
43498- port->count--;
43499+ atomic_dec(&port->count);
43500 port->blocked_open++;
43501 spin_unlock_irqrestore(&port->lock, flags);
43502
43503@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43504 we must not mess that up further */
43505 spin_lock_irqsave(&port->lock, flags);
43506 if (!tty_hung_up_p(filp))
43507- port->count++;
43508+ atomic_inc(&port->count);
43509 port->blocked_open--;
43510 if (retval == 0)
43511 port->flags |= ASYNC_NORMAL_ACTIVE;
43512@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43513 return 0;
43514 }
43515
43516- if (tty->count == 1 && port->count != 1) {
43517+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
43518 printk(KERN_WARNING
43519 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43520- port->count);
43521- port->count = 1;
43522+ atomic_read(&port->count));
43523+ atomic_set(&port->count, 1);
43524 }
43525- if (--port->count < 0) {
43526+ if (atomic_dec_return(&port->count) < 0) {
43527 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43528- port->count);
43529- port->count = 0;
43530+ atomic_read(&port->count));
43531+ atomic_set(&port->count, 0);
43532 }
43533
43534- if (port->count) {
43535+ if (atomic_read(&port->count)) {
43536 spin_unlock_irqrestore(&port->lock, flags);
43537 if (port->ops->drop)
43538 port->ops->drop(port);
43539@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
43540 {
43541 spin_lock_irq(&port->lock);
43542 if (!tty_hung_up_p(filp))
43543- ++port->count;
43544+ atomic_inc(&port->count);
43545 spin_unlock_irq(&port->lock);
43546 tty_port_tty_set(port, tty);
43547
43548diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
43549index 681765b..d3ccdf2 100644
43550--- a/drivers/tty/vt/keyboard.c
43551+++ b/drivers/tty/vt/keyboard.c
43552@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
43553 kbd->kbdmode == VC_OFF) &&
43554 value != KVAL(K_SAK))
43555 return; /* SAK is allowed even in raw mode */
43556+
43557+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
43558+ {
43559+ void *func = fn_handler[value];
43560+ if (func == fn_show_state || func == fn_show_ptregs ||
43561+ func == fn_show_mem)
43562+ return;
43563+ }
43564+#endif
43565+
43566 fn_handler[value](vc);
43567 }
43568
43569@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43570 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
43571 return -EFAULT;
43572
43573- if (!capable(CAP_SYS_TTY_CONFIG))
43574- perm = 0;
43575-
43576 switch (cmd) {
43577 case KDGKBENT:
43578 /* Ensure another thread doesn't free it under us */
43579@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43580 spin_unlock_irqrestore(&kbd_event_lock, flags);
43581 return put_user(val, &user_kbe->kb_value);
43582 case KDSKBENT:
43583+ if (!capable(CAP_SYS_TTY_CONFIG))
43584+ perm = 0;
43585+
43586 if (!perm)
43587 return -EPERM;
43588 if (!i && v == K_NOSUCHMAP) {
43589@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43590 int i, j, k;
43591 int ret;
43592
43593- if (!capable(CAP_SYS_TTY_CONFIG))
43594- perm = 0;
43595-
43596 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
43597 if (!kbs) {
43598 ret = -ENOMEM;
43599@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43600 kfree(kbs);
43601 return ((p && *p) ? -EOVERFLOW : 0);
43602 case KDSKBSENT:
43603+ if (!capable(CAP_SYS_TTY_CONFIG))
43604+ perm = 0;
43605+
43606 if (!perm) {
43607 ret = -EPERM;
43608 goto reterr;
43609diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
43610index 5110f36..8dc0a74 100644
43611--- a/drivers/uio/uio.c
43612+++ b/drivers/uio/uio.c
43613@@ -25,6 +25,7 @@
43614 #include <linux/kobject.h>
43615 #include <linux/cdev.h>
43616 #include <linux/uio_driver.h>
43617+#include <asm/local.h>
43618
43619 #define UIO_MAX_DEVICES (1U << MINORBITS)
43620
43621@@ -32,10 +33,10 @@ struct uio_device {
43622 struct module *owner;
43623 struct device *dev;
43624 int minor;
43625- atomic_t event;
43626+ atomic_unchecked_t event;
43627 struct fasync_struct *async_queue;
43628 wait_queue_head_t wait;
43629- int vma_count;
43630+ local_t vma_count;
43631 struct uio_info *info;
43632 struct kobject *map_dir;
43633 struct kobject *portio_dir;
43634@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
43635 struct device_attribute *attr, char *buf)
43636 {
43637 struct uio_device *idev = dev_get_drvdata(dev);
43638- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
43639+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
43640 }
43641
43642 static struct device_attribute uio_class_attributes[] = {
43643@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
43644 {
43645 struct uio_device *idev = info->uio_dev;
43646
43647- atomic_inc(&idev->event);
43648+ atomic_inc_unchecked(&idev->event);
43649 wake_up_interruptible(&idev->wait);
43650 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
43651 }
43652@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
43653 }
43654
43655 listener->dev = idev;
43656- listener->event_count = atomic_read(&idev->event);
43657+ listener->event_count = atomic_read_unchecked(&idev->event);
43658 filep->private_data = listener;
43659
43660 if (idev->info->open) {
43661@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
43662 return -EIO;
43663
43664 poll_wait(filep, &idev->wait, wait);
43665- if (listener->event_count != atomic_read(&idev->event))
43666+ if (listener->event_count != atomic_read_unchecked(&idev->event))
43667 return POLLIN | POLLRDNORM;
43668 return 0;
43669 }
43670@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
43671 do {
43672 set_current_state(TASK_INTERRUPTIBLE);
43673
43674- event_count = atomic_read(&idev->event);
43675+ event_count = atomic_read_unchecked(&idev->event);
43676 if (event_count != listener->event_count) {
43677 if (copy_to_user(buf, &event_count, count))
43678 retval = -EFAULT;
43679@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
43680 static void uio_vma_open(struct vm_area_struct *vma)
43681 {
43682 struct uio_device *idev = vma->vm_private_data;
43683- idev->vma_count++;
43684+ local_inc(&idev->vma_count);
43685 }
43686
43687 static void uio_vma_close(struct vm_area_struct *vma)
43688 {
43689 struct uio_device *idev = vma->vm_private_data;
43690- idev->vma_count--;
43691+ local_dec(&idev->vma_count);
43692 }
43693
43694 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
43695@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
43696 idev->owner = owner;
43697 idev->info = info;
43698 init_waitqueue_head(&idev->wait);
43699- atomic_set(&idev->event, 0);
43700+ atomic_set_unchecked(&idev->event, 0);
43701
43702 ret = uio_get_minor(idev);
43703 if (ret)
43704diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
43705index b7eb86a..36d28af 100644
43706--- a/drivers/usb/atm/cxacru.c
43707+++ b/drivers/usb/atm/cxacru.c
43708@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
43709 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
43710 if (ret < 2)
43711 return -EINVAL;
43712- if (index < 0 || index > 0x7f)
43713+ if (index > 0x7f)
43714 return -EINVAL;
43715 pos += tmp;
43716
43717diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
43718index 35f10bf..6a38a0b 100644
43719--- a/drivers/usb/atm/usbatm.c
43720+++ b/drivers/usb/atm/usbatm.c
43721@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43722 if (printk_ratelimit())
43723 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
43724 __func__, vpi, vci);
43725- atomic_inc(&vcc->stats->rx_err);
43726+ atomic_inc_unchecked(&vcc->stats->rx_err);
43727 return;
43728 }
43729
43730@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43731 if (length > ATM_MAX_AAL5_PDU) {
43732 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
43733 __func__, length, vcc);
43734- atomic_inc(&vcc->stats->rx_err);
43735+ atomic_inc_unchecked(&vcc->stats->rx_err);
43736 goto out;
43737 }
43738
43739@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43740 if (sarb->len < pdu_length) {
43741 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
43742 __func__, pdu_length, sarb->len, vcc);
43743- atomic_inc(&vcc->stats->rx_err);
43744+ atomic_inc_unchecked(&vcc->stats->rx_err);
43745 goto out;
43746 }
43747
43748 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
43749 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
43750 __func__, vcc);
43751- atomic_inc(&vcc->stats->rx_err);
43752+ atomic_inc_unchecked(&vcc->stats->rx_err);
43753 goto out;
43754 }
43755
43756@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43757 if (printk_ratelimit())
43758 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
43759 __func__, length);
43760- atomic_inc(&vcc->stats->rx_drop);
43761+ atomic_inc_unchecked(&vcc->stats->rx_drop);
43762 goto out;
43763 }
43764
43765@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43766
43767 vcc->push(vcc, skb);
43768
43769- atomic_inc(&vcc->stats->rx);
43770+ atomic_inc_unchecked(&vcc->stats->rx);
43771 out:
43772 skb_trim(sarb, 0);
43773 }
43774@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
43775 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
43776
43777 usbatm_pop(vcc, skb);
43778- atomic_inc(&vcc->stats->tx);
43779+ atomic_inc_unchecked(&vcc->stats->tx);
43780
43781 skb = skb_dequeue(&instance->sndqueue);
43782 }
43783@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
43784 if (!left--)
43785 return sprintf(page,
43786 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
43787- atomic_read(&atm_dev->stats.aal5.tx),
43788- atomic_read(&atm_dev->stats.aal5.tx_err),
43789- atomic_read(&atm_dev->stats.aal5.rx),
43790- atomic_read(&atm_dev->stats.aal5.rx_err),
43791- atomic_read(&atm_dev->stats.aal5.rx_drop));
43792+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
43793+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
43794+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
43795+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
43796+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
43797
43798 if (!left--) {
43799 if (instance->disconnected)
43800diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
43801index 5f0cb41..122d056 100644
43802--- a/drivers/usb/class/cdc-wdm.c
43803+++ b/drivers/usb/class/cdc-wdm.c
43804@@ -56,6 +56,7 @@ MODULE_DEVICE_TABLE (usb, wdm_ids);
43805 #define WDM_RESPONDING 7
43806 #define WDM_SUSPENDING 8
43807 #define WDM_RESETTING 9
43808+#define WDM_OVERFLOW 10
43809
43810 #define WDM_MAX 16
43811
43812@@ -155,6 +156,7 @@ static void wdm_in_callback(struct urb *urb)
43813 {
43814 struct wdm_device *desc = urb->context;
43815 int status = urb->status;
43816+ int length = urb->actual_length;
43817
43818 spin_lock(&desc->iuspin);
43819 clear_bit(WDM_RESPONDING, &desc->flags);
43820@@ -185,9 +187,17 @@ static void wdm_in_callback(struct urb *urb)
43821 }
43822
43823 desc->rerr = status;
43824- desc->reslength = urb->actual_length;
43825- memmove(desc->ubuf + desc->length, desc->inbuf, desc->reslength);
43826- desc->length += desc->reslength;
43827+ if (length + desc->length > desc->wMaxCommand) {
43828+ /* The buffer would overflow */
43829+ set_bit(WDM_OVERFLOW, &desc->flags);
43830+ } else {
43831+ /* we may already be in overflow */
43832+ if (!test_bit(WDM_OVERFLOW, &desc->flags)) {
43833+ memmove(desc->ubuf + desc->length, desc->inbuf, length);
43834+ desc->length += length;
43835+ desc->reslength = length;
43836+ }
43837+ }
43838 skip_error:
43839 wake_up(&desc->wait);
43840
43841@@ -435,6 +445,11 @@ retry:
43842 rv = -ENODEV;
43843 goto err;
43844 }
43845+ if (test_bit(WDM_OVERFLOW, &desc->flags)) {
43846+ clear_bit(WDM_OVERFLOW, &desc->flags);
43847+ rv = -ENOBUFS;
43848+ goto err;
43849+ }
43850 i++;
43851 if (file->f_flags & O_NONBLOCK) {
43852 if (!test_bit(WDM_READ, &desc->flags)) {
43853@@ -478,6 +493,7 @@ retry:
43854 spin_unlock_irq(&desc->iuspin);
43855 goto retry;
43856 }
43857+
43858 if (!desc->reslength) { /* zero length read */
43859 dev_dbg(&desc->intf->dev, "%s: zero length - clearing WDM_READ\n", __func__);
43860 clear_bit(WDM_READ, &desc->flags);
43861@@ -1004,6 +1020,7 @@ static int wdm_post_reset(struct usb_interface *intf)
43862 struct wdm_device *desc = wdm_find_device(intf);
43863 int rv;
43864
43865+ clear_bit(WDM_OVERFLOW, &desc->flags);
43866 clear_bit(WDM_RESETTING, &desc->flags);
43867 rv = recover_from_urb_loss(desc);
43868 mutex_unlock(&desc->wlock);
43869diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
43870index cbacea9..246cccd 100644
43871--- a/drivers/usb/core/devices.c
43872+++ b/drivers/usb/core/devices.c
43873@@ -126,7 +126,7 @@ static const char format_endpt[] =
43874 * time it gets called.
43875 */
43876 static struct device_connect_event {
43877- atomic_t count;
43878+ atomic_unchecked_t count;
43879 wait_queue_head_t wait;
43880 } device_event = {
43881 .count = ATOMIC_INIT(1),
43882@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
43883
43884 void usbfs_conn_disc_event(void)
43885 {
43886- atomic_add(2, &device_event.count);
43887+ atomic_add_unchecked(2, &device_event.count);
43888 wake_up(&device_event.wait);
43889 }
43890
43891@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
43892
43893 poll_wait(file, &device_event.wait, wait);
43894
43895- event_count = atomic_read(&device_event.count);
43896+ event_count = atomic_read_unchecked(&device_event.count);
43897 if (file->f_version != event_count) {
43898 file->f_version = event_count;
43899 return POLLIN | POLLRDNORM;
43900diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
43901index 8e64adf..9a33a3c 100644
43902--- a/drivers/usb/core/hcd.c
43903+++ b/drivers/usb/core/hcd.c
43904@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43905 */
43906 usb_get_urb(urb);
43907 atomic_inc(&urb->use_count);
43908- atomic_inc(&urb->dev->urbnum);
43909+ atomic_inc_unchecked(&urb->dev->urbnum);
43910 usbmon_urb_submit(&hcd->self, urb);
43911
43912 /* NOTE requirements on root-hub callers (usbfs and the hub
43913@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43914 urb->hcpriv = NULL;
43915 INIT_LIST_HEAD(&urb->urb_list);
43916 atomic_dec(&urb->use_count);
43917- atomic_dec(&urb->dev->urbnum);
43918+ atomic_dec_unchecked(&urb->dev->urbnum);
43919 if (atomic_read(&urb->reject))
43920 wake_up(&usb_kill_urb_queue);
43921 usb_put_urb(urb);
43922diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
43923index 131f736..99004c3 100644
43924--- a/drivers/usb/core/message.c
43925+++ b/drivers/usb/core/message.c
43926@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
43927 * method can wait for it to complete. Since you don't have a handle on the
43928 * URB used, you can't cancel the request.
43929 */
43930-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
43931+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
43932 __u8 requesttype, __u16 value, __u16 index, void *data,
43933 __u16 size, int timeout)
43934 {
43935diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
43936index 818e4a0..0fc9589 100644
43937--- a/drivers/usb/core/sysfs.c
43938+++ b/drivers/usb/core/sysfs.c
43939@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
43940 struct usb_device *udev;
43941
43942 udev = to_usb_device(dev);
43943- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
43944+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
43945 }
43946 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
43947
43948diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
43949index f81b925..78d22ec 100644
43950--- a/drivers/usb/core/usb.c
43951+++ b/drivers/usb/core/usb.c
43952@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
43953 set_dev_node(&dev->dev, dev_to_node(bus->controller));
43954 dev->state = USB_STATE_ATTACHED;
43955 dev->lpm_disable_count = 1;
43956- atomic_set(&dev->urbnum, 0);
43957+ atomic_set_unchecked(&dev->urbnum, 0);
43958
43959 INIT_LIST_HEAD(&dev->ep0.urb_list);
43960 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
43961diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
43962index 5e29dde..eca992f 100644
43963--- a/drivers/usb/early/ehci-dbgp.c
43964+++ b/drivers/usb/early/ehci-dbgp.c
43965@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
43966
43967 #ifdef CONFIG_KGDB
43968 static struct kgdb_io kgdbdbgp_io_ops;
43969-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
43970+static struct kgdb_io kgdbdbgp_io_ops_console;
43971+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
43972 #else
43973 #define dbgp_kgdb_mode (0)
43974 #endif
43975@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
43976 .write_char = kgdbdbgp_write_char,
43977 };
43978
43979+static struct kgdb_io kgdbdbgp_io_ops_console = {
43980+ .name = "kgdbdbgp",
43981+ .read_char = kgdbdbgp_read_char,
43982+ .write_char = kgdbdbgp_write_char,
43983+ .is_console = 1
43984+};
43985+
43986 static int kgdbdbgp_wait_time;
43987
43988 static int __init kgdbdbgp_parse_config(char *str)
43989@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
43990 ptr++;
43991 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
43992 }
43993- kgdb_register_io_module(&kgdbdbgp_io_ops);
43994- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
43995+ if (early_dbgp_console.index != -1)
43996+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
43997+ else
43998+ kgdb_register_io_module(&kgdbdbgp_io_ops);
43999
44000 return 0;
44001 }
44002diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44003index 598dcc1..032dd4f 100644
44004--- a/drivers/usb/gadget/u_serial.c
44005+++ b/drivers/usb/gadget/u_serial.c
44006@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44007 spin_lock_irq(&port->port_lock);
44008
44009 /* already open? Great. */
44010- if (port->port.count) {
44011+ if (atomic_read(&port->port.count)) {
44012 status = 0;
44013- port->port.count++;
44014+ atomic_inc(&port->port.count);
44015
44016 /* currently opening/closing? wait ... */
44017 } else if (port->openclose) {
44018@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44019 tty->driver_data = port;
44020 port->port.tty = tty;
44021
44022- port->port.count = 1;
44023+ atomic_set(&port->port.count, 1);
44024 port->openclose = false;
44025
44026 /* if connected, start the I/O stream */
44027@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44028
44029 spin_lock_irq(&port->port_lock);
44030
44031- if (port->port.count != 1) {
44032- if (port->port.count == 0)
44033+ if (atomic_read(&port->port.count) != 1) {
44034+ if (atomic_read(&port->port.count) == 0)
44035 WARN_ON(1);
44036 else
44037- --port->port.count;
44038+ atomic_dec(&port->port.count);
44039 goto exit;
44040 }
44041
44042@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44043 * and sleep if necessary
44044 */
44045 port->openclose = true;
44046- port->port.count = 0;
44047+ atomic_set(&port->port.count, 0);
44048
44049 gser = port->port_usb;
44050 if (gser && gser->disconnect)
44051@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
44052 int cond;
44053
44054 spin_lock_irq(&port->port_lock);
44055- cond = (port->port.count == 0) && !port->openclose;
44056+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44057 spin_unlock_irq(&port->port_lock);
44058 return cond;
44059 }
44060@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44061 /* if it's already open, start I/O ... and notify the serial
44062 * protocol about open/close status (connect/disconnect).
44063 */
44064- if (port->port.count) {
44065+ if (atomic_read(&port->port.count)) {
44066 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44067 gs_start_io(port);
44068 if (gser->connect)
44069@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
44070
44071 port->port_usb = NULL;
44072 gser->ioport = NULL;
44073- if (port->port.count > 0 || port->openclose) {
44074+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44075 wake_up_interruptible(&port->drain_wait);
44076 if (port->port.tty)
44077 tty_hangup(port->port.tty);
44078@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
44079
44080 /* finally, free any unused/unusable I/O buffers */
44081 spin_lock_irqsave(&port->port_lock, flags);
44082- if (port->port.count == 0 && !port->openclose)
44083+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44084 gs_buf_free(&port->port_write_buf);
44085 gs_free_requests(gser->out, &port->read_pool, NULL);
44086 gs_free_requests(gser->out, &port->read_queue, NULL);
44087diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44088index 5f3bcd3..bfca43f 100644
44089--- a/drivers/usb/serial/console.c
44090+++ b/drivers/usb/serial/console.c
44091@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44092
44093 info->port = port;
44094
44095- ++port->port.count;
44096+ atomic_inc(&port->port.count);
44097 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44098 if (serial->type->set_termios) {
44099 /*
44100@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44101 }
44102 /* Now that any required fake tty operations are completed restore
44103 * the tty port count */
44104- --port->port.count;
44105+ atomic_dec(&port->port.count);
44106 /* The console is special in terms of closing the device so
44107 * indicate this port is now acting as a system console. */
44108 port->port.console = 1;
44109@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44110 free_tty:
44111 kfree(tty);
44112 reset_open_count:
44113- port->port.count = 0;
44114+ atomic_set(&port->port.count, 0);
44115 usb_autopm_put_interface(serial->interface);
44116 error_get_interface:
44117 usb_serial_put(serial);
44118diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44119index 75f70f0..d467e1a 100644
44120--- a/drivers/usb/storage/usb.h
44121+++ b/drivers/usb/storage/usb.h
44122@@ -63,7 +63,7 @@ struct us_unusual_dev {
44123 __u8 useProtocol;
44124 __u8 useTransport;
44125 int (*initFunction)(struct us_data *);
44126-};
44127+} __do_const;
44128
44129
44130 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44131diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44132index d6bea3e..60b250e 100644
44133--- a/drivers/usb/wusbcore/wa-hc.h
44134+++ b/drivers/usb/wusbcore/wa-hc.h
44135@@ -192,7 +192,7 @@ struct wahc {
44136 struct list_head xfer_delayed_list;
44137 spinlock_t xfer_list_lock;
44138 struct work_struct xfer_work;
44139- atomic_t xfer_id_count;
44140+ atomic_unchecked_t xfer_id_count;
44141 };
44142
44143
44144@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44145 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44146 spin_lock_init(&wa->xfer_list_lock);
44147 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44148- atomic_set(&wa->xfer_id_count, 1);
44149+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44150 }
44151
44152 /**
44153diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44154index 57c01ab..8a05959 100644
44155--- a/drivers/usb/wusbcore/wa-xfer.c
44156+++ b/drivers/usb/wusbcore/wa-xfer.c
44157@@ -296,7 +296,7 @@ out:
44158 */
44159 static void wa_xfer_id_init(struct wa_xfer *xfer)
44160 {
44161- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44162+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44163 }
44164
44165 /*
44166diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
44167index 8c55011..eed4ae1a 100644
44168--- a/drivers/video/aty/aty128fb.c
44169+++ b/drivers/video/aty/aty128fb.c
44170@@ -149,7 +149,7 @@ enum {
44171 };
44172
44173 /* Must match above enum */
44174-static char * const r128_family[] = {
44175+static const char * const r128_family[] = {
44176 "AGP",
44177 "PCI",
44178 "PRO AGP",
44179diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
44180index 4f27fdc..d3537e6 100644
44181--- a/drivers/video/aty/atyfb_base.c
44182+++ b/drivers/video/aty/atyfb_base.c
44183@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
44184 par->accel_flags = var->accel_flags; /* hack */
44185
44186 if (var->accel_flags) {
44187- info->fbops->fb_sync = atyfb_sync;
44188+ pax_open_kernel();
44189+ *(void **)&info->fbops->fb_sync = atyfb_sync;
44190+ pax_close_kernel();
44191 info->flags &= ~FBINFO_HWACCEL_DISABLED;
44192 } else {
44193- info->fbops->fb_sync = NULL;
44194+ pax_open_kernel();
44195+ *(void **)&info->fbops->fb_sync = NULL;
44196+ pax_close_kernel();
44197 info->flags |= FBINFO_HWACCEL_DISABLED;
44198 }
44199
44200diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
44201index 95ec042..e6affdd 100644
44202--- a/drivers/video/aty/mach64_cursor.c
44203+++ b/drivers/video/aty/mach64_cursor.c
44204@@ -7,6 +7,7 @@
44205 #include <linux/string.h>
44206
44207 #include <asm/io.h>
44208+#include <asm/pgtable.h>
44209
44210 #ifdef __sparc__
44211 #include <asm/fbio.h>
44212@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
44213 info->sprite.buf_align = 16; /* and 64 lines tall. */
44214 info->sprite.flags = FB_PIXMAP_IO;
44215
44216- info->fbops->fb_cursor = atyfb_cursor;
44217+ pax_open_kernel();
44218+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
44219+ pax_close_kernel();
44220
44221 return 0;
44222 }
44223diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
44224index 6c5ed6b..b727c88 100644
44225--- a/drivers/video/backlight/kb3886_bl.c
44226+++ b/drivers/video/backlight/kb3886_bl.c
44227@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
44228 static unsigned long kb3886bl_flags;
44229 #define KB3886BL_SUSPENDED 0x01
44230
44231-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
44232+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
44233 {
44234 .ident = "Sahara Touch-iT",
44235 .matches = {
44236diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
44237index 88cad6b..dd746c7 100644
44238--- a/drivers/video/fb_defio.c
44239+++ b/drivers/video/fb_defio.c
44240@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
44241
44242 BUG_ON(!fbdefio);
44243 mutex_init(&fbdefio->lock);
44244- info->fbops->fb_mmap = fb_deferred_io_mmap;
44245+ pax_open_kernel();
44246+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
44247+ pax_close_kernel();
44248 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
44249 INIT_LIST_HEAD(&fbdefio->pagelist);
44250 if (fbdefio->delay == 0) /* set a default of 1 s */
44251@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
44252 page->mapping = NULL;
44253 }
44254
44255- info->fbops->fb_mmap = NULL;
44256+ *(void **)&info->fbops->fb_mmap = NULL;
44257 mutex_destroy(&fbdefio->lock);
44258 }
44259 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
44260diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
44261index 5c3960d..15cf8fc 100644
44262--- a/drivers/video/fbcmap.c
44263+++ b/drivers/video/fbcmap.c
44264@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
44265 rc = -ENODEV;
44266 goto out;
44267 }
44268- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
44269- !info->fbops->fb_setcmap)) {
44270+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
44271 rc = -EINVAL;
44272 goto out1;
44273 }
44274diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
44275index dc61c12..e29796e 100644
44276--- a/drivers/video/fbmem.c
44277+++ b/drivers/video/fbmem.c
44278@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44279 image->dx += image->width + 8;
44280 }
44281 } else if (rotate == FB_ROTATE_UD) {
44282- for (x = 0; x < num && image->dx >= 0; x++) {
44283+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
44284 info->fbops->fb_imageblit(info, image);
44285 image->dx -= image->width + 8;
44286 }
44287@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44288 image->dy += image->height + 8;
44289 }
44290 } else if (rotate == FB_ROTATE_CCW) {
44291- for (x = 0; x < num && image->dy >= 0; x++) {
44292+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
44293 info->fbops->fb_imageblit(info, image);
44294 image->dy -= image->height + 8;
44295 }
44296@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
44297 return -EFAULT;
44298 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
44299 return -EINVAL;
44300- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
44301+ if (con2fb.framebuffer >= FB_MAX)
44302 return -EINVAL;
44303 if (!registered_fb[con2fb.framebuffer])
44304 request_module("fb%d", con2fb.framebuffer);
44305diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
44306index 7672d2e..b56437f 100644
44307--- a/drivers/video/i810/i810_accel.c
44308+++ b/drivers/video/i810/i810_accel.c
44309@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
44310 }
44311 }
44312 printk("ringbuffer lockup!!!\n");
44313+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
44314 i810_report_error(mmio);
44315 par->dev_flags |= LOCKUP;
44316 info->pixmap.scan_align = 1;
44317diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
44318index 3c14e43..eafa544 100644
44319--- a/drivers/video/logo/logo_linux_clut224.ppm
44320+++ b/drivers/video/logo/logo_linux_clut224.ppm
44321@@ -1,1604 +1,1123 @@
44322 P3
44323-# Standard 224-color Linux logo
44324 80 80
44325 255
44326- 0 0 0 0 0 0 0 0 0 0 0 0
44327- 0 0 0 0 0 0 0 0 0 0 0 0
44328- 0 0 0 0 0 0 0 0 0 0 0 0
44329- 0 0 0 0 0 0 0 0 0 0 0 0
44330- 0 0 0 0 0 0 0 0 0 0 0 0
44331- 0 0 0 0 0 0 0 0 0 0 0 0
44332- 0 0 0 0 0 0 0 0 0 0 0 0
44333- 0 0 0 0 0 0 0 0 0 0 0 0
44334- 0 0 0 0 0 0 0 0 0 0 0 0
44335- 6 6 6 6 6 6 10 10 10 10 10 10
44336- 10 10 10 6 6 6 6 6 6 6 6 6
44337- 0 0 0 0 0 0 0 0 0 0 0 0
44338- 0 0 0 0 0 0 0 0 0 0 0 0
44339- 0 0 0 0 0 0 0 0 0 0 0 0
44340- 0 0 0 0 0 0 0 0 0 0 0 0
44341- 0 0 0 0 0 0 0 0 0 0 0 0
44342- 0 0 0 0 0 0 0 0 0 0 0 0
44343- 0 0 0 0 0 0 0 0 0 0 0 0
44344- 0 0 0 0 0 0 0 0 0 0 0 0
44345- 0 0 0 0 0 0 0 0 0 0 0 0
44346- 0 0 0 0 0 0 0 0 0 0 0 0
44347- 0 0 0 0 0 0 0 0 0 0 0 0
44348- 0 0 0 0 0 0 0 0 0 0 0 0
44349- 0 0 0 0 0 0 0 0 0 0 0 0
44350- 0 0 0 0 0 0 0 0 0 0 0 0
44351- 0 0 0 0 0 0 0 0 0 0 0 0
44352- 0 0 0 0 0 0 0 0 0 0 0 0
44353- 0 0 0 0 0 0 0 0 0 0 0 0
44354- 0 0 0 6 6 6 10 10 10 14 14 14
44355- 22 22 22 26 26 26 30 30 30 34 34 34
44356- 30 30 30 30 30 30 26 26 26 18 18 18
44357- 14 14 14 10 10 10 6 6 6 0 0 0
44358- 0 0 0 0 0 0 0 0 0 0 0 0
44359- 0 0 0 0 0 0 0 0 0 0 0 0
44360- 0 0 0 0 0 0 0 0 0 0 0 0
44361- 0 0 0 0 0 0 0 0 0 0 0 0
44362- 0 0 0 0 0 0 0 0 0 0 0 0
44363- 0 0 0 0 0 0 0 0 0 0 0 0
44364- 0 0 0 0 0 0 0 0 0 0 0 0
44365- 0 0 0 0 0 0 0 0 0 0 0 0
44366- 0 0 0 0 0 0 0 0 0 0 0 0
44367- 0 0 0 0 0 1 0 0 1 0 0 0
44368- 0 0 0 0 0 0 0 0 0 0 0 0
44369- 0 0 0 0 0 0 0 0 0 0 0 0
44370- 0 0 0 0 0 0 0 0 0 0 0 0
44371- 0 0 0 0 0 0 0 0 0 0 0 0
44372- 0 0 0 0 0 0 0 0 0 0 0 0
44373- 0 0 0 0 0 0 0 0 0 0 0 0
44374- 6 6 6 14 14 14 26 26 26 42 42 42
44375- 54 54 54 66 66 66 78 78 78 78 78 78
44376- 78 78 78 74 74 74 66 66 66 54 54 54
44377- 42 42 42 26 26 26 18 18 18 10 10 10
44378- 6 6 6 0 0 0 0 0 0 0 0 0
44379- 0 0 0 0 0 0 0 0 0 0 0 0
44380- 0 0 0 0 0 0 0 0 0 0 0 0
44381- 0 0 0 0 0 0 0 0 0 0 0 0
44382- 0 0 0 0 0 0 0 0 0 0 0 0
44383- 0 0 0 0 0 0 0 0 0 0 0 0
44384- 0 0 0 0 0 0 0 0 0 0 0 0
44385- 0 0 0 0 0 0 0 0 0 0 0 0
44386- 0 0 0 0 0 0 0 0 0 0 0 0
44387- 0 0 1 0 0 0 0 0 0 0 0 0
44388- 0 0 0 0 0 0 0 0 0 0 0 0
44389- 0 0 0 0 0 0 0 0 0 0 0 0
44390- 0 0 0 0 0 0 0 0 0 0 0 0
44391- 0 0 0 0 0 0 0 0 0 0 0 0
44392- 0 0 0 0 0 0 0 0 0 0 0 0
44393- 0 0 0 0 0 0 0 0 0 10 10 10
44394- 22 22 22 42 42 42 66 66 66 86 86 86
44395- 66 66 66 38 38 38 38 38 38 22 22 22
44396- 26 26 26 34 34 34 54 54 54 66 66 66
44397- 86 86 86 70 70 70 46 46 46 26 26 26
44398- 14 14 14 6 6 6 0 0 0 0 0 0
44399- 0 0 0 0 0 0 0 0 0 0 0 0
44400- 0 0 0 0 0 0 0 0 0 0 0 0
44401- 0 0 0 0 0 0 0 0 0 0 0 0
44402- 0 0 0 0 0 0 0 0 0 0 0 0
44403- 0 0 0 0 0 0 0 0 0 0 0 0
44404- 0 0 0 0 0 0 0 0 0 0 0 0
44405- 0 0 0 0 0 0 0 0 0 0 0 0
44406- 0 0 0 0 0 0 0 0 0 0 0 0
44407- 0 0 1 0 0 1 0 0 1 0 0 0
44408- 0 0 0 0 0 0 0 0 0 0 0 0
44409- 0 0 0 0 0 0 0 0 0 0 0 0
44410- 0 0 0 0 0 0 0 0 0 0 0 0
44411- 0 0 0 0 0 0 0 0 0 0 0 0
44412- 0 0 0 0 0 0 0 0 0 0 0 0
44413- 0 0 0 0 0 0 10 10 10 26 26 26
44414- 50 50 50 82 82 82 58 58 58 6 6 6
44415- 2 2 6 2 2 6 2 2 6 2 2 6
44416- 2 2 6 2 2 6 2 2 6 2 2 6
44417- 6 6 6 54 54 54 86 86 86 66 66 66
44418- 38 38 38 18 18 18 6 6 6 0 0 0
44419- 0 0 0 0 0 0 0 0 0 0 0 0
44420- 0 0 0 0 0 0 0 0 0 0 0 0
44421- 0 0 0 0 0 0 0 0 0 0 0 0
44422- 0 0 0 0 0 0 0 0 0 0 0 0
44423- 0 0 0 0 0 0 0 0 0 0 0 0
44424- 0 0 0 0 0 0 0 0 0 0 0 0
44425- 0 0 0 0 0 0 0 0 0 0 0 0
44426- 0 0 0 0 0 0 0 0 0 0 0 0
44427- 0 0 0 0 0 0 0 0 0 0 0 0
44428- 0 0 0 0 0 0 0 0 0 0 0 0
44429- 0 0 0 0 0 0 0 0 0 0 0 0
44430- 0 0 0 0 0 0 0 0 0 0 0 0
44431- 0 0 0 0 0 0 0 0 0 0 0 0
44432- 0 0 0 0 0 0 0 0 0 0 0 0
44433- 0 0 0 6 6 6 22 22 22 50 50 50
44434- 78 78 78 34 34 34 2 2 6 2 2 6
44435- 2 2 6 2 2 6 2 2 6 2 2 6
44436- 2 2 6 2 2 6 2 2 6 2 2 6
44437- 2 2 6 2 2 6 6 6 6 70 70 70
44438- 78 78 78 46 46 46 22 22 22 6 6 6
44439- 0 0 0 0 0 0 0 0 0 0 0 0
44440- 0 0 0 0 0 0 0 0 0 0 0 0
44441- 0 0 0 0 0 0 0 0 0 0 0 0
44442- 0 0 0 0 0 0 0 0 0 0 0 0
44443- 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
44448- 0 0 0 0 0 0 0 0 0 0 0 0
44449- 0 0 0 0 0 0 0 0 0 0 0 0
44450- 0 0 0 0 0 0 0 0 0 0 0 0
44451- 0 0 0 0 0 0 0 0 0 0 0 0
44452- 0 0 0 0 0 0 0 0 0 0 0 0
44453- 6 6 6 18 18 18 42 42 42 82 82 82
44454- 26 26 26 2 2 6 2 2 6 2 2 6
44455- 2 2 6 2 2 6 2 2 6 2 2 6
44456- 2 2 6 2 2 6 2 2 6 14 14 14
44457- 46 46 46 34 34 34 6 6 6 2 2 6
44458- 42 42 42 78 78 78 42 42 42 18 18 18
44459- 6 6 6 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 1 0 0 0 0 0 1 0 0 0
44468- 0 0 0 0 0 0 0 0 0 0 0 0
44469- 0 0 0 0 0 0 0 0 0 0 0 0
44470- 0 0 0 0 0 0 0 0 0 0 0 0
44471- 0 0 0 0 0 0 0 0 0 0 0 0
44472- 0 0 0 0 0 0 0 0 0 0 0 0
44473- 10 10 10 30 30 30 66 66 66 58 58 58
44474- 2 2 6 2 2 6 2 2 6 2 2 6
44475- 2 2 6 2 2 6 2 2 6 2 2 6
44476- 2 2 6 2 2 6 2 2 6 26 26 26
44477- 86 86 86 101 101 101 46 46 46 10 10 10
44478- 2 2 6 58 58 58 70 70 70 34 34 34
44479- 10 10 10 0 0 0 0 0 0 0 0 0
44480- 0 0 0 0 0 0 0 0 0 0 0 0
44481- 0 0 0 0 0 0 0 0 0 0 0 0
44482- 0 0 0 0 0 0 0 0 0 0 0 0
44483- 0 0 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 1 0 0 1 0 0 1 0 0 0
44488- 0 0 0 0 0 0 0 0 0 0 0 0
44489- 0 0 0 0 0 0 0 0 0 0 0 0
44490- 0 0 0 0 0 0 0 0 0 0 0 0
44491- 0 0 0 0 0 0 0 0 0 0 0 0
44492- 0 0 0 0 0 0 0 0 0 0 0 0
44493- 14 14 14 42 42 42 86 86 86 10 10 10
44494- 2 2 6 2 2 6 2 2 6 2 2 6
44495- 2 2 6 2 2 6 2 2 6 2 2 6
44496- 2 2 6 2 2 6 2 2 6 30 30 30
44497- 94 94 94 94 94 94 58 58 58 26 26 26
44498- 2 2 6 6 6 6 78 78 78 54 54 54
44499- 22 22 22 6 6 6 0 0 0 0 0 0
44500- 0 0 0 0 0 0 0 0 0 0 0 0
44501- 0 0 0 0 0 0 0 0 0 0 0 0
44502- 0 0 0 0 0 0 0 0 0 0 0 0
44503- 0 0 0 0 0 0 0 0 0 0 0 0
44504- 0 0 0 0 0 0 0 0 0 0 0 0
44505- 0 0 0 0 0 0 0 0 0 0 0 0
44506- 0 0 0 0 0 0 0 0 0 0 0 0
44507- 0 0 0 0 0 0 0 0 0 0 0 0
44508- 0 0 0 0 0 0 0 0 0 0 0 0
44509- 0 0 0 0 0 0 0 0 0 0 0 0
44510- 0 0 0 0 0 0 0 0 0 0 0 0
44511- 0 0 0 0 0 0 0 0 0 0 0 0
44512- 0 0 0 0 0 0 0 0 0 6 6 6
44513- 22 22 22 62 62 62 62 62 62 2 2 6
44514- 2 2 6 2 2 6 2 2 6 2 2 6
44515- 2 2 6 2 2 6 2 2 6 2 2 6
44516- 2 2 6 2 2 6 2 2 6 26 26 26
44517- 54 54 54 38 38 38 18 18 18 10 10 10
44518- 2 2 6 2 2 6 34 34 34 82 82 82
44519- 38 38 38 14 14 14 0 0 0 0 0 0
44520- 0 0 0 0 0 0 0 0 0 0 0 0
44521- 0 0 0 0 0 0 0 0 0 0 0 0
44522- 0 0 0 0 0 0 0 0 0 0 0 0
44523- 0 0 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 1 0 0 1 0 0 0
44528- 0 0 0 0 0 0 0 0 0 0 0 0
44529- 0 0 0 0 0 0 0 0 0 0 0 0
44530- 0 0 0 0 0 0 0 0 0 0 0 0
44531- 0 0 0 0 0 0 0 0 0 0 0 0
44532- 0 0 0 0 0 0 0 0 0 6 6 6
44533- 30 30 30 78 78 78 30 30 30 2 2 6
44534- 2 2 6 2 2 6 2 2 6 2 2 6
44535- 2 2 6 2 2 6 2 2 6 2 2 6
44536- 2 2 6 2 2 6 2 2 6 10 10 10
44537- 10 10 10 2 2 6 2 2 6 2 2 6
44538- 2 2 6 2 2 6 2 2 6 78 78 78
44539- 50 50 50 18 18 18 6 6 6 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 1 0 0 0 0 0 0 0 0 0
44548- 0 0 0 0 0 0 0 0 0 0 0 0
44549- 0 0 0 0 0 0 0 0 0 0 0 0
44550- 0 0 0 0 0 0 0 0 0 0 0 0
44551- 0 0 0 0 0 0 0 0 0 0 0 0
44552- 0 0 0 0 0 0 0 0 0 10 10 10
44553- 38 38 38 86 86 86 14 14 14 2 2 6
44554- 2 2 6 2 2 6 2 2 6 2 2 6
44555- 2 2 6 2 2 6 2 2 6 2 2 6
44556- 2 2 6 2 2 6 2 2 6 2 2 6
44557- 2 2 6 2 2 6 2 2 6 2 2 6
44558- 2 2 6 2 2 6 2 2 6 54 54 54
44559- 66 66 66 26 26 26 6 6 6 0 0 0
44560- 0 0 0 0 0 0 0 0 0 0 0 0
44561- 0 0 0 0 0 0 0 0 0 0 0 0
44562- 0 0 0 0 0 0 0 0 0 0 0 0
44563- 0 0 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 1 0 0 1 0 0 0
44568- 0 0 0 0 0 0 0 0 0 0 0 0
44569- 0 0 0 0 0 0 0 0 0 0 0 0
44570- 0 0 0 0 0 0 0 0 0 0 0 0
44571- 0 0 0 0 0 0 0 0 0 0 0 0
44572- 0 0 0 0 0 0 0 0 0 14 14 14
44573- 42 42 42 82 82 82 2 2 6 2 2 6
44574- 2 2 6 6 6 6 10 10 10 2 2 6
44575- 2 2 6 2 2 6 2 2 6 2 2 6
44576- 2 2 6 2 2 6 2 2 6 6 6 6
44577- 14 14 14 10 10 10 2 2 6 2 2 6
44578- 2 2 6 2 2 6 2 2 6 18 18 18
44579- 82 82 82 34 34 34 10 10 10 0 0 0
44580- 0 0 0 0 0 0 0 0 0 0 0 0
44581- 0 0 0 0 0 0 0 0 0 0 0 0
44582- 0 0 0 0 0 0 0 0 0 0 0 0
44583- 0 0 0 0 0 0 0 0 0 0 0 0
44584- 0 0 0 0 0 0 0 0 0 0 0 0
44585- 0 0 0 0 0 0 0 0 0 0 0 0
44586- 0 0 0 0 0 0 0 0 0 0 0 0
44587- 0 0 1 0 0 0 0 0 0 0 0 0
44588- 0 0 0 0 0 0 0 0 0 0 0 0
44589- 0 0 0 0 0 0 0 0 0 0 0 0
44590- 0 0 0 0 0 0 0 0 0 0 0 0
44591- 0 0 0 0 0 0 0 0 0 0 0 0
44592- 0 0 0 0 0 0 0 0 0 14 14 14
44593- 46 46 46 86 86 86 2 2 6 2 2 6
44594- 6 6 6 6 6 6 22 22 22 34 34 34
44595- 6 6 6 2 2 6 2 2 6 2 2 6
44596- 2 2 6 2 2 6 18 18 18 34 34 34
44597- 10 10 10 50 50 50 22 22 22 2 2 6
44598- 2 2 6 2 2 6 2 2 6 10 10 10
44599- 86 86 86 42 42 42 14 14 14 0 0 0
44600- 0 0 0 0 0 0 0 0 0 0 0 0
44601- 0 0 0 0 0 0 0 0 0 0 0 0
44602- 0 0 0 0 0 0 0 0 0 0 0 0
44603- 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
44608- 0 0 0 0 0 0 0 0 0 0 0 0
44609- 0 0 0 0 0 0 0 0 0 0 0 0
44610- 0 0 0 0 0 0 0 0 0 0 0 0
44611- 0 0 0 0 0 0 0 0 0 0 0 0
44612- 0 0 0 0 0 0 0 0 0 14 14 14
44613- 46 46 46 86 86 86 2 2 6 2 2 6
44614- 38 38 38 116 116 116 94 94 94 22 22 22
44615- 22 22 22 2 2 6 2 2 6 2 2 6
44616- 14 14 14 86 86 86 138 138 138 162 162 162
44617-154 154 154 38 38 38 26 26 26 6 6 6
44618- 2 2 6 2 2 6 2 2 6 2 2 6
44619- 86 86 86 46 46 46 14 14 14 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 0 0 0
44628- 0 0 0 0 0 0 0 0 0 0 0 0
44629- 0 0 0 0 0 0 0 0 0 0 0 0
44630- 0 0 0 0 0 0 0 0 0 0 0 0
44631- 0 0 0 0 0 0 0 0 0 0 0 0
44632- 0 0 0 0 0 0 0 0 0 14 14 14
44633- 46 46 46 86 86 86 2 2 6 14 14 14
44634-134 134 134 198 198 198 195 195 195 116 116 116
44635- 10 10 10 2 2 6 2 2 6 6 6 6
44636-101 98 89 187 187 187 210 210 210 218 218 218
44637-214 214 214 134 134 134 14 14 14 6 6 6
44638- 2 2 6 2 2 6 2 2 6 2 2 6
44639- 86 86 86 50 50 50 18 18 18 6 6 6
44640- 0 0 0 0 0 0 0 0 0 0 0 0
44641- 0 0 0 0 0 0 0 0 0 0 0 0
44642- 0 0 0 0 0 0 0 0 0 0 0 0
44643- 0 0 0 0 0 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 1 0 0 0
44647- 0 0 1 0 0 1 0 0 1 0 0 0
44648- 0 0 0 0 0 0 0 0 0 0 0 0
44649- 0 0 0 0 0 0 0 0 0 0 0 0
44650- 0 0 0 0 0 0 0 0 0 0 0 0
44651- 0 0 0 0 0 0 0 0 0 0 0 0
44652- 0 0 0 0 0 0 0 0 0 14 14 14
44653- 46 46 46 86 86 86 2 2 6 54 54 54
44654-218 218 218 195 195 195 226 226 226 246 246 246
44655- 58 58 58 2 2 6 2 2 6 30 30 30
44656-210 210 210 253 253 253 174 174 174 123 123 123
44657-221 221 221 234 234 234 74 74 74 2 2 6
44658- 2 2 6 2 2 6 2 2 6 2 2 6
44659- 70 70 70 58 58 58 22 22 22 6 6 6
44660- 0 0 0 0 0 0 0 0 0 0 0 0
44661- 0 0 0 0 0 0 0 0 0 0 0 0
44662- 0 0 0 0 0 0 0 0 0 0 0 0
44663- 0 0 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 0 0 0
44668- 0 0 0 0 0 0 0 0 0 0 0 0
44669- 0 0 0 0 0 0 0 0 0 0 0 0
44670- 0 0 0 0 0 0 0 0 0 0 0 0
44671- 0 0 0 0 0 0 0 0 0 0 0 0
44672- 0 0 0 0 0 0 0 0 0 14 14 14
44673- 46 46 46 82 82 82 2 2 6 106 106 106
44674-170 170 170 26 26 26 86 86 86 226 226 226
44675-123 123 123 10 10 10 14 14 14 46 46 46
44676-231 231 231 190 190 190 6 6 6 70 70 70
44677- 90 90 90 238 238 238 158 158 158 2 2 6
44678- 2 2 6 2 2 6 2 2 6 2 2 6
44679- 70 70 70 58 58 58 22 22 22 6 6 6
44680- 0 0 0 0 0 0 0 0 0 0 0 0
44681- 0 0 0 0 0 0 0 0 0 0 0 0
44682- 0 0 0 0 0 0 0 0 0 0 0 0
44683- 0 0 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 1 0 0 0
44687- 0 0 1 0 0 1 0 0 1 0 0 0
44688- 0 0 0 0 0 0 0 0 0 0 0 0
44689- 0 0 0 0 0 0 0 0 0 0 0 0
44690- 0 0 0 0 0 0 0 0 0 0 0 0
44691- 0 0 0 0 0 0 0 0 0 0 0 0
44692- 0 0 0 0 0 0 0 0 0 14 14 14
44693- 42 42 42 86 86 86 6 6 6 116 116 116
44694-106 106 106 6 6 6 70 70 70 149 149 149
44695-128 128 128 18 18 18 38 38 38 54 54 54
44696-221 221 221 106 106 106 2 2 6 14 14 14
44697- 46 46 46 190 190 190 198 198 198 2 2 6
44698- 2 2 6 2 2 6 2 2 6 2 2 6
44699- 74 74 74 62 62 62 22 22 22 6 6 6
44700- 0 0 0 0 0 0 0 0 0 0 0 0
44701- 0 0 0 0 0 0 0 0 0 0 0 0
44702- 0 0 0 0 0 0 0 0 0 0 0 0
44703- 0 0 0 0 0 0 0 0 0 0 0 0
44704- 0 0 0 0 0 0 0 0 0 0 0 0
44705- 0 0 0 0 0 0 0 0 0 0 0 0
44706- 0 0 0 0 0 0 0 0 1 0 0 0
44707- 0 0 1 0 0 0 0 0 1 0 0 0
44708- 0 0 0 0 0 0 0 0 0 0 0 0
44709- 0 0 0 0 0 0 0 0 0 0 0 0
44710- 0 0 0 0 0 0 0 0 0 0 0 0
44711- 0 0 0 0 0 0 0 0 0 0 0 0
44712- 0 0 0 0 0 0 0 0 0 14 14 14
44713- 42 42 42 94 94 94 14 14 14 101 101 101
44714-128 128 128 2 2 6 18 18 18 116 116 116
44715-118 98 46 121 92 8 121 92 8 98 78 10
44716-162 162 162 106 106 106 2 2 6 2 2 6
44717- 2 2 6 195 195 195 195 195 195 6 6 6
44718- 2 2 6 2 2 6 2 2 6 2 2 6
44719- 74 74 74 62 62 62 22 22 22 6 6 6
44720- 0 0 0 0 0 0 0 0 0 0 0 0
44721- 0 0 0 0 0 0 0 0 0 0 0 0
44722- 0 0 0 0 0 0 0 0 0 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 1 0 0 1
44727- 0 0 1 0 0 0 0 0 1 0 0 0
44728- 0 0 0 0 0 0 0 0 0 0 0 0
44729- 0 0 0 0 0 0 0 0 0 0 0 0
44730- 0 0 0 0 0 0 0 0 0 0 0 0
44731- 0 0 0 0 0 0 0 0 0 0 0 0
44732- 0 0 0 0 0 0 0 0 0 10 10 10
44733- 38 38 38 90 90 90 14 14 14 58 58 58
44734-210 210 210 26 26 26 54 38 6 154 114 10
44735-226 170 11 236 186 11 225 175 15 184 144 12
44736-215 174 15 175 146 61 37 26 9 2 2 6
44737- 70 70 70 246 246 246 138 138 138 2 2 6
44738- 2 2 6 2 2 6 2 2 6 2 2 6
44739- 70 70 70 66 66 66 26 26 26 6 6 6
44740- 0 0 0 0 0 0 0 0 0 0 0 0
44741- 0 0 0 0 0 0 0 0 0 0 0 0
44742- 0 0 0 0 0 0 0 0 0 0 0 0
44743- 0 0 0 0 0 0 0 0 0 0 0 0
44744- 0 0 0 0 0 0 0 0 0 0 0 0
44745- 0 0 0 0 0 0 0 0 0 0 0 0
44746- 0 0 0 0 0 0 0 0 0 0 0 0
44747- 0 0 0 0 0 0 0 0 0 0 0 0
44748- 0 0 0 0 0 0 0 0 0 0 0 0
44749- 0 0 0 0 0 0 0 0 0 0 0 0
44750- 0 0 0 0 0 0 0 0 0 0 0 0
44751- 0 0 0 0 0 0 0 0 0 0 0 0
44752- 0 0 0 0 0 0 0 0 0 10 10 10
44753- 38 38 38 86 86 86 14 14 14 10 10 10
44754-195 195 195 188 164 115 192 133 9 225 175 15
44755-239 182 13 234 190 10 232 195 16 232 200 30
44756-245 207 45 241 208 19 232 195 16 184 144 12
44757-218 194 134 211 206 186 42 42 42 2 2 6
44758- 2 2 6 2 2 6 2 2 6 2 2 6
44759- 50 50 50 74 74 74 30 30 30 6 6 6
44760- 0 0 0 0 0 0 0 0 0 0 0 0
44761- 0 0 0 0 0 0 0 0 0 0 0 0
44762- 0 0 0 0 0 0 0 0 0 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 0 0 0
44768- 0 0 0 0 0 0 0 0 0 0 0 0
44769- 0 0 0 0 0 0 0 0 0 0 0 0
44770- 0 0 0 0 0 0 0 0 0 0 0 0
44771- 0 0 0 0 0 0 0 0 0 0 0 0
44772- 0 0 0 0 0 0 0 0 0 10 10 10
44773- 34 34 34 86 86 86 14 14 14 2 2 6
44774-121 87 25 192 133 9 219 162 10 239 182 13
44775-236 186 11 232 195 16 241 208 19 244 214 54
44776-246 218 60 246 218 38 246 215 20 241 208 19
44777-241 208 19 226 184 13 121 87 25 2 2 6
44778- 2 2 6 2 2 6 2 2 6 2 2 6
44779- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
44788- 0 0 0 0 0 0 0 0 0 0 0 0
44789- 0 0 0 0 0 0 0 0 0 0 0 0
44790- 0 0 0 0 0 0 0 0 0 0 0 0
44791- 0 0 0 0 0 0 0 0 0 0 0 0
44792- 0 0 0 0 0 0 0 0 0 10 10 10
44793- 34 34 34 82 82 82 30 30 30 61 42 6
44794-180 123 7 206 145 10 230 174 11 239 182 13
44795-234 190 10 238 202 15 241 208 19 246 218 74
44796-246 218 38 246 215 20 246 215 20 246 215 20
44797-226 184 13 215 174 15 184 144 12 6 6 6
44798- 2 2 6 2 2 6 2 2 6 2 2 6
44799- 26 26 26 94 94 94 42 42 42 14 14 14
44800- 0 0 0 0 0 0 0 0 0 0 0 0
44801- 0 0 0 0 0 0 0 0 0 0 0 0
44802- 0 0 0 0 0 0 0 0 0 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 0 0 0
44808- 0 0 0 0 0 0 0 0 0 0 0 0
44809- 0 0 0 0 0 0 0 0 0 0 0 0
44810- 0 0 0 0 0 0 0 0 0 0 0 0
44811- 0 0 0 0 0 0 0 0 0 0 0 0
44812- 0 0 0 0 0 0 0 0 0 10 10 10
44813- 30 30 30 78 78 78 50 50 50 104 69 6
44814-192 133 9 216 158 10 236 178 12 236 186 11
44815-232 195 16 241 208 19 244 214 54 245 215 43
44816-246 215 20 246 215 20 241 208 19 198 155 10
44817-200 144 11 216 158 10 156 118 10 2 2 6
44818- 2 2 6 2 2 6 2 2 6 2 2 6
44819- 6 6 6 90 90 90 54 54 54 18 18 18
44820- 6 6 6 0 0 0 0 0 0 0 0 0
44821- 0 0 0 0 0 0 0 0 0 0 0 0
44822- 0 0 0 0 0 0 0 0 0 0 0 0
44823- 0 0 0 0 0 0 0 0 0 0 0 0
44824- 0 0 0 0 0 0 0 0 0 0 0 0
44825- 0 0 0 0 0 0 0 0 0 0 0 0
44826- 0 0 0 0 0 0 0 0 0 0 0 0
44827- 0 0 0 0 0 0 0 0 0 0 0 0
44828- 0 0 0 0 0 0 0 0 0 0 0 0
44829- 0 0 0 0 0 0 0 0 0 0 0 0
44830- 0 0 0 0 0 0 0 0 0 0 0 0
44831- 0 0 0 0 0 0 0 0 0 0 0 0
44832- 0 0 0 0 0 0 0 0 0 10 10 10
44833- 30 30 30 78 78 78 46 46 46 22 22 22
44834-137 92 6 210 162 10 239 182 13 238 190 10
44835-238 202 15 241 208 19 246 215 20 246 215 20
44836-241 208 19 203 166 17 185 133 11 210 150 10
44837-216 158 10 210 150 10 102 78 10 2 2 6
44838- 6 6 6 54 54 54 14 14 14 2 2 6
44839- 2 2 6 62 62 62 74 74 74 30 30 30
44840- 10 10 10 0 0 0 0 0 0 0 0 0
44841- 0 0 0 0 0 0 0 0 0 0 0 0
44842- 0 0 0 0 0 0 0 0 0 0 0 0
44843- 0 0 0 0 0 0 0 0 0 0 0 0
44844- 0 0 0 0 0 0 0 0 0 0 0 0
44845- 0 0 0 0 0 0 0 0 0 0 0 0
44846- 0 0 0 0 0 0 0 0 0 0 0 0
44847- 0 0 0 0 0 0 0 0 0 0 0 0
44848- 0 0 0 0 0 0 0 0 0 0 0 0
44849- 0 0 0 0 0 0 0 0 0 0 0 0
44850- 0 0 0 0 0 0 0 0 0 0 0 0
44851- 0 0 0 0 0 0 0 0 0 0 0 0
44852- 0 0 0 0 0 0 0 0 0 10 10 10
44853- 34 34 34 78 78 78 50 50 50 6 6 6
44854- 94 70 30 139 102 15 190 146 13 226 184 13
44855-232 200 30 232 195 16 215 174 15 190 146 13
44856-168 122 10 192 133 9 210 150 10 213 154 11
44857-202 150 34 182 157 106 101 98 89 2 2 6
44858- 2 2 6 78 78 78 116 116 116 58 58 58
44859- 2 2 6 22 22 22 90 90 90 46 46 46
44860- 18 18 18 6 6 6 0 0 0 0 0 0
44861- 0 0 0 0 0 0 0 0 0 0 0 0
44862- 0 0 0 0 0 0 0 0 0 0 0 0
44863- 0 0 0 0 0 0 0 0 0 0 0 0
44864- 0 0 0 0 0 0 0 0 0 0 0 0
44865- 0 0 0 0 0 0 0 0 0 0 0 0
44866- 0 0 0 0 0 0 0 0 0 0 0 0
44867- 0 0 0 0 0 0 0 0 0 0 0 0
44868- 0 0 0 0 0 0 0 0 0 0 0 0
44869- 0 0 0 0 0 0 0 0 0 0 0 0
44870- 0 0 0 0 0 0 0 0 0 0 0 0
44871- 0 0 0 0 0 0 0 0 0 0 0 0
44872- 0 0 0 0 0 0 0 0 0 10 10 10
44873- 38 38 38 86 86 86 50 50 50 6 6 6
44874-128 128 128 174 154 114 156 107 11 168 122 10
44875-198 155 10 184 144 12 197 138 11 200 144 11
44876-206 145 10 206 145 10 197 138 11 188 164 115
44877-195 195 195 198 198 198 174 174 174 14 14 14
44878- 2 2 6 22 22 22 116 116 116 116 116 116
44879- 22 22 22 2 2 6 74 74 74 70 70 70
44880- 30 30 30 10 10 10 0 0 0 0 0 0
44881- 0 0 0 0 0 0 0 0 0 0 0 0
44882- 0 0 0 0 0 0 0 0 0 0 0 0
44883- 0 0 0 0 0 0 0 0 0 0 0 0
44884- 0 0 0 0 0 0 0 0 0 0 0 0
44885- 0 0 0 0 0 0 0 0 0 0 0 0
44886- 0 0 0 0 0 0 0 0 0 0 0 0
44887- 0 0 0 0 0 0 0 0 0 0 0 0
44888- 0 0 0 0 0 0 0 0 0 0 0 0
44889- 0 0 0 0 0 0 0 0 0 0 0 0
44890- 0 0 0 0 0 0 0 0 0 0 0 0
44891- 0 0 0 0 0 0 0 0 0 0 0 0
44892- 0 0 0 0 0 0 6 6 6 18 18 18
44893- 50 50 50 101 101 101 26 26 26 10 10 10
44894-138 138 138 190 190 190 174 154 114 156 107 11
44895-197 138 11 200 144 11 197 138 11 192 133 9
44896-180 123 7 190 142 34 190 178 144 187 187 187
44897-202 202 202 221 221 221 214 214 214 66 66 66
44898- 2 2 6 2 2 6 50 50 50 62 62 62
44899- 6 6 6 2 2 6 10 10 10 90 90 90
44900- 50 50 50 18 18 18 6 6 6 0 0 0
44901- 0 0 0 0 0 0 0 0 0 0 0 0
44902- 0 0 0 0 0 0 0 0 0 0 0 0
44903- 0 0 0 0 0 0 0 0 0 0 0 0
44904- 0 0 0 0 0 0 0 0 0 0 0 0
44905- 0 0 0 0 0 0 0 0 0 0 0 0
44906- 0 0 0 0 0 0 0 0 0 0 0 0
44907- 0 0 0 0 0 0 0 0 0 0 0 0
44908- 0 0 0 0 0 0 0 0 0 0 0 0
44909- 0 0 0 0 0 0 0 0 0 0 0 0
44910- 0 0 0 0 0 0 0 0 0 0 0 0
44911- 0 0 0 0 0 0 0 0 0 0 0 0
44912- 0 0 0 0 0 0 10 10 10 34 34 34
44913- 74 74 74 74 74 74 2 2 6 6 6 6
44914-144 144 144 198 198 198 190 190 190 178 166 146
44915-154 121 60 156 107 11 156 107 11 168 124 44
44916-174 154 114 187 187 187 190 190 190 210 210 210
44917-246 246 246 253 253 253 253 253 253 182 182 182
44918- 6 6 6 2 2 6 2 2 6 2 2 6
44919- 2 2 6 2 2 6 2 2 6 62 62 62
44920- 74 74 74 34 34 34 14 14 14 0 0 0
44921- 0 0 0 0 0 0 0 0 0 0 0 0
44922- 0 0 0 0 0 0 0 0 0 0 0 0
44923- 0 0 0 0 0 0 0 0 0 0 0 0
44924- 0 0 0 0 0 0 0 0 0 0 0 0
44925- 0 0 0 0 0 0 0 0 0 0 0 0
44926- 0 0 0 0 0 0 0 0 0 0 0 0
44927- 0 0 0 0 0 0 0 0 0 0 0 0
44928- 0 0 0 0 0 0 0 0 0 0 0 0
44929- 0 0 0 0 0 0 0 0 0 0 0 0
44930- 0 0 0 0 0 0 0 0 0 0 0 0
44931- 0 0 0 0 0 0 0 0 0 0 0 0
44932- 0 0 0 10 10 10 22 22 22 54 54 54
44933- 94 94 94 18 18 18 2 2 6 46 46 46
44934-234 234 234 221 221 221 190 190 190 190 190 190
44935-190 190 190 187 187 187 187 187 187 190 190 190
44936-190 190 190 195 195 195 214 214 214 242 242 242
44937-253 253 253 253 253 253 253 253 253 253 253 253
44938- 82 82 82 2 2 6 2 2 6 2 2 6
44939- 2 2 6 2 2 6 2 2 6 14 14 14
44940- 86 86 86 54 54 54 22 22 22 6 6 6
44941- 0 0 0 0 0 0 0 0 0 0 0 0
44942- 0 0 0 0 0 0 0 0 0 0 0 0
44943- 0 0 0 0 0 0 0 0 0 0 0 0
44944- 0 0 0 0 0 0 0 0 0 0 0 0
44945- 0 0 0 0 0 0 0 0 0 0 0 0
44946- 0 0 0 0 0 0 0 0 0 0 0 0
44947- 0 0 0 0 0 0 0 0 0 0 0 0
44948- 0 0 0 0 0 0 0 0 0 0 0 0
44949- 0 0 0 0 0 0 0 0 0 0 0 0
44950- 0 0 0 0 0 0 0 0 0 0 0 0
44951- 0 0 0 0 0 0 0 0 0 0 0 0
44952- 6 6 6 18 18 18 46 46 46 90 90 90
44953- 46 46 46 18 18 18 6 6 6 182 182 182
44954-253 253 253 246 246 246 206 206 206 190 190 190
44955-190 190 190 190 190 190 190 190 190 190 190 190
44956-206 206 206 231 231 231 250 250 250 253 253 253
44957-253 253 253 253 253 253 253 253 253 253 253 253
44958-202 202 202 14 14 14 2 2 6 2 2 6
44959- 2 2 6 2 2 6 2 2 6 2 2 6
44960- 42 42 42 86 86 86 42 42 42 18 18 18
44961- 6 6 6 0 0 0 0 0 0 0 0 0
44962- 0 0 0 0 0 0 0 0 0 0 0 0
44963- 0 0 0 0 0 0 0 0 0 0 0 0
44964- 0 0 0 0 0 0 0 0 0 0 0 0
44965- 0 0 0 0 0 0 0 0 0 0 0 0
44966- 0 0 0 0 0 0 0 0 0 0 0 0
44967- 0 0 0 0 0 0 0 0 0 0 0 0
44968- 0 0 0 0 0 0 0 0 0 0 0 0
44969- 0 0 0 0 0 0 0 0 0 0 0 0
44970- 0 0 0 0 0 0 0 0 0 0 0 0
44971- 0 0 0 0 0 0 0 0 0 6 6 6
44972- 14 14 14 38 38 38 74 74 74 66 66 66
44973- 2 2 6 6 6 6 90 90 90 250 250 250
44974-253 253 253 253 253 253 238 238 238 198 198 198
44975-190 190 190 190 190 190 195 195 195 221 221 221
44976-246 246 246 253 253 253 253 253 253 253 253 253
44977-253 253 253 253 253 253 253 253 253 253 253 253
44978-253 253 253 82 82 82 2 2 6 2 2 6
44979- 2 2 6 2 2 6 2 2 6 2 2 6
44980- 2 2 6 78 78 78 70 70 70 34 34 34
44981- 14 14 14 6 6 6 0 0 0 0 0 0
44982- 0 0 0 0 0 0 0 0 0 0 0 0
44983- 0 0 0 0 0 0 0 0 0 0 0 0
44984- 0 0 0 0 0 0 0 0 0 0 0 0
44985- 0 0 0 0 0 0 0 0 0 0 0 0
44986- 0 0 0 0 0 0 0 0 0 0 0 0
44987- 0 0 0 0 0 0 0 0 0 0 0 0
44988- 0 0 0 0 0 0 0 0 0 0 0 0
44989- 0 0 0 0 0 0 0 0 0 0 0 0
44990- 0 0 0 0 0 0 0 0 0 0 0 0
44991- 0 0 0 0 0 0 0 0 0 14 14 14
44992- 34 34 34 66 66 66 78 78 78 6 6 6
44993- 2 2 6 18 18 18 218 218 218 253 253 253
44994-253 253 253 253 253 253 253 253 253 246 246 246
44995-226 226 226 231 231 231 246 246 246 253 253 253
44996-253 253 253 253 253 253 253 253 253 253 253 253
44997-253 253 253 253 253 253 253 253 253 253 253 253
44998-253 253 253 178 178 178 2 2 6 2 2 6
44999- 2 2 6 2 2 6 2 2 6 2 2 6
45000- 2 2 6 18 18 18 90 90 90 62 62 62
45001- 30 30 30 10 10 10 0 0 0 0 0 0
45002- 0 0 0 0 0 0 0 0 0 0 0 0
45003- 0 0 0 0 0 0 0 0 0 0 0 0
45004- 0 0 0 0 0 0 0 0 0 0 0 0
45005- 0 0 0 0 0 0 0 0 0 0 0 0
45006- 0 0 0 0 0 0 0 0 0 0 0 0
45007- 0 0 0 0 0 0 0 0 0 0 0 0
45008- 0 0 0 0 0 0 0 0 0 0 0 0
45009- 0 0 0 0 0 0 0 0 0 0 0 0
45010- 0 0 0 0 0 0 0 0 0 0 0 0
45011- 0 0 0 0 0 0 10 10 10 26 26 26
45012- 58 58 58 90 90 90 18 18 18 2 2 6
45013- 2 2 6 110 110 110 253 253 253 253 253 253
45014-253 253 253 253 253 253 253 253 253 253 253 253
45015-250 250 250 253 253 253 253 253 253 253 253 253
45016-253 253 253 253 253 253 253 253 253 253 253 253
45017-253 253 253 253 253 253 253 253 253 253 253 253
45018-253 253 253 231 231 231 18 18 18 2 2 6
45019- 2 2 6 2 2 6 2 2 6 2 2 6
45020- 2 2 6 2 2 6 18 18 18 94 94 94
45021- 54 54 54 26 26 26 10 10 10 0 0 0
45022- 0 0 0 0 0 0 0 0 0 0 0 0
45023- 0 0 0 0 0 0 0 0 0 0 0 0
45024- 0 0 0 0 0 0 0 0 0 0 0 0
45025- 0 0 0 0 0 0 0 0 0 0 0 0
45026- 0 0 0 0 0 0 0 0 0 0 0 0
45027- 0 0 0 0 0 0 0 0 0 0 0 0
45028- 0 0 0 0 0 0 0 0 0 0 0 0
45029- 0 0 0 0 0 0 0 0 0 0 0 0
45030- 0 0 0 0 0 0 0 0 0 0 0 0
45031- 0 0 0 6 6 6 22 22 22 50 50 50
45032- 90 90 90 26 26 26 2 2 6 2 2 6
45033- 14 14 14 195 195 195 250 250 250 253 253 253
45034-253 253 253 253 253 253 253 253 253 253 253 253
45035-253 253 253 253 253 253 253 253 253 253 253 253
45036-253 253 253 253 253 253 253 253 253 253 253 253
45037-253 253 253 253 253 253 253 253 253 253 253 253
45038-250 250 250 242 242 242 54 54 54 2 2 6
45039- 2 2 6 2 2 6 2 2 6 2 2 6
45040- 2 2 6 2 2 6 2 2 6 38 38 38
45041- 86 86 86 50 50 50 22 22 22 6 6 6
45042- 0 0 0 0 0 0 0 0 0 0 0 0
45043- 0 0 0 0 0 0 0 0 0 0 0 0
45044- 0 0 0 0 0 0 0 0 0 0 0 0
45045- 0 0 0 0 0 0 0 0 0 0 0 0
45046- 0 0 0 0 0 0 0 0 0 0 0 0
45047- 0 0 0 0 0 0 0 0 0 0 0 0
45048- 0 0 0 0 0 0 0 0 0 0 0 0
45049- 0 0 0 0 0 0 0 0 0 0 0 0
45050- 0 0 0 0 0 0 0 0 0 0 0 0
45051- 6 6 6 14 14 14 38 38 38 82 82 82
45052- 34 34 34 2 2 6 2 2 6 2 2 6
45053- 42 42 42 195 195 195 246 246 246 253 253 253
45054-253 253 253 253 253 253 253 253 253 250 250 250
45055-242 242 242 242 242 242 250 250 250 253 253 253
45056-253 253 253 253 253 253 253 253 253 253 253 253
45057-253 253 253 250 250 250 246 246 246 238 238 238
45058-226 226 226 231 231 231 101 101 101 6 6 6
45059- 2 2 6 2 2 6 2 2 6 2 2 6
45060- 2 2 6 2 2 6 2 2 6 2 2 6
45061- 38 38 38 82 82 82 42 42 42 14 14 14
45062- 6 6 6 0 0 0 0 0 0 0 0 0
45063- 0 0 0 0 0 0 0 0 0 0 0 0
45064- 0 0 0 0 0 0 0 0 0 0 0 0
45065- 0 0 0 0 0 0 0 0 0 0 0 0
45066- 0 0 0 0 0 0 0 0 0 0 0 0
45067- 0 0 0 0 0 0 0 0 0 0 0 0
45068- 0 0 0 0 0 0 0 0 0 0 0 0
45069- 0 0 0 0 0 0 0 0 0 0 0 0
45070- 0 0 0 0 0 0 0 0 0 0 0 0
45071- 10 10 10 26 26 26 62 62 62 66 66 66
45072- 2 2 6 2 2 6 2 2 6 6 6 6
45073- 70 70 70 170 170 170 206 206 206 234 234 234
45074-246 246 246 250 250 250 250 250 250 238 238 238
45075-226 226 226 231 231 231 238 238 238 250 250 250
45076-250 250 250 250 250 250 246 246 246 231 231 231
45077-214 214 214 206 206 206 202 202 202 202 202 202
45078-198 198 198 202 202 202 182 182 182 18 18 18
45079- 2 2 6 2 2 6 2 2 6 2 2 6
45080- 2 2 6 2 2 6 2 2 6 2 2 6
45081- 2 2 6 62 62 62 66 66 66 30 30 30
45082- 10 10 10 0 0 0 0 0 0 0 0 0
45083- 0 0 0 0 0 0 0 0 0 0 0 0
45084- 0 0 0 0 0 0 0 0 0 0 0 0
45085- 0 0 0 0 0 0 0 0 0 0 0 0
45086- 0 0 0 0 0 0 0 0 0 0 0 0
45087- 0 0 0 0 0 0 0 0 0 0 0 0
45088- 0 0 0 0 0 0 0 0 0 0 0 0
45089- 0 0 0 0 0 0 0 0 0 0 0 0
45090- 0 0 0 0 0 0 0 0 0 0 0 0
45091- 14 14 14 42 42 42 82 82 82 18 18 18
45092- 2 2 6 2 2 6 2 2 6 10 10 10
45093- 94 94 94 182 182 182 218 218 218 242 242 242
45094-250 250 250 253 253 253 253 253 253 250 250 250
45095-234 234 234 253 253 253 253 253 253 253 253 253
45096-253 253 253 253 253 253 253 253 253 246 246 246
45097-238 238 238 226 226 226 210 210 210 202 202 202
45098-195 195 195 195 195 195 210 210 210 158 158 158
45099- 6 6 6 14 14 14 50 50 50 14 14 14
45100- 2 2 6 2 2 6 2 2 6 2 2 6
45101- 2 2 6 6 6 6 86 86 86 46 46 46
45102- 18 18 18 6 6 6 0 0 0 0 0 0
45103- 0 0 0 0 0 0 0 0 0 0 0 0
45104- 0 0 0 0 0 0 0 0 0 0 0 0
45105- 0 0 0 0 0 0 0 0 0 0 0 0
45106- 0 0 0 0 0 0 0 0 0 0 0 0
45107- 0 0 0 0 0 0 0 0 0 0 0 0
45108- 0 0 0 0 0 0 0 0 0 0 0 0
45109- 0 0 0 0 0 0 0 0 0 0 0 0
45110- 0 0 0 0 0 0 0 0 0 6 6 6
45111- 22 22 22 54 54 54 70 70 70 2 2 6
45112- 2 2 6 10 10 10 2 2 6 22 22 22
45113-166 166 166 231 231 231 250 250 250 253 253 253
45114-253 253 253 253 253 253 253 253 253 250 250 250
45115-242 242 242 253 253 253 253 253 253 253 253 253
45116-253 253 253 253 253 253 253 253 253 253 253 253
45117-253 253 253 253 253 253 253 253 253 246 246 246
45118-231 231 231 206 206 206 198 198 198 226 226 226
45119- 94 94 94 2 2 6 6 6 6 38 38 38
45120- 30 30 30 2 2 6 2 2 6 2 2 6
45121- 2 2 6 2 2 6 62 62 62 66 66 66
45122- 26 26 26 10 10 10 0 0 0 0 0 0
45123- 0 0 0 0 0 0 0 0 0 0 0 0
45124- 0 0 0 0 0 0 0 0 0 0 0 0
45125- 0 0 0 0 0 0 0 0 0 0 0 0
45126- 0 0 0 0 0 0 0 0 0 0 0 0
45127- 0 0 0 0 0 0 0 0 0 0 0 0
45128- 0 0 0 0 0 0 0 0 0 0 0 0
45129- 0 0 0 0 0 0 0 0 0 0 0 0
45130- 0 0 0 0 0 0 0 0 0 10 10 10
45131- 30 30 30 74 74 74 50 50 50 2 2 6
45132- 26 26 26 26 26 26 2 2 6 106 106 106
45133-238 238 238 253 253 253 253 253 253 253 253 253
45134-253 253 253 253 253 253 253 253 253 253 253 253
45135-253 253 253 253 253 253 253 253 253 253 253 253
45136-253 253 253 253 253 253 253 253 253 253 253 253
45137-253 253 253 253 253 253 253 253 253 253 253 253
45138-253 253 253 246 246 246 218 218 218 202 202 202
45139-210 210 210 14 14 14 2 2 6 2 2 6
45140- 30 30 30 22 22 22 2 2 6 2 2 6
45141- 2 2 6 2 2 6 18 18 18 86 86 86
45142- 42 42 42 14 14 14 0 0 0 0 0 0
45143- 0 0 0 0 0 0 0 0 0 0 0 0
45144- 0 0 0 0 0 0 0 0 0 0 0 0
45145- 0 0 0 0 0 0 0 0 0 0 0 0
45146- 0 0 0 0 0 0 0 0 0 0 0 0
45147- 0 0 0 0 0 0 0 0 0 0 0 0
45148- 0 0 0 0 0 0 0 0 0 0 0 0
45149- 0 0 0 0 0 0 0 0 0 0 0 0
45150- 0 0 0 0 0 0 0 0 0 14 14 14
45151- 42 42 42 90 90 90 22 22 22 2 2 6
45152- 42 42 42 2 2 6 18 18 18 218 218 218
45153-253 253 253 253 253 253 253 253 253 253 253 253
45154-253 253 253 253 253 253 253 253 253 253 253 253
45155-253 253 253 253 253 253 253 253 253 253 253 253
45156-253 253 253 253 253 253 253 253 253 253 253 253
45157-253 253 253 253 253 253 253 253 253 253 253 253
45158-253 253 253 253 253 253 250 250 250 221 221 221
45159-218 218 218 101 101 101 2 2 6 14 14 14
45160- 18 18 18 38 38 38 10 10 10 2 2 6
45161- 2 2 6 2 2 6 2 2 6 78 78 78
45162- 58 58 58 22 22 22 6 6 6 0 0 0
45163- 0 0 0 0 0 0 0 0 0 0 0 0
45164- 0 0 0 0 0 0 0 0 0 0 0 0
45165- 0 0 0 0 0 0 0 0 0 0 0 0
45166- 0 0 0 0 0 0 0 0 0 0 0 0
45167- 0 0 0 0 0 0 0 0 0 0 0 0
45168- 0 0 0 0 0 0 0 0 0 0 0 0
45169- 0 0 0 0 0 0 0 0 0 0 0 0
45170- 0 0 0 0 0 0 6 6 6 18 18 18
45171- 54 54 54 82 82 82 2 2 6 26 26 26
45172- 22 22 22 2 2 6 123 123 123 253 253 253
45173-253 253 253 253 253 253 253 253 253 253 253 253
45174-253 253 253 253 253 253 253 253 253 253 253 253
45175-253 253 253 253 253 253 253 253 253 253 253 253
45176-253 253 253 253 253 253 253 253 253 253 253 253
45177-253 253 253 253 253 253 253 253 253 253 253 253
45178-253 253 253 253 253 253 253 253 253 250 250 250
45179-238 238 238 198 198 198 6 6 6 38 38 38
45180- 58 58 58 26 26 26 38 38 38 2 2 6
45181- 2 2 6 2 2 6 2 2 6 46 46 46
45182- 78 78 78 30 30 30 10 10 10 0 0 0
45183- 0 0 0 0 0 0 0 0 0 0 0 0
45184- 0 0 0 0 0 0 0 0 0 0 0 0
45185- 0 0 0 0 0 0 0 0 0 0 0 0
45186- 0 0 0 0 0 0 0 0 0 0 0 0
45187- 0 0 0 0 0 0 0 0 0 0 0 0
45188- 0 0 0 0 0 0 0 0 0 0 0 0
45189- 0 0 0 0 0 0 0 0 0 0 0 0
45190- 0 0 0 0 0 0 10 10 10 30 30 30
45191- 74 74 74 58 58 58 2 2 6 42 42 42
45192- 2 2 6 22 22 22 231 231 231 253 253 253
45193-253 253 253 253 253 253 253 253 253 253 253 253
45194-253 253 253 253 253 253 253 253 253 250 250 250
45195-253 253 253 253 253 253 253 253 253 253 253 253
45196-253 253 253 253 253 253 253 253 253 253 253 253
45197-253 253 253 253 253 253 253 253 253 253 253 253
45198-253 253 253 253 253 253 253 253 253 253 253 253
45199-253 253 253 246 246 246 46 46 46 38 38 38
45200- 42 42 42 14 14 14 38 38 38 14 14 14
45201- 2 2 6 2 2 6 2 2 6 6 6 6
45202- 86 86 86 46 46 46 14 14 14 0 0 0
45203- 0 0 0 0 0 0 0 0 0 0 0 0
45204- 0 0 0 0 0 0 0 0 0 0 0 0
45205- 0 0 0 0 0 0 0 0 0 0 0 0
45206- 0 0 0 0 0 0 0 0 0 0 0 0
45207- 0 0 0 0 0 0 0 0 0 0 0 0
45208- 0 0 0 0 0 0 0 0 0 0 0 0
45209- 0 0 0 0 0 0 0 0 0 0 0 0
45210- 0 0 0 6 6 6 14 14 14 42 42 42
45211- 90 90 90 18 18 18 18 18 18 26 26 26
45212- 2 2 6 116 116 116 253 253 253 253 253 253
45213-253 253 253 253 253 253 253 253 253 253 253 253
45214-253 253 253 253 253 253 250 250 250 238 238 238
45215-253 253 253 253 253 253 253 253 253 253 253 253
45216-253 253 253 253 253 253 253 253 253 253 253 253
45217-253 253 253 253 253 253 253 253 253 253 253 253
45218-253 253 253 253 253 253 253 253 253 253 253 253
45219-253 253 253 253 253 253 94 94 94 6 6 6
45220- 2 2 6 2 2 6 10 10 10 34 34 34
45221- 2 2 6 2 2 6 2 2 6 2 2 6
45222- 74 74 74 58 58 58 22 22 22 6 6 6
45223- 0 0 0 0 0 0 0 0 0 0 0 0
45224- 0 0 0 0 0 0 0 0 0 0 0 0
45225- 0 0 0 0 0 0 0 0 0 0 0 0
45226- 0 0 0 0 0 0 0 0 0 0 0 0
45227- 0 0 0 0 0 0 0 0 0 0 0 0
45228- 0 0 0 0 0 0 0 0 0 0 0 0
45229- 0 0 0 0 0 0 0 0 0 0 0 0
45230- 0 0 0 10 10 10 26 26 26 66 66 66
45231- 82 82 82 2 2 6 38 38 38 6 6 6
45232- 14 14 14 210 210 210 253 253 253 253 253 253
45233-253 253 253 253 253 253 253 253 253 253 253 253
45234-253 253 253 253 253 253 246 246 246 242 242 242
45235-253 253 253 253 253 253 253 253 253 253 253 253
45236-253 253 253 253 253 253 253 253 253 253 253 253
45237-253 253 253 253 253 253 253 253 253 253 253 253
45238-253 253 253 253 253 253 253 253 253 253 253 253
45239-253 253 253 253 253 253 144 144 144 2 2 6
45240- 2 2 6 2 2 6 2 2 6 46 46 46
45241- 2 2 6 2 2 6 2 2 6 2 2 6
45242- 42 42 42 74 74 74 30 30 30 10 10 10
45243- 0 0 0 0 0 0 0 0 0 0 0 0
45244- 0 0 0 0 0 0 0 0 0 0 0 0
45245- 0 0 0 0 0 0 0 0 0 0 0 0
45246- 0 0 0 0 0 0 0 0 0 0 0 0
45247- 0 0 0 0 0 0 0 0 0 0 0 0
45248- 0 0 0 0 0 0 0 0 0 0 0 0
45249- 0 0 0 0 0 0 0 0 0 0 0 0
45250- 6 6 6 14 14 14 42 42 42 90 90 90
45251- 26 26 26 6 6 6 42 42 42 2 2 6
45252- 74 74 74 250 250 250 253 253 253 253 253 253
45253-253 253 253 253 253 253 253 253 253 253 253 253
45254-253 253 253 253 253 253 242 242 242 242 242 242
45255-253 253 253 253 253 253 253 253 253 253 253 253
45256-253 253 253 253 253 253 253 253 253 253 253 253
45257-253 253 253 253 253 253 253 253 253 253 253 253
45258-253 253 253 253 253 253 253 253 253 253 253 253
45259-253 253 253 253 253 253 182 182 182 2 2 6
45260- 2 2 6 2 2 6 2 2 6 46 46 46
45261- 2 2 6 2 2 6 2 2 6 2 2 6
45262- 10 10 10 86 86 86 38 38 38 10 10 10
45263- 0 0 0 0 0 0 0 0 0 0 0 0
45264- 0 0 0 0 0 0 0 0 0 0 0 0
45265- 0 0 0 0 0 0 0 0 0 0 0 0
45266- 0 0 0 0 0 0 0 0 0 0 0 0
45267- 0 0 0 0 0 0 0 0 0 0 0 0
45268- 0 0 0 0 0 0 0 0 0 0 0 0
45269- 0 0 0 0 0 0 0 0 0 0 0 0
45270- 10 10 10 26 26 26 66 66 66 82 82 82
45271- 2 2 6 22 22 22 18 18 18 2 2 6
45272-149 149 149 253 253 253 253 253 253 253 253 253
45273-253 253 253 253 253 253 253 253 253 253 253 253
45274-253 253 253 253 253 253 234 234 234 242 242 242
45275-253 253 253 253 253 253 253 253 253 253 253 253
45276-253 253 253 253 253 253 253 253 253 253 253 253
45277-253 253 253 253 253 253 253 253 253 253 253 253
45278-253 253 253 253 253 253 253 253 253 253 253 253
45279-253 253 253 253 253 253 206 206 206 2 2 6
45280- 2 2 6 2 2 6 2 2 6 38 38 38
45281- 2 2 6 2 2 6 2 2 6 2 2 6
45282- 6 6 6 86 86 86 46 46 46 14 14 14
45283- 0 0 0 0 0 0 0 0 0 0 0 0
45284- 0 0 0 0 0 0 0 0 0 0 0 0
45285- 0 0 0 0 0 0 0 0 0 0 0 0
45286- 0 0 0 0 0 0 0 0 0 0 0 0
45287- 0 0 0 0 0 0 0 0 0 0 0 0
45288- 0 0 0 0 0 0 0 0 0 0 0 0
45289- 0 0 0 0 0 0 0 0 0 6 6 6
45290- 18 18 18 46 46 46 86 86 86 18 18 18
45291- 2 2 6 34 34 34 10 10 10 6 6 6
45292-210 210 210 253 253 253 253 253 253 253 253 253
45293-253 253 253 253 253 253 253 253 253 253 253 253
45294-253 253 253 253 253 253 234 234 234 242 242 242
45295-253 253 253 253 253 253 253 253 253 253 253 253
45296-253 253 253 253 253 253 253 253 253 253 253 253
45297-253 253 253 253 253 253 253 253 253 253 253 253
45298-253 253 253 253 253 253 253 253 253 253 253 253
45299-253 253 253 253 253 253 221 221 221 6 6 6
45300- 2 2 6 2 2 6 6 6 6 30 30 30
45301- 2 2 6 2 2 6 2 2 6 2 2 6
45302- 2 2 6 82 82 82 54 54 54 18 18 18
45303- 6 6 6 0 0 0 0 0 0 0 0 0
45304- 0 0 0 0 0 0 0 0 0 0 0 0
45305- 0 0 0 0 0 0 0 0 0 0 0 0
45306- 0 0 0 0 0 0 0 0 0 0 0 0
45307- 0 0 0 0 0 0 0 0 0 0 0 0
45308- 0 0 0 0 0 0 0 0 0 0 0 0
45309- 0 0 0 0 0 0 0 0 0 10 10 10
45310- 26 26 26 66 66 66 62 62 62 2 2 6
45311- 2 2 6 38 38 38 10 10 10 26 26 26
45312-238 238 238 253 253 253 253 253 253 253 253 253
45313-253 253 253 253 253 253 253 253 253 253 253 253
45314-253 253 253 253 253 253 231 231 231 238 238 238
45315-253 253 253 253 253 253 253 253 253 253 253 253
45316-253 253 253 253 253 253 253 253 253 253 253 253
45317-253 253 253 253 253 253 253 253 253 253 253 253
45318-253 253 253 253 253 253 253 253 253 253 253 253
45319-253 253 253 253 253 253 231 231 231 6 6 6
45320- 2 2 6 2 2 6 10 10 10 30 30 30
45321- 2 2 6 2 2 6 2 2 6 2 2 6
45322- 2 2 6 66 66 66 58 58 58 22 22 22
45323- 6 6 6 0 0 0 0 0 0 0 0 0
45324- 0 0 0 0 0 0 0 0 0 0 0 0
45325- 0 0 0 0 0 0 0 0 0 0 0 0
45326- 0 0 0 0 0 0 0 0 0 0 0 0
45327- 0 0 0 0 0 0 0 0 0 0 0 0
45328- 0 0 0 0 0 0 0 0 0 0 0 0
45329- 0 0 0 0 0 0 0 0 0 10 10 10
45330- 38 38 38 78 78 78 6 6 6 2 2 6
45331- 2 2 6 46 46 46 14 14 14 42 42 42
45332-246 246 246 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 231 231 231 242 242 242
45335-253 253 253 253 253 253 253 253 253 253 253 253
45336-253 253 253 253 253 253 253 253 253 253 253 253
45337-253 253 253 253 253 253 253 253 253 253 253 253
45338-253 253 253 253 253 253 253 253 253 253 253 253
45339-253 253 253 253 253 253 234 234 234 10 10 10
45340- 2 2 6 2 2 6 22 22 22 14 14 14
45341- 2 2 6 2 2 6 2 2 6 2 2 6
45342- 2 2 6 66 66 66 62 62 62 22 22 22
45343- 6 6 6 0 0 0 0 0 0 0 0 0
45344- 0 0 0 0 0 0 0 0 0 0 0 0
45345- 0 0 0 0 0 0 0 0 0 0 0 0
45346- 0 0 0 0 0 0 0 0 0 0 0 0
45347- 0 0 0 0 0 0 0 0 0 0 0 0
45348- 0 0 0 0 0 0 0 0 0 0 0 0
45349- 0 0 0 0 0 0 6 6 6 18 18 18
45350- 50 50 50 74 74 74 2 2 6 2 2 6
45351- 14 14 14 70 70 70 34 34 34 62 62 62
45352-250 250 250 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 231 231 231 246 246 246
45355-253 253 253 253 253 253 253 253 253 253 253 253
45356-253 253 253 253 253 253 253 253 253 253 253 253
45357-253 253 253 253 253 253 253 253 253 253 253 253
45358-253 253 253 253 253 253 253 253 253 253 253 253
45359-253 253 253 253 253 253 234 234 234 14 14 14
45360- 2 2 6 2 2 6 30 30 30 2 2 6
45361- 2 2 6 2 2 6 2 2 6 2 2 6
45362- 2 2 6 66 66 66 62 62 62 22 22 22
45363- 6 6 6 0 0 0 0 0 0 0 0 0
45364- 0 0 0 0 0 0 0 0 0 0 0 0
45365- 0 0 0 0 0 0 0 0 0 0 0 0
45366- 0 0 0 0 0 0 0 0 0 0 0 0
45367- 0 0 0 0 0 0 0 0 0 0 0 0
45368- 0 0 0 0 0 0 0 0 0 0 0 0
45369- 0 0 0 0 0 0 6 6 6 18 18 18
45370- 54 54 54 62 62 62 2 2 6 2 2 6
45371- 2 2 6 30 30 30 46 46 46 70 70 70
45372-250 250 250 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 231 231 231 246 246 246
45375-253 253 253 253 253 253 253 253 253 253 253 253
45376-253 253 253 253 253 253 253 253 253 253 253 253
45377-253 253 253 253 253 253 253 253 253 253 253 253
45378-253 253 253 253 253 253 253 253 253 253 253 253
45379-253 253 253 253 253 253 226 226 226 10 10 10
45380- 2 2 6 6 6 6 30 30 30 2 2 6
45381- 2 2 6 2 2 6 2 2 6 2 2 6
45382- 2 2 6 66 66 66 58 58 58 22 22 22
45383- 6 6 6 0 0 0 0 0 0 0 0 0
45384- 0 0 0 0 0 0 0 0 0 0 0 0
45385- 0 0 0 0 0 0 0 0 0 0 0 0
45386- 0 0 0 0 0 0 0 0 0 0 0 0
45387- 0 0 0 0 0 0 0 0 0 0 0 0
45388- 0 0 0 0 0 0 0 0 0 0 0 0
45389- 0 0 0 0 0 0 6 6 6 22 22 22
45390- 58 58 58 62 62 62 2 2 6 2 2 6
45391- 2 2 6 2 2 6 30 30 30 78 78 78
45392-250 250 250 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 231 231 231 246 246 246
45395-253 253 253 253 253 253 253 253 253 253 253 253
45396-253 253 253 253 253 253 253 253 253 253 253 253
45397-253 253 253 253 253 253 253 253 253 253 253 253
45398-253 253 253 253 253 253 253 253 253 253 253 253
45399-253 253 253 253 253 253 206 206 206 2 2 6
45400- 22 22 22 34 34 34 18 14 6 22 22 22
45401- 26 26 26 18 18 18 6 6 6 2 2 6
45402- 2 2 6 82 82 82 54 54 54 18 18 18
45403- 6 6 6 0 0 0 0 0 0 0 0 0
45404- 0 0 0 0 0 0 0 0 0 0 0 0
45405- 0 0 0 0 0 0 0 0 0 0 0 0
45406- 0 0 0 0 0 0 0 0 0 0 0 0
45407- 0 0 0 0 0 0 0 0 0 0 0 0
45408- 0 0 0 0 0 0 0 0 0 0 0 0
45409- 0 0 0 0 0 0 6 6 6 26 26 26
45410- 62 62 62 106 106 106 74 54 14 185 133 11
45411-210 162 10 121 92 8 6 6 6 62 62 62
45412-238 238 238 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 231 231 231 246 246 246
45415-253 253 253 253 253 253 253 253 253 253 253 253
45416-253 253 253 253 253 253 253 253 253 253 253 253
45417-253 253 253 253 253 253 253 253 253 253 253 253
45418-253 253 253 253 253 253 253 253 253 253 253 253
45419-253 253 253 253 253 253 158 158 158 18 18 18
45420- 14 14 14 2 2 6 2 2 6 2 2 6
45421- 6 6 6 18 18 18 66 66 66 38 38 38
45422- 6 6 6 94 94 94 50 50 50 18 18 18
45423- 6 6 6 0 0 0 0 0 0 0 0 0
45424- 0 0 0 0 0 0 0 0 0 0 0 0
45425- 0 0 0 0 0 0 0 0 0 0 0 0
45426- 0 0 0 0 0 0 0 0 0 0 0 0
45427- 0 0 0 0 0 0 0 0 0 0 0 0
45428- 0 0 0 0 0 0 0 0 0 6 6 6
45429- 10 10 10 10 10 10 18 18 18 38 38 38
45430- 78 78 78 142 134 106 216 158 10 242 186 14
45431-246 190 14 246 190 14 156 118 10 10 10 10
45432- 90 90 90 238 238 238 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 250 250 250
45435-253 253 253 253 253 253 253 253 253 253 253 253
45436-253 253 253 253 253 253 253 253 253 253 253 253
45437-253 253 253 253 253 253 253 253 253 253 253 253
45438-253 253 253 253 253 253 253 253 253 246 230 190
45439-238 204 91 238 204 91 181 142 44 37 26 9
45440- 2 2 6 2 2 6 2 2 6 2 2 6
45441- 2 2 6 2 2 6 38 38 38 46 46 46
45442- 26 26 26 106 106 106 54 54 54 18 18 18
45443- 6 6 6 0 0 0 0 0 0 0 0 0
45444- 0 0 0 0 0 0 0 0 0 0 0 0
45445- 0 0 0 0 0 0 0 0 0 0 0 0
45446- 0 0 0 0 0 0 0 0 0 0 0 0
45447- 0 0 0 0 0 0 0 0 0 0 0 0
45448- 0 0 0 6 6 6 14 14 14 22 22 22
45449- 30 30 30 38 38 38 50 50 50 70 70 70
45450-106 106 106 190 142 34 226 170 11 242 186 14
45451-246 190 14 246 190 14 246 190 14 154 114 10
45452- 6 6 6 74 74 74 226 226 226 253 253 253
45453-253 253 253 253 253 253 253 253 253 253 253 253
45454-253 253 253 253 253 253 231 231 231 250 250 250
45455-253 253 253 253 253 253 253 253 253 253 253 253
45456-253 253 253 253 253 253 253 253 253 253 253 253
45457-253 253 253 253 253 253 253 253 253 253 253 253
45458-253 253 253 253 253 253 253 253 253 228 184 62
45459-241 196 14 241 208 19 232 195 16 38 30 10
45460- 2 2 6 2 2 6 2 2 6 2 2 6
45461- 2 2 6 6 6 6 30 30 30 26 26 26
45462-203 166 17 154 142 90 66 66 66 26 26 26
45463- 6 6 6 0 0 0 0 0 0 0 0 0
45464- 0 0 0 0 0 0 0 0 0 0 0 0
45465- 0 0 0 0 0 0 0 0 0 0 0 0
45466- 0 0 0 0 0 0 0 0 0 0 0 0
45467- 0 0 0 0 0 0 0 0 0 0 0 0
45468- 6 6 6 18 18 18 38 38 38 58 58 58
45469- 78 78 78 86 86 86 101 101 101 123 123 123
45470-175 146 61 210 150 10 234 174 13 246 186 14
45471-246 190 14 246 190 14 246 190 14 238 190 10
45472-102 78 10 2 2 6 46 46 46 198 198 198
45473-253 253 253 253 253 253 253 253 253 253 253 253
45474-253 253 253 253 253 253 234 234 234 242 242 242
45475-253 253 253 253 253 253 253 253 253 253 253 253
45476-253 253 253 253 253 253 253 253 253 253 253 253
45477-253 253 253 253 253 253 253 253 253 253 253 253
45478-253 253 253 253 253 253 253 253 253 224 178 62
45479-242 186 14 241 196 14 210 166 10 22 18 6
45480- 2 2 6 2 2 6 2 2 6 2 2 6
45481- 2 2 6 2 2 6 6 6 6 121 92 8
45482-238 202 15 232 195 16 82 82 82 34 34 34
45483- 10 10 10 0 0 0 0 0 0 0 0 0
45484- 0 0 0 0 0 0 0 0 0 0 0 0
45485- 0 0 0 0 0 0 0 0 0 0 0 0
45486- 0 0 0 0 0 0 0 0 0 0 0 0
45487- 0 0 0 0 0 0 0 0 0 0 0 0
45488- 14 14 14 38 38 38 70 70 70 154 122 46
45489-190 142 34 200 144 11 197 138 11 197 138 11
45490-213 154 11 226 170 11 242 186 14 246 190 14
45491-246 190 14 246 190 14 246 190 14 246 190 14
45492-225 175 15 46 32 6 2 2 6 22 22 22
45493-158 158 158 250 250 250 253 253 253 253 253 253
45494-253 253 253 253 253 253 253 253 253 253 253 253
45495-253 253 253 253 253 253 253 253 253 253 253 253
45496-253 253 253 253 253 253 253 253 253 253 253 253
45497-253 253 253 253 253 253 253 253 253 253 253 253
45498-253 253 253 250 250 250 242 242 242 224 178 62
45499-239 182 13 236 186 11 213 154 11 46 32 6
45500- 2 2 6 2 2 6 2 2 6 2 2 6
45501- 2 2 6 2 2 6 61 42 6 225 175 15
45502-238 190 10 236 186 11 112 100 78 42 42 42
45503- 14 14 14 0 0 0 0 0 0 0 0 0
45504- 0 0 0 0 0 0 0 0 0 0 0 0
45505- 0 0 0 0 0 0 0 0 0 0 0 0
45506- 0 0 0 0 0 0 0 0 0 0 0 0
45507- 0 0 0 0 0 0 0 0 0 6 6 6
45508- 22 22 22 54 54 54 154 122 46 213 154 11
45509-226 170 11 230 174 11 226 170 11 226 170 11
45510-236 178 12 242 186 14 246 190 14 246 190 14
45511-246 190 14 246 190 14 246 190 14 246 190 14
45512-241 196 14 184 144 12 10 10 10 2 2 6
45513- 6 6 6 116 116 116 242 242 242 253 253 253
45514-253 253 253 253 253 253 253 253 253 253 253 253
45515-253 253 253 253 253 253 253 253 253 253 253 253
45516-253 253 253 253 253 253 253 253 253 253 253 253
45517-253 253 253 253 253 253 253 253 253 253 253 253
45518-253 253 253 231 231 231 198 198 198 214 170 54
45519-236 178 12 236 178 12 210 150 10 137 92 6
45520- 18 14 6 2 2 6 2 2 6 2 2 6
45521- 6 6 6 70 47 6 200 144 11 236 178 12
45522-239 182 13 239 182 13 124 112 88 58 58 58
45523- 22 22 22 6 6 6 0 0 0 0 0 0
45524- 0 0 0 0 0 0 0 0 0 0 0 0
45525- 0 0 0 0 0 0 0 0 0 0 0 0
45526- 0 0 0 0 0 0 0 0 0 0 0 0
45527- 0 0 0 0 0 0 0 0 0 10 10 10
45528- 30 30 30 70 70 70 180 133 36 226 170 11
45529-239 182 13 242 186 14 242 186 14 246 186 14
45530-246 190 14 246 190 14 246 190 14 246 190 14
45531-246 190 14 246 190 14 246 190 14 246 190 14
45532-246 190 14 232 195 16 98 70 6 2 2 6
45533- 2 2 6 2 2 6 66 66 66 221 221 221
45534-253 253 253 253 253 253 253 253 253 253 253 253
45535-253 253 253 253 253 253 253 253 253 253 253 253
45536-253 253 253 253 253 253 253 253 253 253 253 253
45537-253 253 253 253 253 253 253 253 253 253 253 253
45538-253 253 253 206 206 206 198 198 198 214 166 58
45539-230 174 11 230 174 11 216 158 10 192 133 9
45540-163 110 8 116 81 8 102 78 10 116 81 8
45541-167 114 7 197 138 11 226 170 11 239 182 13
45542-242 186 14 242 186 14 162 146 94 78 78 78
45543- 34 34 34 14 14 14 6 6 6 0 0 0
45544- 0 0 0 0 0 0 0 0 0 0 0 0
45545- 0 0 0 0 0 0 0 0 0 0 0 0
45546- 0 0 0 0 0 0 0 0 0 0 0 0
45547- 0 0 0 0 0 0 0 0 0 6 6 6
45548- 30 30 30 78 78 78 190 142 34 226 170 11
45549-239 182 13 246 190 14 246 190 14 246 190 14
45550-246 190 14 246 190 14 246 190 14 246 190 14
45551-246 190 14 246 190 14 246 190 14 246 190 14
45552-246 190 14 241 196 14 203 166 17 22 18 6
45553- 2 2 6 2 2 6 2 2 6 38 38 38
45554-218 218 218 253 253 253 253 253 253 253 253 253
45555-253 253 253 253 253 253 253 253 253 253 253 253
45556-253 253 253 253 253 253 253 253 253 253 253 253
45557-253 253 253 253 253 253 253 253 253 253 253 253
45558-250 250 250 206 206 206 198 198 198 202 162 69
45559-226 170 11 236 178 12 224 166 10 210 150 10
45560-200 144 11 197 138 11 192 133 9 197 138 11
45561-210 150 10 226 170 11 242 186 14 246 190 14
45562-246 190 14 246 186 14 225 175 15 124 112 88
45563- 62 62 62 30 30 30 14 14 14 6 6 6
45564- 0 0 0 0 0 0 0 0 0 0 0 0
45565- 0 0 0 0 0 0 0 0 0 0 0 0
45566- 0 0 0 0 0 0 0 0 0 0 0 0
45567- 0 0 0 0 0 0 0 0 0 10 10 10
45568- 30 30 30 78 78 78 174 135 50 224 166 10
45569-239 182 13 246 190 14 246 190 14 246 190 14
45570-246 190 14 246 190 14 246 190 14 246 190 14
45571-246 190 14 246 190 14 246 190 14 246 190 14
45572-246 190 14 246 190 14 241 196 14 139 102 15
45573- 2 2 6 2 2 6 2 2 6 2 2 6
45574- 78 78 78 250 250 250 253 253 253 253 253 253
45575-253 253 253 253 253 253 253 253 253 253 253 253
45576-253 253 253 253 253 253 253 253 253 253 253 253
45577-253 253 253 253 253 253 253 253 253 253 253 253
45578-250 250 250 214 214 214 198 198 198 190 150 46
45579-219 162 10 236 178 12 234 174 13 224 166 10
45580-216 158 10 213 154 11 213 154 11 216 158 10
45581-226 170 11 239 182 13 246 190 14 246 190 14
45582-246 190 14 246 190 14 242 186 14 206 162 42
45583-101 101 101 58 58 58 30 30 30 14 14 14
45584- 6 6 6 0 0 0 0 0 0 0 0 0
45585- 0 0 0 0 0 0 0 0 0 0 0 0
45586- 0 0 0 0 0 0 0 0 0 0 0 0
45587- 0 0 0 0 0 0 0 0 0 10 10 10
45588- 30 30 30 74 74 74 174 135 50 216 158 10
45589-236 178 12 246 190 14 246 190 14 246 190 14
45590-246 190 14 246 190 14 246 190 14 246 190 14
45591-246 190 14 246 190 14 246 190 14 246 190 14
45592-246 190 14 246 190 14 241 196 14 226 184 13
45593- 61 42 6 2 2 6 2 2 6 2 2 6
45594- 22 22 22 238 238 238 253 253 253 253 253 253
45595-253 253 253 253 253 253 253 253 253 253 253 253
45596-253 253 253 253 253 253 253 253 253 253 253 253
45597-253 253 253 253 253 253 253 253 253 253 253 253
45598-253 253 253 226 226 226 187 187 187 180 133 36
45599-216 158 10 236 178 12 239 182 13 236 178 12
45600-230 174 11 226 170 11 226 170 11 230 174 11
45601-236 178 12 242 186 14 246 190 14 246 190 14
45602-246 190 14 246 190 14 246 186 14 239 182 13
45603-206 162 42 106 106 106 66 66 66 34 34 34
45604- 14 14 14 6 6 6 0 0 0 0 0 0
45605- 0 0 0 0 0 0 0 0 0 0 0 0
45606- 0 0 0 0 0 0 0 0 0 0 0 0
45607- 0 0 0 0 0 0 0 0 0 6 6 6
45608- 26 26 26 70 70 70 163 133 67 213 154 11
45609-236 178 12 246 190 14 246 190 14 246 190 14
45610-246 190 14 246 190 14 246 190 14 246 190 14
45611-246 190 14 246 190 14 246 190 14 246 190 14
45612-246 190 14 246 190 14 246 190 14 241 196 14
45613-190 146 13 18 14 6 2 2 6 2 2 6
45614- 46 46 46 246 246 246 253 253 253 253 253 253
45615-253 253 253 253 253 253 253 253 253 253 253 253
45616-253 253 253 253 253 253 253 253 253 253 253 253
45617-253 253 253 253 253 253 253 253 253 253 253 253
45618-253 253 253 221 221 221 86 86 86 156 107 11
45619-216 158 10 236 178 12 242 186 14 246 186 14
45620-242 186 14 239 182 13 239 182 13 242 186 14
45621-242 186 14 246 186 14 246 190 14 246 190 14
45622-246 190 14 246 190 14 246 190 14 246 190 14
45623-242 186 14 225 175 15 142 122 72 66 66 66
45624- 30 30 30 10 10 10 0 0 0 0 0 0
45625- 0 0 0 0 0 0 0 0 0 0 0 0
45626- 0 0 0 0 0 0 0 0 0 0 0 0
45627- 0 0 0 0 0 0 0 0 0 6 6 6
45628- 26 26 26 70 70 70 163 133 67 210 150 10
45629-236 178 12 246 190 14 246 190 14 246 190 14
45630-246 190 14 246 190 14 246 190 14 246 190 14
45631-246 190 14 246 190 14 246 190 14 246 190 14
45632-246 190 14 246 190 14 246 190 14 246 190 14
45633-232 195 16 121 92 8 34 34 34 106 106 106
45634-221 221 221 253 253 253 253 253 253 253 253 253
45635-253 253 253 253 253 253 253 253 253 253 253 253
45636-253 253 253 253 253 253 253 253 253 253 253 253
45637-253 253 253 253 253 253 253 253 253 253 253 253
45638-242 242 242 82 82 82 18 14 6 163 110 8
45639-216 158 10 236 178 12 242 186 14 246 190 14
45640-246 190 14 246 190 14 246 190 14 246 190 14
45641-246 190 14 246 190 14 246 190 14 246 190 14
45642-246 190 14 246 190 14 246 190 14 246 190 14
45643-246 190 14 246 190 14 242 186 14 163 133 67
45644- 46 46 46 18 18 18 6 6 6 0 0 0
45645- 0 0 0 0 0 0 0 0 0 0 0 0
45646- 0 0 0 0 0 0 0 0 0 0 0 0
45647- 0 0 0 0 0 0 0 0 0 10 10 10
45648- 30 30 30 78 78 78 163 133 67 210 150 10
45649-236 178 12 246 186 14 246 190 14 246 190 14
45650-246 190 14 246 190 14 246 190 14 246 190 14
45651-246 190 14 246 190 14 246 190 14 246 190 14
45652-246 190 14 246 190 14 246 190 14 246 190 14
45653-241 196 14 215 174 15 190 178 144 253 253 253
45654-253 253 253 253 253 253 253 253 253 253 253 253
45655-253 253 253 253 253 253 253 253 253 253 253 253
45656-253 253 253 253 253 253 253 253 253 253 253 253
45657-253 253 253 253 253 253 253 253 253 218 218 218
45658- 58 58 58 2 2 6 22 18 6 167 114 7
45659-216 158 10 236 178 12 246 186 14 246 190 14
45660-246 190 14 246 190 14 246 190 14 246 190 14
45661-246 190 14 246 190 14 246 190 14 246 190 14
45662-246 190 14 246 190 14 246 190 14 246 190 14
45663-246 190 14 246 186 14 242 186 14 190 150 46
45664- 54 54 54 22 22 22 6 6 6 0 0 0
45665- 0 0 0 0 0 0 0 0 0 0 0 0
45666- 0 0 0 0 0 0 0 0 0 0 0 0
45667- 0 0 0 0 0 0 0 0 0 14 14 14
45668- 38 38 38 86 86 86 180 133 36 213 154 11
45669-236 178 12 246 186 14 246 190 14 246 190 14
45670-246 190 14 246 190 14 246 190 14 246 190 14
45671-246 190 14 246 190 14 246 190 14 246 190 14
45672-246 190 14 246 190 14 246 190 14 246 190 14
45673-246 190 14 232 195 16 190 146 13 214 214 214
45674-253 253 253 253 253 253 253 253 253 253 253 253
45675-253 253 253 253 253 253 253 253 253 253 253 253
45676-253 253 253 253 253 253 253 253 253 253 253 253
45677-253 253 253 250 250 250 170 170 170 26 26 26
45678- 2 2 6 2 2 6 37 26 9 163 110 8
45679-219 162 10 239 182 13 246 186 14 246 190 14
45680-246 190 14 246 190 14 246 190 14 246 190 14
45681-246 190 14 246 190 14 246 190 14 246 190 14
45682-246 190 14 246 190 14 246 190 14 246 190 14
45683-246 186 14 236 178 12 224 166 10 142 122 72
45684- 46 46 46 18 18 18 6 6 6 0 0 0
45685- 0 0 0 0 0 0 0 0 0 0 0 0
45686- 0 0 0 0 0 0 0 0 0 0 0 0
45687- 0 0 0 0 0 0 6 6 6 18 18 18
45688- 50 50 50 109 106 95 192 133 9 224 166 10
45689-242 186 14 246 190 14 246 190 14 246 190 14
45690-246 190 14 246 190 14 246 190 14 246 190 14
45691-246 190 14 246 190 14 246 190 14 246 190 14
45692-246 190 14 246 190 14 246 190 14 246 190 14
45693-242 186 14 226 184 13 210 162 10 142 110 46
45694-226 226 226 253 253 253 253 253 253 253 253 253
45695-253 253 253 253 253 253 253 253 253 253 253 253
45696-253 253 253 253 253 253 253 253 253 253 253 253
45697-198 198 198 66 66 66 2 2 6 2 2 6
45698- 2 2 6 2 2 6 50 34 6 156 107 11
45699-219 162 10 239 182 13 246 186 14 246 190 14
45700-246 190 14 246 190 14 246 190 14 246 190 14
45701-246 190 14 246 190 14 246 190 14 246 190 14
45702-246 190 14 246 190 14 246 190 14 242 186 14
45703-234 174 13 213 154 11 154 122 46 66 66 66
45704- 30 30 30 10 10 10 0 0 0 0 0 0
45705- 0 0 0 0 0 0 0 0 0 0 0 0
45706- 0 0 0 0 0 0 0 0 0 0 0 0
45707- 0 0 0 0 0 0 6 6 6 22 22 22
45708- 58 58 58 154 121 60 206 145 10 234 174 13
45709-242 186 14 246 186 14 246 190 14 246 190 14
45710-246 190 14 246 190 14 246 190 14 246 190 14
45711-246 190 14 246 190 14 246 190 14 246 190 14
45712-246 190 14 246 190 14 246 190 14 246 190 14
45713-246 186 14 236 178 12 210 162 10 163 110 8
45714- 61 42 6 138 138 138 218 218 218 250 250 250
45715-253 253 253 253 253 253 253 253 253 250 250 250
45716-242 242 242 210 210 210 144 144 144 66 66 66
45717- 6 6 6 2 2 6 2 2 6 2 2 6
45718- 2 2 6 2 2 6 61 42 6 163 110 8
45719-216 158 10 236 178 12 246 190 14 246 190 14
45720-246 190 14 246 190 14 246 190 14 246 190 14
45721-246 190 14 246 190 14 246 190 14 246 190 14
45722-246 190 14 239 182 13 230 174 11 216 158 10
45723-190 142 34 124 112 88 70 70 70 38 38 38
45724- 18 18 18 6 6 6 0 0 0 0 0 0
45725- 0 0 0 0 0 0 0 0 0 0 0 0
45726- 0 0 0 0 0 0 0 0 0 0 0 0
45727- 0 0 0 0 0 0 6 6 6 22 22 22
45728- 62 62 62 168 124 44 206 145 10 224 166 10
45729-236 178 12 239 182 13 242 186 14 242 186 14
45730-246 186 14 246 190 14 246 190 14 246 190 14
45731-246 190 14 246 190 14 246 190 14 246 190 14
45732-246 190 14 246 190 14 246 190 14 246 190 14
45733-246 190 14 236 178 12 216 158 10 175 118 6
45734- 80 54 7 2 2 6 6 6 6 30 30 30
45735- 54 54 54 62 62 62 50 50 50 38 38 38
45736- 14 14 14 2 2 6 2 2 6 2 2 6
45737- 2 2 6 2 2 6 2 2 6 2 2 6
45738- 2 2 6 6 6 6 80 54 7 167 114 7
45739-213 154 11 236 178 12 246 190 14 246 190 14
45740-246 190 14 246 190 14 246 190 14 246 190 14
45741-246 190 14 242 186 14 239 182 13 239 182 13
45742-230 174 11 210 150 10 174 135 50 124 112 88
45743- 82 82 82 54 54 54 34 34 34 18 18 18
45744- 6 6 6 0 0 0 0 0 0 0 0 0
45745- 0 0 0 0 0 0 0 0 0 0 0 0
45746- 0 0 0 0 0 0 0 0 0 0 0 0
45747- 0 0 0 0 0 0 6 6 6 18 18 18
45748- 50 50 50 158 118 36 192 133 9 200 144 11
45749-216 158 10 219 162 10 224 166 10 226 170 11
45750-230 174 11 236 178 12 239 182 13 239 182 13
45751-242 186 14 246 186 14 246 190 14 246 190 14
45752-246 190 14 246 190 14 246 190 14 246 190 14
45753-246 186 14 230 174 11 210 150 10 163 110 8
45754-104 69 6 10 10 10 2 2 6 2 2 6
45755- 2 2 6 2 2 6 2 2 6 2 2 6
45756- 2 2 6 2 2 6 2 2 6 2 2 6
45757- 2 2 6 2 2 6 2 2 6 2 2 6
45758- 2 2 6 6 6 6 91 60 6 167 114 7
45759-206 145 10 230 174 11 242 186 14 246 190 14
45760-246 190 14 246 190 14 246 186 14 242 186 14
45761-239 182 13 230 174 11 224 166 10 213 154 11
45762-180 133 36 124 112 88 86 86 86 58 58 58
45763- 38 38 38 22 22 22 10 10 10 6 6 6
45764- 0 0 0 0 0 0 0 0 0 0 0 0
45765- 0 0 0 0 0 0 0 0 0 0 0 0
45766- 0 0 0 0 0 0 0 0 0 0 0 0
45767- 0 0 0 0 0 0 0 0 0 14 14 14
45768- 34 34 34 70 70 70 138 110 50 158 118 36
45769-167 114 7 180 123 7 192 133 9 197 138 11
45770-200 144 11 206 145 10 213 154 11 219 162 10
45771-224 166 10 230 174 11 239 182 13 242 186 14
45772-246 186 14 246 186 14 246 186 14 246 186 14
45773-239 182 13 216 158 10 185 133 11 152 99 6
45774-104 69 6 18 14 6 2 2 6 2 2 6
45775- 2 2 6 2 2 6 2 2 6 2 2 6
45776- 2 2 6 2 2 6 2 2 6 2 2 6
45777- 2 2 6 2 2 6 2 2 6 2 2 6
45778- 2 2 6 6 6 6 80 54 7 152 99 6
45779-192 133 9 219 162 10 236 178 12 239 182 13
45780-246 186 14 242 186 14 239 182 13 236 178 12
45781-224 166 10 206 145 10 192 133 9 154 121 60
45782- 94 94 94 62 62 62 42 42 42 22 22 22
45783- 14 14 14 6 6 6 0 0 0 0 0 0
45784- 0 0 0 0 0 0 0 0 0 0 0 0
45785- 0 0 0 0 0 0 0 0 0 0 0 0
45786- 0 0 0 0 0 0 0 0 0 0 0 0
45787- 0 0 0 0 0 0 0 0 0 6 6 6
45788- 18 18 18 34 34 34 58 58 58 78 78 78
45789-101 98 89 124 112 88 142 110 46 156 107 11
45790-163 110 8 167 114 7 175 118 6 180 123 7
45791-185 133 11 197 138 11 210 150 10 219 162 10
45792-226 170 11 236 178 12 236 178 12 234 174 13
45793-219 162 10 197 138 11 163 110 8 130 83 6
45794- 91 60 6 10 10 10 2 2 6 2 2 6
45795- 18 18 18 38 38 38 38 38 38 38 38 38
45796- 38 38 38 38 38 38 38 38 38 38 38 38
45797- 38 38 38 38 38 38 26 26 26 2 2 6
45798- 2 2 6 6 6 6 70 47 6 137 92 6
45799-175 118 6 200 144 11 219 162 10 230 174 11
45800-234 174 13 230 174 11 219 162 10 210 150 10
45801-192 133 9 163 110 8 124 112 88 82 82 82
45802- 50 50 50 30 30 30 14 14 14 6 6 6
45803- 0 0 0 0 0 0 0 0 0 0 0 0
45804- 0 0 0 0 0 0 0 0 0 0 0 0
45805- 0 0 0 0 0 0 0 0 0 0 0 0
45806- 0 0 0 0 0 0 0 0 0 0 0 0
45807- 0 0 0 0 0 0 0 0 0 0 0 0
45808- 6 6 6 14 14 14 22 22 22 34 34 34
45809- 42 42 42 58 58 58 74 74 74 86 86 86
45810-101 98 89 122 102 70 130 98 46 121 87 25
45811-137 92 6 152 99 6 163 110 8 180 123 7
45812-185 133 11 197 138 11 206 145 10 200 144 11
45813-180 123 7 156 107 11 130 83 6 104 69 6
45814- 50 34 6 54 54 54 110 110 110 101 98 89
45815- 86 86 86 82 82 82 78 78 78 78 78 78
45816- 78 78 78 78 78 78 78 78 78 78 78 78
45817- 78 78 78 82 82 82 86 86 86 94 94 94
45818-106 106 106 101 101 101 86 66 34 124 80 6
45819-156 107 11 180 123 7 192 133 9 200 144 11
45820-206 145 10 200 144 11 192 133 9 175 118 6
45821-139 102 15 109 106 95 70 70 70 42 42 42
45822- 22 22 22 10 10 10 0 0 0 0 0 0
45823- 0 0 0 0 0 0 0 0 0 0 0 0
45824- 0 0 0 0 0 0 0 0 0 0 0 0
45825- 0 0 0 0 0 0 0 0 0 0 0 0
45826- 0 0 0 0 0 0 0 0 0 0 0 0
45827- 0 0 0 0 0 0 0 0 0 0 0 0
45828- 0 0 0 0 0 0 6 6 6 10 10 10
45829- 14 14 14 22 22 22 30 30 30 38 38 38
45830- 50 50 50 62 62 62 74 74 74 90 90 90
45831-101 98 89 112 100 78 121 87 25 124 80 6
45832-137 92 6 152 99 6 152 99 6 152 99 6
45833-138 86 6 124 80 6 98 70 6 86 66 30
45834-101 98 89 82 82 82 58 58 58 46 46 46
45835- 38 38 38 34 34 34 34 34 34 34 34 34
45836- 34 34 34 34 34 34 34 34 34 34 34 34
45837- 34 34 34 34 34 34 38 38 38 42 42 42
45838- 54 54 54 82 82 82 94 86 76 91 60 6
45839-134 86 6 156 107 11 167 114 7 175 118 6
45840-175 118 6 167 114 7 152 99 6 121 87 25
45841-101 98 89 62 62 62 34 34 34 18 18 18
45842- 6 6 6 0 0 0 0 0 0 0 0 0
45843- 0 0 0 0 0 0 0 0 0 0 0 0
45844- 0 0 0 0 0 0 0 0 0 0 0 0
45845- 0 0 0 0 0 0 0 0 0 0 0 0
45846- 0 0 0 0 0 0 0 0 0 0 0 0
45847- 0 0 0 0 0 0 0 0 0 0 0 0
45848- 0 0 0 0 0 0 0 0 0 0 0 0
45849- 0 0 0 6 6 6 6 6 6 10 10 10
45850- 18 18 18 22 22 22 30 30 30 42 42 42
45851- 50 50 50 66 66 66 86 86 86 101 98 89
45852-106 86 58 98 70 6 104 69 6 104 69 6
45853-104 69 6 91 60 6 82 62 34 90 90 90
45854- 62 62 62 38 38 38 22 22 22 14 14 14
45855- 10 10 10 10 10 10 10 10 10 10 10 10
45856- 10 10 10 10 10 10 6 6 6 10 10 10
45857- 10 10 10 10 10 10 10 10 10 14 14 14
45858- 22 22 22 42 42 42 70 70 70 89 81 66
45859- 80 54 7 104 69 6 124 80 6 137 92 6
45860-134 86 6 116 81 8 100 82 52 86 86 86
45861- 58 58 58 30 30 30 14 14 14 6 6 6
45862- 0 0 0 0 0 0 0 0 0 0 0 0
45863- 0 0 0 0 0 0 0 0 0 0 0 0
45864- 0 0 0 0 0 0 0 0 0 0 0 0
45865- 0 0 0 0 0 0 0 0 0 0 0 0
45866- 0 0 0 0 0 0 0 0 0 0 0 0
45867- 0 0 0 0 0 0 0 0 0 0 0 0
45868- 0 0 0 0 0 0 0 0 0 0 0 0
45869- 0 0 0 0 0 0 0 0 0 0 0 0
45870- 0 0 0 6 6 6 10 10 10 14 14 14
45871- 18 18 18 26 26 26 38 38 38 54 54 54
45872- 70 70 70 86 86 86 94 86 76 89 81 66
45873- 89 81 66 86 86 86 74 74 74 50 50 50
45874- 30 30 30 14 14 14 6 6 6 0 0 0
45875- 0 0 0 0 0 0 0 0 0 0 0 0
45876- 0 0 0 0 0 0 0 0 0 0 0 0
45877- 0 0 0 0 0 0 0 0 0 0 0 0
45878- 6 6 6 18 18 18 34 34 34 58 58 58
45879- 82 82 82 89 81 66 89 81 66 89 81 66
45880- 94 86 66 94 86 76 74 74 74 50 50 50
45881- 26 26 26 14 14 14 6 6 6 0 0 0
45882- 0 0 0 0 0 0 0 0 0 0 0 0
45883- 0 0 0 0 0 0 0 0 0 0 0 0
45884- 0 0 0 0 0 0 0 0 0 0 0 0
45885- 0 0 0 0 0 0 0 0 0 0 0 0
45886- 0 0 0 0 0 0 0 0 0 0 0 0
45887- 0 0 0 0 0 0 0 0 0 0 0 0
45888- 0 0 0 0 0 0 0 0 0 0 0 0
45889- 0 0 0 0 0 0 0 0 0 0 0 0
45890- 0 0 0 0 0 0 0 0 0 0 0 0
45891- 6 6 6 6 6 6 14 14 14 18 18 18
45892- 30 30 30 38 38 38 46 46 46 54 54 54
45893- 50 50 50 42 42 42 30 30 30 18 18 18
45894- 10 10 10 0 0 0 0 0 0 0 0 0
45895- 0 0 0 0 0 0 0 0 0 0 0 0
45896- 0 0 0 0 0 0 0 0 0 0 0 0
45897- 0 0 0 0 0 0 0 0 0 0 0 0
45898- 0 0 0 6 6 6 14 14 14 26 26 26
45899- 38 38 38 50 50 50 58 58 58 58 58 58
45900- 54 54 54 42 42 42 30 30 30 18 18 18
45901- 10 10 10 0 0 0 0 0 0 0 0 0
45902- 0 0 0 0 0 0 0 0 0 0 0 0
45903- 0 0 0 0 0 0 0 0 0 0 0 0
45904- 0 0 0 0 0 0 0 0 0 0 0 0
45905- 0 0 0 0 0 0 0 0 0 0 0 0
45906- 0 0 0 0 0 0 0 0 0 0 0 0
45907- 0 0 0 0 0 0 0 0 0 0 0 0
45908- 0 0 0 0 0 0 0 0 0 0 0 0
45909- 0 0 0 0 0 0 0 0 0 0 0 0
45910- 0 0 0 0 0 0 0 0 0 0 0 0
45911- 0 0 0 0 0 0 0 0 0 6 6 6
45912- 6 6 6 10 10 10 14 14 14 18 18 18
45913- 18 18 18 14 14 14 10 10 10 6 6 6
45914- 0 0 0 0 0 0 0 0 0 0 0 0
45915- 0 0 0 0 0 0 0 0 0 0 0 0
45916- 0 0 0 0 0 0 0 0 0 0 0 0
45917- 0 0 0 0 0 0 0 0 0 0 0 0
45918- 0 0 0 0 0 0 0 0 0 6 6 6
45919- 14 14 14 18 18 18 22 22 22 22 22 22
45920- 18 18 18 14 14 14 10 10 10 6 6 6
45921- 0 0 0 0 0 0 0 0 0 0 0 0
45922- 0 0 0 0 0 0 0 0 0 0 0 0
45923- 0 0 0 0 0 0 0 0 0 0 0 0
45924- 0 0 0 0 0 0 0 0 0 0 0 0
45925- 0 0 0 0 0 0 0 0 0 0 0 0
45926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45939+4 4 4 4 4 4
45940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45952+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45953+4 4 4 4 4 4
45954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45966+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45967+4 4 4 4 4 4
45968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45981+4 4 4 4 4 4
45982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45995+4 4 4 4 4 4
45996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46009+4 4 4 4 4 4
46010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46014+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46015+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46019+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46020+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46021+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46023+4 4 4 4 4 4
46024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46028+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46029+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46030+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46033+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46034+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46035+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46036+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46037+4 4 4 4 4 4
46038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46042+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46043+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46044+0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
46048+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46049+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46050+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46051+4 4 4 4 4 4
46052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46055+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46056+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46057+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46058+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
46061+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46062+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46063+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46064+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46065+4 4 4 4 4 4
46066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46069+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46070+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46071+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46072+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46073+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46074+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46075+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46076+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46077+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46078+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46079+4 4 4 4 4 4
46080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46083+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46084+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46085+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46086+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46087+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46088+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46089+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46090+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46091+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46092+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46093+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 4 4 4 4 4 4 5 5 5 3 3 3
46097+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46098+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46099+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46100+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46101+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46102+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46103+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46104+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46105+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46106+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46107+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 4 4 4 2 2 2 0 0 0 4 0 0
46111+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46112+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46113+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46114+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46115+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46116+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46117+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46118+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46119+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46120+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46121+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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46125+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46126+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46127+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46128+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46129+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46130+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46131+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46132+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46133+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46134+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46135+4 4 4 4 4 4
46136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46138+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46139+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46140+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46141+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46142+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46143+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46144+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46145+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46146+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46147+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46148+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46149+4 4 4 4 4 4
46150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46151+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
46152+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46153+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46154+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46155+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46156+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46157+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46158+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46159+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46160+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46161+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46162+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46163+4 4 4 4 4 4
46164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46165+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46166+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
46167+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
46168+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46169+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
46170+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
46171+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
46172+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
46173+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
46174+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
46175+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
46176+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
46177+0 0 0 4 4 4
46178+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46179+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
46180+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
46181+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
46182+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
46183+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
46184+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
46185+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
46186+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
46187+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
46188+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
46189+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
46190+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
46191+2 0 0 0 0 0
46192+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
46193+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
46194+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
46195+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
46196+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
46197+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
46198+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
46199+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
46200+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
46201+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
46202+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
46203+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
46204+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
46205+37 38 37 0 0 0
46206+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46207+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
46208+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
46209+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
46210+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
46211+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
46212+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
46213+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
46214+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
46215+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
46216+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
46217+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
46218+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
46219+85 115 134 4 0 0
46220+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
46221+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
46222+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
46223+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
46224+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
46225+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
46226+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
46227+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
46228+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
46229+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
46230+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
46231+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
46232+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
46233+60 73 81 4 0 0
46234+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
46235+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
46236+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
46237+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
46238+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
46239+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
46240+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
46241+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
46242+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
46243+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
46244+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
46245+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
46246+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
46247+16 19 21 4 0 0
46248+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
46249+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
46250+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
46251+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
46252+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
46253+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
46254+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
46255+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
46256+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
46257+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
46258+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
46259+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
46260+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
46261+4 0 0 4 3 3
46262+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
46263+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
46264+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
46265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
46266+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
46267+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
46268+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
46269+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
46270+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
46271+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
46272+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
46273+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
46274+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
46275+3 2 2 4 4 4
46276+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
46277+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
46278+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
46279+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46280+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
46281+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
46282+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
46283+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
46284+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
46285+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
46286+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
46287+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
46288+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
46289+4 4 4 4 4 4
46290+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
46291+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
46292+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
46293+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
46294+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
46295+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
46296+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
46297+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
46298+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
46299+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
46300+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
46301+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
46302+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
46303+4 4 4 4 4 4
46304+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
46305+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
46306+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
46307+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
46308+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
46309+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46310+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
46311+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
46312+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
46313+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
46314+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
46315+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
46316+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
46317+5 5 5 5 5 5
46318+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
46319+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
46320+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
46321+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
46322+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
46323+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46324+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
46325+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
46326+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
46327+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
46328+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
46329+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
46330+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46331+5 5 5 4 4 4
46332+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
46333+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
46334+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
46335+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
46336+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46337+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
46338+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
46339+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
46340+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
46341+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
46342+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
46343+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46345+4 4 4 4 4 4
46346+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
46347+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
46348+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
46349+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
46350+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
46351+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46352+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46353+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
46354+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
46355+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
46356+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
46357+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
46358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46359+4 4 4 4 4 4
46360+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
46361+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
46362+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
46363+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
46364+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46365+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
46366+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
46367+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
46368+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
46369+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
46370+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
46371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46373+4 4 4 4 4 4
46374+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
46375+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
46376+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
46377+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
46378+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46379+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46380+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46381+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
46382+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
46383+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
46384+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
46385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46387+4 4 4 4 4 4
46388+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
46389+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
46390+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
46391+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
46392+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46393+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
46394+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46395+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
46396+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
46397+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
46398+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46401+4 4 4 4 4 4
46402+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
46403+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
46404+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
46405+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
46406+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46407+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
46408+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
46409+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
46410+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
46411+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
46412+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
46413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46415+4 4 4 4 4 4
46416+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
46417+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
46418+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
46419+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
46420+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46421+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
46422+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
46423+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
46424+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
46425+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
46426+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
46427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46429+4 4 4 4 4 4
46430+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
46431+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
46432+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
46433+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46434+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
46435+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
46436+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
46437+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
46438+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
46439+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
46440+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46443+4 4 4 4 4 4
46444+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
46445+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
46446+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
46447+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46448+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46449+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
46450+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
46451+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
46452+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
46453+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
46454+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46457+4 4 4 4 4 4
46458+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
46459+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
46460+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46461+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46462+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46463+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
46464+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
46465+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
46466+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
46467+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
46468+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46471+4 4 4 4 4 4
46472+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
46473+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
46474+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46475+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46476+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46477+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46478+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46479+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46480+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46481+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46482+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46485+4 4 4 4 4 4
46486+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46487+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46488+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46489+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46490+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46491+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46492+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46493+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46494+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46495+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46496+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46499+4 4 4 4 4 4
46500+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46501+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46502+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46503+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46504+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46505+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46506+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46507+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46508+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46509+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46510+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46513+4 4 4 4 4 4
46514+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46515+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46516+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46517+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46518+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46519+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46520+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46521+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46522+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46523+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46524+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46527+4 4 4 4 4 4
46528+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46529+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46530+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46531+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46532+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46533+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46534+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46535+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46536+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46537+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46538+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46541+4 4 4 4 4 4
46542+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46543+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46544+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46545+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46546+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46547+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46548+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46549+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46550+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46551+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46552+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46555+4 4 4 4 4 4
46556+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46557+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46558+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46559+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46560+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46561+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46562+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46563+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46564+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46565+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46566+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46569+4 4 4 4 4 4
46570+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46571+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46572+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46573+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46574+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46575+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46576+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46577+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46578+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46579+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46580+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46583+4 4 4 4 4 4
46584+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46585+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46586+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46587+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46588+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46589+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46590+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46591+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46592+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46593+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46594+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46597+4 4 4 4 4 4
46598+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46599+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
46600+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
46601+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
46602+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
46603+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
46604+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46605+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
46606+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46607+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46608+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46611+4 4 4 4 4 4
46612+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46613+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
46614+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
46615+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46616+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
46617+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
46618+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46619+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
46620+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46621+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46622+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46625+4 4 4 4 4 4
46626+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46627+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
46628+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
46629+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
46630+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
46631+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
46632+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
46633+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
46634+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
46635+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46636+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46639+4 4 4 4 4 4
46640+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46641+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
46642+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
46643+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
46644+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
46645+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
46646+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
46647+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
46648+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
46649+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46650+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46653+4 4 4 4 4 4
46654+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
46655+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
46656+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
46657+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
46658+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46659+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
46660+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
46661+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
46662+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
46663+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46664+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46667+4 4 4 4 4 4
46668+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46669+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
46670+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
46671+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
46672+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
46673+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
46674+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
46675+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
46676+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
46677+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46678+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46681+4 4 4 4 4 4
46682+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
46683+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
46684+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
46685+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
46686+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
46687+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
46688+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
46689+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
46690+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
46691+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
46692+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46695+4 4 4 4 4 4
46696+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
46697+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46698+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
46699+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
46700+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
46701+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
46702+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
46703+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
46704+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
46705+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
46706+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46709+4 4 4 4 4 4
46710+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
46711+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46712+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
46713+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
46714+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
46715+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
46716+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46717+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
46718+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
46719+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
46720+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46723+4 4 4 4 4 4
46724+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
46725+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
46726+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
46727+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
46728+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
46729+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
46730+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
46731+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
46732+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
46733+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
46734+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46737+4 4 4 4 4 4
46738+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
46739+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
46740+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46741+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
46742+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
46743+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
46744+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
46745+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
46746+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
46747+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
46748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46751+4 4 4 4 4 4
46752+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46753+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
46754+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
46755+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
46756+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
46757+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
46758+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
46759+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
46760+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
46761+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46765+4 4 4 4 4 4
46766+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
46767+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
46768+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
46769+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
46770+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
46771+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
46772+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
46773+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
46774+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
46775+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46779+4 4 4 4 4 4
46780+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
46781+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
46782+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
46783+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
46784+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
46785+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
46786+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
46787+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
46788+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46789+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46793+4 4 4 4 4 4
46794+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
46795+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46796+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
46797+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46798+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
46799+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
46800+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
46801+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
46802+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
46803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46807+4 4 4 4 4 4
46808+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
46809+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
46810+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
46811+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
46812+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
46813+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
46814+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
46815+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
46816+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
46817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46821+4 4 4 4 4 4
46822+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46823+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
46824+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
46825+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
46826+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
46827+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
46828+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
46829+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
46830+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46835+4 4 4 4 4 4
46836+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
46837+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
46838+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46839+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
46840+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
46841+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
46842+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
46843+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
46844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46849+4 4 4 4 4 4
46850+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46851+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
46852+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
46853+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
46854+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
46855+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
46856+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
46857+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46863+4 4 4 4 4 4
46864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46865+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
46866+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46867+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
46868+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
46869+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
46870+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
46871+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
46872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46877+4 4 4 4 4 4
46878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46879+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
46880+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
46881+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
46882+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
46883+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
46884+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
46885+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
46886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46891+4 4 4 4 4 4
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 5 5 5 5 5 5 5 5 5
46894+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
46895+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46896+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
46897+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
46898+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
46899+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46905+4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46909+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
46910+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
46911+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
46912+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
46913+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46919+4 4 4 4 4 4
46920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46923+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46924+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
46925+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
46926+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
46927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46933+4 4 4 4 4 4
46934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46937+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46938+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46939+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
46940+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
46941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46947+4 4 4 4 4 4
46948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46951+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46952+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46953+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46954+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
46955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46961+4 4 4 4 4 4
46962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46965+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
46966+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
46967+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
46968+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
46969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46975+4 4 4 4 4 4
46976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46980+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
46981+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46982+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46989+4 4 4 4 4 4
46990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46994+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
46995+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
46996+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47003+4 4 4 4 4 4
47004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47008+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47009+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47010+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47017+4 4 4 4 4 4
47018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47022+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47023+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47031+4 4 4 4 4 4
47032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47036+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47037+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47045+4 4 4 4 4 4
47046diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47047index fe92eed..106e085 100644
47048--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47049+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47050@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47051 struct mb862xxfb_par *par = info->par;
47052
47053 if (info->var.bits_per_pixel == 32) {
47054- info->fbops->fb_fillrect = cfb_fillrect;
47055- info->fbops->fb_copyarea = cfb_copyarea;
47056- info->fbops->fb_imageblit = cfb_imageblit;
47057+ pax_open_kernel();
47058+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47059+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47060+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47061+ pax_close_kernel();
47062 } else {
47063 outreg(disp, GC_L0EM, 3);
47064- info->fbops->fb_fillrect = mb86290fb_fillrect;
47065- info->fbops->fb_copyarea = mb86290fb_copyarea;
47066- info->fbops->fb_imageblit = mb86290fb_imageblit;
47067+ pax_open_kernel();
47068+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47069+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47070+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47071+ pax_close_kernel();
47072 }
47073 outreg(draw, GDC_REG_DRAW_BASE, 0);
47074 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47075diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47076index ff22871..b129bed 100644
47077--- a/drivers/video/nvidia/nvidia.c
47078+++ b/drivers/video/nvidia/nvidia.c
47079@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47080 info->fix.line_length = (info->var.xres_virtual *
47081 info->var.bits_per_pixel) >> 3;
47082 if (info->var.accel_flags) {
47083- info->fbops->fb_imageblit = nvidiafb_imageblit;
47084- info->fbops->fb_fillrect = nvidiafb_fillrect;
47085- info->fbops->fb_copyarea = nvidiafb_copyarea;
47086- info->fbops->fb_sync = nvidiafb_sync;
47087+ pax_open_kernel();
47088+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47089+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47090+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47091+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47092+ pax_close_kernel();
47093 info->pixmap.scan_align = 4;
47094 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47095 info->flags |= FBINFO_READS_FAST;
47096 NVResetGraphics(info);
47097 } else {
47098- info->fbops->fb_imageblit = cfb_imageblit;
47099- info->fbops->fb_fillrect = cfb_fillrect;
47100- info->fbops->fb_copyarea = cfb_copyarea;
47101- info->fbops->fb_sync = NULL;
47102+ pax_open_kernel();
47103+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47104+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47105+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47106+ *(void **)&info->fbops->fb_sync = NULL;
47107+ pax_close_kernel();
47108 info->pixmap.scan_align = 1;
47109 info->flags |= FBINFO_HWACCEL_DISABLED;
47110 info->flags &= ~FBINFO_READS_FAST;
47111@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47112 info->pixmap.size = 8 * 1024;
47113 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47114
47115- if (!hwcur)
47116- info->fbops->fb_cursor = NULL;
47117+ if (!hwcur) {
47118+ pax_open_kernel();
47119+ *(void **)&info->fbops->fb_cursor = NULL;
47120+ pax_close_kernel();
47121+ }
47122
47123 info->var.accel_flags = (!noaccel);
47124
47125diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47126index 76d9053..dec2bfd 100644
47127--- a/drivers/video/s1d13xxxfb.c
47128+++ b/drivers/video/s1d13xxxfb.c
47129@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47130
47131 switch(prod_id) {
47132 case S1D13506_PROD_ID: /* activate acceleration */
47133- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47134- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47135+ pax_open_kernel();
47136+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47137+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47138+ pax_close_kernel();
47139 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47140 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47141 break;
47142diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47143index 97bd662..39fab85 100644
47144--- a/drivers/video/smscufx.c
47145+++ b/drivers/video/smscufx.c
47146@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47147 fb_deferred_io_cleanup(info);
47148 kfree(info->fbdefio);
47149 info->fbdefio = NULL;
47150- info->fbops->fb_mmap = ufx_ops_mmap;
47151+ pax_open_kernel();
47152+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47153+ pax_close_kernel();
47154 }
47155
47156 pr_debug("released /dev/fb%d user=%d count=%d",
47157diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
47158index 86d449e..8e04dc5 100644
47159--- a/drivers/video/udlfb.c
47160+++ b/drivers/video/udlfb.c
47161@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
47162 dlfb_urb_completion(urb);
47163
47164 error:
47165- atomic_add(bytes_sent, &dev->bytes_sent);
47166- atomic_add(bytes_identical, &dev->bytes_identical);
47167- atomic_add(width*height*2, &dev->bytes_rendered);
47168+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47169+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47170+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
47171 end_cycles = get_cycles();
47172- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47173+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47174 >> 10)), /* Kcycles */
47175 &dev->cpu_kcycles_used);
47176
47177@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
47178 dlfb_urb_completion(urb);
47179
47180 error:
47181- atomic_add(bytes_sent, &dev->bytes_sent);
47182- atomic_add(bytes_identical, &dev->bytes_identical);
47183- atomic_add(bytes_rendered, &dev->bytes_rendered);
47184+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47185+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47186+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
47187 end_cycles = get_cycles();
47188- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47189+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47190 >> 10)), /* Kcycles */
47191 &dev->cpu_kcycles_used);
47192 }
47193@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
47194 fb_deferred_io_cleanup(info);
47195 kfree(info->fbdefio);
47196 info->fbdefio = NULL;
47197- info->fbops->fb_mmap = dlfb_ops_mmap;
47198+ pax_open_kernel();
47199+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
47200+ pax_close_kernel();
47201 }
47202
47203 pr_warn("released /dev/fb%d user=%d count=%d\n",
47204@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
47205 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47206 struct dlfb_data *dev = fb_info->par;
47207 return snprintf(buf, PAGE_SIZE, "%u\n",
47208- atomic_read(&dev->bytes_rendered));
47209+ atomic_read_unchecked(&dev->bytes_rendered));
47210 }
47211
47212 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47213@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47214 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47215 struct dlfb_data *dev = fb_info->par;
47216 return snprintf(buf, PAGE_SIZE, "%u\n",
47217- atomic_read(&dev->bytes_identical));
47218+ atomic_read_unchecked(&dev->bytes_identical));
47219 }
47220
47221 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47222@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47223 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47224 struct dlfb_data *dev = fb_info->par;
47225 return snprintf(buf, PAGE_SIZE, "%u\n",
47226- atomic_read(&dev->bytes_sent));
47227+ atomic_read_unchecked(&dev->bytes_sent));
47228 }
47229
47230 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47231@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47232 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47233 struct dlfb_data *dev = fb_info->par;
47234 return snprintf(buf, PAGE_SIZE, "%u\n",
47235- atomic_read(&dev->cpu_kcycles_used));
47236+ atomic_read_unchecked(&dev->cpu_kcycles_used));
47237 }
47238
47239 static ssize_t edid_show(
47240@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
47241 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47242 struct dlfb_data *dev = fb_info->par;
47243
47244- atomic_set(&dev->bytes_rendered, 0);
47245- atomic_set(&dev->bytes_identical, 0);
47246- atomic_set(&dev->bytes_sent, 0);
47247- atomic_set(&dev->cpu_kcycles_used, 0);
47248+ atomic_set_unchecked(&dev->bytes_rendered, 0);
47249+ atomic_set_unchecked(&dev->bytes_identical, 0);
47250+ atomic_set_unchecked(&dev->bytes_sent, 0);
47251+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
47252
47253 return count;
47254 }
47255diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
47256index b75db01..ad2f34a 100644
47257--- a/drivers/video/uvesafb.c
47258+++ b/drivers/video/uvesafb.c
47259@@ -19,6 +19,7 @@
47260 #include <linux/io.h>
47261 #include <linux/mutex.h>
47262 #include <linux/slab.h>
47263+#include <linux/moduleloader.h>
47264 #include <video/edid.h>
47265 #include <video/uvesafb.h>
47266 #ifdef CONFIG_X86
47267@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
47268 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
47269 par->pmi_setpal = par->ypan = 0;
47270 } else {
47271+
47272+#ifdef CONFIG_PAX_KERNEXEC
47273+#ifdef CONFIG_MODULES
47274+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
47275+#endif
47276+ if (!par->pmi_code) {
47277+ par->pmi_setpal = par->ypan = 0;
47278+ return 0;
47279+ }
47280+#endif
47281+
47282 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
47283 + task->t.regs.edi);
47284+
47285+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47286+ pax_open_kernel();
47287+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
47288+ pax_close_kernel();
47289+
47290+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
47291+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
47292+#else
47293 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
47294 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
47295+#endif
47296+
47297 printk(KERN_INFO "uvesafb: protected mode interface info at "
47298 "%04x:%04x\n",
47299 (u16)task->t.regs.es, (u16)task->t.regs.edi);
47300@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
47301 par->ypan = ypan;
47302
47303 if (par->pmi_setpal || par->ypan) {
47304+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
47305 if (__supported_pte_mask & _PAGE_NX) {
47306 par->pmi_setpal = par->ypan = 0;
47307 printk(KERN_WARNING "uvesafb: NX protection is actively."
47308 "We have better not to use the PMI.\n");
47309- } else {
47310+ } else
47311+#endif
47312 uvesafb_vbe_getpmi(task, par);
47313- }
47314 }
47315 #else
47316 /* The protected mode interface is not available on non-x86. */
47317@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47318 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
47319
47320 /* Disable blanking if the user requested so. */
47321- if (!blank)
47322- info->fbops->fb_blank = NULL;
47323+ if (!blank) {
47324+ pax_open_kernel();
47325+ *(void **)&info->fbops->fb_blank = NULL;
47326+ pax_close_kernel();
47327+ }
47328
47329 /*
47330 * Find out how much IO memory is required for the mode with
47331@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47332 info->flags = FBINFO_FLAG_DEFAULT |
47333 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
47334
47335- if (!par->ypan)
47336- info->fbops->fb_pan_display = NULL;
47337+ if (!par->ypan) {
47338+ pax_open_kernel();
47339+ *(void **)&info->fbops->fb_pan_display = NULL;
47340+ pax_close_kernel();
47341+ }
47342 }
47343
47344 static void uvesafb_init_mtrr(struct fb_info *info)
47345@@ -1836,6 +1866,11 @@ out:
47346 if (par->vbe_modes)
47347 kfree(par->vbe_modes);
47348
47349+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47350+ if (par->pmi_code)
47351+ module_free_exec(NULL, par->pmi_code);
47352+#endif
47353+
47354 framebuffer_release(info);
47355 return err;
47356 }
47357@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
47358 kfree(par->vbe_state_orig);
47359 if (par->vbe_state_saved)
47360 kfree(par->vbe_state_saved);
47361+
47362+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47363+ if (par->pmi_code)
47364+ module_free_exec(NULL, par->pmi_code);
47365+#endif
47366+
47367 }
47368
47369 framebuffer_release(info);
47370diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
47371index 501b340..d80aa17 100644
47372--- a/drivers/video/vesafb.c
47373+++ b/drivers/video/vesafb.c
47374@@ -9,6 +9,7 @@
47375 */
47376
47377 #include <linux/module.h>
47378+#include <linux/moduleloader.h>
47379 #include <linux/kernel.h>
47380 #include <linux/errno.h>
47381 #include <linux/string.h>
47382@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
47383 static int vram_total __initdata; /* Set total amount of memory */
47384 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
47385 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
47386-static void (*pmi_start)(void) __read_mostly;
47387-static void (*pmi_pal) (void) __read_mostly;
47388+static void (*pmi_start)(void) __read_only;
47389+static void (*pmi_pal) (void) __read_only;
47390 static int depth __read_mostly;
47391 static int vga_compat __read_mostly;
47392 /* --------------------------------------------------------------------- */
47393@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
47394 unsigned int size_vmode;
47395 unsigned int size_remap;
47396 unsigned int size_total;
47397+ void *pmi_code = NULL;
47398
47399 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
47400 return -ENODEV;
47401@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
47402 size_remap = size_total;
47403 vesafb_fix.smem_len = size_remap;
47404
47405-#ifndef __i386__
47406- screen_info.vesapm_seg = 0;
47407-#endif
47408-
47409 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
47410 printk(KERN_WARNING
47411 "vesafb: cannot reserve video memory at 0x%lx\n",
47412@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
47413 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
47414 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
47415
47416+#ifdef __i386__
47417+
47418+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47419+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
47420+ if (!pmi_code)
47421+#elif !defined(CONFIG_PAX_KERNEXEC)
47422+ if (0)
47423+#endif
47424+
47425+#endif
47426+ screen_info.vesapm_seg = 0;
47427+
47428 if (screen_info.vesapm_seg) {
47429- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
47430- screen_info.vesapm_seg,screen_info.vesapm_off);
47431+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
47432+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
47433 }
47434
47435 if (screen_info.vesapm_seg < 0xc000)
47436@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
47437
47438 if (ypan || pmi_setpal) {
47439 unsigned short *pmi_base;
47440+
47441 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
47442- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
47443- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
47444+
47445+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47446+ pax_open_kernel();
47447+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
47448+#else
47449+ pmi_code = pmi_base;
47450+#endif
47451+
47452+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
47453+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
47454+
47455+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47456+ pmi_start = ktva_ktla(pmi_start);
47457+ pmi_pal = ktva_ktla(pmi_pal);
47458+ pax_close_kernel();
47459+#endif
47460+
47461 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
47462 if (pmi_base[3]) {
47463 printk(KERN_INFO "vesafb: pmi: ports = ");
47464@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47465 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
47466 (ypan ? FBINFO_HWACCEL_YPAN : 0);
47467
47468- if (!ypan)
47469- info->fbops->fb_pan_display = NULL;
47470+ if (!ypan) {
47471+ pax_open_kernel();
47472+ *(void **)&info->fbops->fb_pan_display = NULL;
47473+ pax_close_kernel();
47474+ }
47475
47476 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47477 err = -ENOMEM;
47478@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47479 info->node, info->fix.id);
47480 return 0;
47481 err:
47482+
47483+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47484+ module_free_exec(NULL, pmi_code);
47485+#endif
47486+
47487 if (info->screen_base)
47488 iounmap(info->screen_base);
47489 framebuffer_release(info);
47490diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47491index 88714ae..16c2e11 100644
47492--- a/drivers/video/via/via_clock.h
47493+++ b/drivers/video/via/via_clock.h
47494@@ -56,7 +56,7 @@ struct via_clock {
47495
47496 void (*set_engine_pll_state)(u8 state);
47497 void (*set_engine_pll)(struct via_pll_config config);
47498-};
47499+} __no_const;
47500
47501
47502 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47503diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47504index fef20db..d28b1ab 100644
47505--- a/drivers/xen/xenfs/xenstored.c
47506+++ b/drivers/xen/xenfs/xenstored.c
47507@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47508 static int xsd_kva_open(struct inode *inode, struct file *file)
47509 {
47510 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47511+#ifdef CONFIG_GRKERNSEC_HIDESYM
47512+ NULL);
47513+#else
47514 xen_store_interface);
47515+#endif
47516+
47517 if (!file->private_data)
47518 return -ENOMEM;
47519 return 0;
47520diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47521index 890bed5..17ae73e 100644
47522--- a/fs/9p/vfs_inode.c
47523+++ b/fs/9p/vfs_inode.c
47524@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47525 void
47526 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47527 {
47528- char *s = nd_get_link(nd);
47529+ const char *s = nd_get_link(nd);
47530
47531 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47532 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47533diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47534index 0efd152..b5802ad 100644
47535--- a/fs/Kconfig.binfmt
47536+++ b/fs/Kconfig.binfmt
47537@@ -89,7 +89,7 @@ config HAVE_AOUT
47538
47539 config BINFMT_AOUT
47540 tristate "Kernel support for a.out and ECOFF binaries"
47541- depends on HAVE_AOUT
47542+ depends on HAVE_AOUT && BROKEN
47543 ---help---
47544 A.out (Assembler.OUTput) is a set of formats for libraries and
47545 executables used in the earliest versions of UNIX. Linux used
47546diff --git a/fs/aio.c b/fs/aio.c
47547index 71f613c..9d01f1f 100644
47548--- a/fs/aio.c
47549+++ b/fs/aio.c
47550@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47551 size += sizeof(struct io_event) * nr_events;
47552 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47553
47554- if (nr_pages < 0)
47555+ if (nr_pages <= 0)
47556 return -EINVAL;
47557
47558 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47559@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47560 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47561 {
47562 ssize_t ret;
47563+ struct iovec iovstack;
47564
47565 #ifdef CONFIG_COMPAT
47566 if (compat)
47567 ret = compat_rw_copy_check_uvector(type,
47568 (struct compat_iovec __user *)kiocb->ki_buf,
47569- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47570+ kiocb->ki_nbytes, 1, &iovstack,
47571 &kiocb->ki_iovec);
47572 else
47573 #endif
47574 ret = rw_copy_check_uvector(type,
47575 (struct iovec __user *)kiocb->ki_buf,
47576- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47577+ kiocb->ki_nbytes, 1, &iovstack,
47578 &kiocb->ki_iovec);
47579 if (ret < 0)
47580 goto out;
47581@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47582 if (ret < 0)
47583 goto out;
47584
47585+ if (kiocb->ki_iovec == &iovstack) {
47586+ kiocb->ki_inline_vec = iovstack;
47587+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
47588+ }
47589 kiocb->ki_nr_segs = kiocb->ki_nbytes;
47590 kiocb->ki_cur_seg = 0;
47591 /* ki_nbytes/left now reflect bytes instead of segs */
47592diff --git a/fs/attr.c b/fs/attr.c
47593index 1449adb..a2038c2 100644
47594--- a/fs/attr.c
47595+++ b/fs/attr.c
47596@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
47597 unsigned long limit;
47598
47599 limit = rlimit(RLIMIT_FSIZE);
47600+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
47601 if (limit != RLIM_INFINITY && offset > limit)
47602 goto out_sig;
47603 if (offset > inode->i_sb->s_maxbytes)
47604diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
47605index 03bc1d3..6205356 100644
47606--- a/fs/autofs4/waitq.c
47607+++ b/fs/autofs4/waitq.c
47608@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
47609 {
47610 unsigned long sigpipe, flags;
47611 mm_segment_t fs;
47612- const char *data = (const char *)addr;
47613+ const char __user *data = (const char __force_user *)addr;
47614 ssize_t wr = 0;
47615
47616 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
47617@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
47618 return 1;
47619 }
47620
47621+#ifdef CONFIG_GRKERNSEC_HIDESYM
47622+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
47623+#endif
47624+
47625 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47626 enum autofs_notify notify)
47627 {
47628@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47629
47630 /* If this is a direct mount request create a dummy name */
47631 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
47632+#ifdef CONFIG_GRKERNSEC_HIDESYM
47633+ /* this name does get written to userland via autofs4_write() */
47634+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
47635+#else
47636 qstr.len = sprintf(name, "%p", dentry);
47637+#endif
47638 else {
47639 qstr.len = autofs4_getpath(sbi, dentry, &name);
47640 if (!qstr.len) {
47641diff --git a/fs/befs/endian.h b/fs/befs/endian.h
47642index 2722387..c8dd2a7 100644
47643--- a/fs/befs/endian.h
47644+++ b/fs/befs/endian.h
47645@@ -11,7 +11,7 @@
47646
47647 #include <asm/byteorder.h>
47648
47649-static inline u64
47650+static inline u64 __intentional_overflow(-1)
47651 fs64_to_cpu(const struct super_block *sb, fs64 n)
47652 {
47653 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47654@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
47655 return (__force fs64)cpu_to_be64(n);
47656 }
47657
47658-static inline u32
47659+static inline u32 __intentional_overflow(-1)
47660 fs32_to_cpu(const struct super_block *sb, fs32 n)
47661 {
47662 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47663diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
47664index 2b3bda8..6a2d4be 100644
47665--- a/fs/befs/linuxvfs.c
47666+++ b/fs/befs/linuxvfs.c
47667@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47668 {
47669 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
47670 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
47671- char *link = nd_get_link(nd);
47672+ const char *link = nd_get_link(nd);
47673 if (!IS_ERR(link))
47674 kfree(link);
47675 }
47676diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
47677index 6043567..16a9239 100644
47678--- a/fs/binfmt_aout.c
47679+++ b/fs/binfmt_aout.c
47680@@ -16,6 +16,7 @@
47681 #include <linux/string.h>
47682 #include <linux/fs.h>
47683 #include <linux/file.h>
47684+#include <linux/security.h>
47685 #include <linux/stat.h>
47686 #include <linux/fcntl.h>
47687 #include <linux/ptrace.h>
47688@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
47689 #endif
47690 # define START_STACK(u) ((void __user *)u.start_stack)
47691
47692+ memset(&dump, 0, sizeof(dump));
47693+
47694 fs = get_fs();
47695 set_fs(KERNEL_DS);
47696 has_dumped = 1;
47697@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
47698
47699 /* If the size of the dump file exceeds the rlimit, then see what would happen
47700 if we wrote the stack, but not the data area. */
47701+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
47702 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
47703 dump.u_dsize = 0;
47704
47705 /* Make sure we have enough room to write the stack and data areas. */
47706+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
47707 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
47708 dump.u_ssize = 0;
47709
47710@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
47711 rlim = rlimit(RLIMIT_DATA);
47712 if (rlim >= RLIM_INFINITY)
47713 rlim = ~0;
47714+
47715+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
47716 if (ex.a_data + ex.a_bss > rlim)
47717 return -ENOMEM;
47718
47719@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
47720
47721 install_exec_creds(bprm);
47722
47723+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47724+ current->mm->pax_flags = 0UL;
47725+#endif
47726+
47727+#ifdef CONFIG_PAX_PAGEEXEC
47728+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
47729+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
47730+
47731+#ifdef CONFIG_PAX_EMUTRAMP
47732+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
47733+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
47734+#endif
47735+
47736+#ifdef CONFIG_PAX_MPROTECT
47737+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
47738+ current->mm->pax_flags |= MF_PAX_MPROTECT;
47739+#endif
47740+
47741+ }
47742+#endif
47743+
47744 if (N_MAGIC(ex) == OMAGIC) {
47745 unsigned long text_addr, map_size;
47746 loff_t pos;
47747@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
47748 }
47749
47750 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
47751- PROT_READ | PROT_WRITE | PROT_EXEC,
47752+ PROT_READ | PROT_WRITE,
47753 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
47754 fd_offset + ex.a_text);
47755 if (error != N_DATADDR(ex)) {
47756diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
47757index 0c42cdb..c4f1cf1 100644
47758--- a/fs/binfmt_elf.c
47759+++ b/fs/binfmt_elf.c
47760@@ -33,6 +33,7 @@
47761 #include <linux/elf.h>
47762 #include <linux/utsname.h>
47763 #include <linux/coredump.h>
47764+#include <linux/xattr.h>
47765 #include <asm/uaccess.h>
47766 #include <asm/param.h>
47767 #include <asm/page.h>
47768@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
47769 #define elf_core_dump NULL
47770 #endif
47771
47772+#ifdef CONFIG_PAX_MPROTECT
47773+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
47774+#endif
47775+
47776 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
47777 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
47778 #else
47779@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
47780 .load_binary = load_elf_binary,
47781 .load_shlib = load_elf_library,
47782 .core_dump = elf_core_dump,
47783+
47784+#ifdef CONFIG_PAX_MPROTECT
47785+ .handle_mprotect= elf_handle_mprotect,
47786+#endif
47787+
47788 .min_coredump = ELF_EXEC_PAGESIZE,
47789 };
47790
47791@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
47792
47793 static int set_brk(unsigned long start, unsigned long end)
47794 {
47795+ unsigned long e = end;
47796+
47797 start = ELF_PAGEALIGN(start);
47798 end = ELF_PAGEALIGN(end);
47799 if (end > start) {
47800@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
47801 if (BAD_ADDR(addr))
47802 return addr;
47803 }
47804- current->mm->start_brk = current->mm->brk = end;
47805+ current->mm->start_brk = current->mm->brk = e;
47806 return 0;
47807 }
47808
47809@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47810 elf_addr_t __user *u_rand_bytes;
47811 const char *k_platform = ELF_PLATFORM;
47812 const char *k_base_platform = ELF_BASE_PLATFORM;
47813- unsigned char k_rand_bytes[16];
47814+ u32 k_rand_bytes[4];
47815 int items;
47816 elf_addr_t *elf_info;
47817 int ei_index = 0;
47818 const struct cred *cred = current_cred();
47819 struct vm_area_struct *vma;
47820+ unsigned long saved_auxv[AT_VECTOR_SIZE];
47821
47822 /*
47823 * In some cases (e.g. Hyper-Threading), we want to avoid L1
47824@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47825 * Generate 16 random bytes for userspace PRNG seeding.
47826 */
47827 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
47828- u_rand_bytes = (elf_addr_t __user *)
47829- STACK_ALLOC(p, sizeof(k_rand_bytes));
47830+ srandom32(k_rand_bytes[0] ^ random32());
47831+ srandom32(k_rand_bytes[1] ^ random32());
47832+ srandom32(k_rand_bytes[2] ^ random32());
47833+ srandom32(k_rand_bytes[3] ^ random32());
47834+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
47835+ u_rand_bytes = (elf_addr_t __user *) p;
47836 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
47837 return -EFAULT;
47838
47839@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47840 return -EFAULT;
47841 current->mm->env_end = p;
47842
47843+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
47844+
47845 /* Put the elf_info on the stack in the right place. */
47846 sp = (elf_addr_t __user *)envp + 1;
47847- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
47848+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
47849 return -EFAULT;
47850 return 0;
47851 }
47852@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
47853 an ELF header */
47854
47855 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47856- struct file *interpreter, unsigned long *interp_map_addr,
47857- unsigned long no_base)
47858+ struct file *interpreter, unsigned long no_base)
47859 {
47860 struct elf_phdr *elf_phdata;
47861 struct elf_phdr *eppnt;
47862- unsigned long load_addr = 0;
47863+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
47864 int load_addr_set = 0;
47865 unsigned long last_bss = 0, elf_bss = 0;
47866- unsigned long error = ~0UL;
47867+ unsigned long error = -EINVAL;
47868 unsigned long total_size;
47869 int retval, i, size;
47870
47871@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47872 goto out_close;
47873 }
47874
47875+#ifdef CONFIG_PAX_SEGMEXEC
47876+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
47877+ pax_task_size = SEGMEXEC_TASK_SIZE;
47878+#endif
47879+
47880 eppnt = elf_phdata;
47881 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
47882 if (eppnt->p_type == PT_LOAD) {
47883@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47884 map_addr = elf_map(interpreter, load_addr + vaddr,
47885 eppnt, elf_prot, elf_type, total_size);
47886 total_size = 0;
47887- if (!*interp_map_addr)
47888- *interp_map_addr = map_addr;
47889 error = map_addr;
47890 if (BAD_ADDR(map_addr))
47891 goto out_close;
47892@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47893 k = load_addr + eppnt->p_vaddr;
47894 if (BAD_ADDR(k) ||
47895 eppnt->p_filesz > eppnt->p_memsz ||
47896- eppnt->p_memsz > TASK_SIZE ||
47897- TASK_SIZE - eppnt->p_memsz < k) {
47898+ eppnt->p_memsz > pax_task_size ||
47899+ pax_task_size - eppnt->p_memsz < k) {
47900 error = -ENOMEM;
47901 goto out_close;
47902 }
47903@@ -530,6 +551,315 @@ out:
47904 return error;
47905 }
47906
47907+#ifdef CONFIG_PAX_PT_PAX_FLAGS
47908+#ifdef CONFIG_PAX_SOFTMODE
47909+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
47910+{
47911+ unsigned long pax_flags = 0UL;
47912+
47913+#ifdef CONFIG_PAX_PAGEEXEC
47914+ if (elf_phdata->p_flags & PF_PAGEEXEC)
47915+ pax_flags |= MF_PAX_PAGEEXEC;
47916+#endif
47917+
47918+#ifdef CONFIG_PAX_SEGMEXEC
47919+ if (elf_phdata->p_flags & PF_SEGMEXEC)
47920+ pax_flags |= MF_PAX_SEGMEXEC;
47921+#endif
47922+
47923+#ifdef CONFIG_PAX_EMUTRAMP
47924+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
47925+ pax_flags |= MF_PAX_EMUTRAMP;
47926+#endif
47927+
47928+#ifdef CONFIG_PAX_MPROTECT
47929+ if (elf_phdata->p_flags & PF_MPROTECT)
47930+ pax_flags |= MF_PAX_MPROTECT;
47931+#endif
47932+
47933+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47934+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
47935+ pax_flags |= MF_PAX_RANDMMAP;
47936+#endif
47937+
47938+ return pax_flags;
47939+}
47940+#endif
47941+
47942+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
47943+{
47944+ unsigned long pax_flags = 0UL;
47945+
47946+#ifdef CONFIG_PAX_PAGEEXEC
47947+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
47948+ pax_flags |= MF_PAX_PAGEEXEC;
47949+#endif
47950+
47951+#ifdef CONFIG_PAX_SEGMEXEC
47952+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
47953+ pax_flags |= MF_PAX_SEGMEXEC;
47954+#endif
47955+
47956+#ifdef CONFIG_PAX_EMUTRAMP
47957+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
47958+ pax_flags |= MF_PAX_EMUTRAMP;
47959+#endif
47960+
47961+#ifdef CONFIG_PAX_MPROTECT
47962+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
47963+ pax_flags |= MF_PAX_MPROTECT;
47964+#endif
47965+
47966+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47967+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
47968+ pax_flags |= MF_PAX_RANDMMAP;
47969+#endif
47970+
47971+ return pax_flags;
47972+}
47973+#endif
47974+
47975+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
47976+#ifdef CONFIG_PAX_SOFTMODE
47977+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
47978+{
47979+ unsigned long pax_flags = 0UL;
47980+
47981+#ifdef CONFIG_PAX_PAGEEXEC
47982+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
47983+ pax_flags |= MF_PAX_PAGEEXEC;
47984+#endif
47985+
47986+#ifdef CONFIG_PAX_SEGMEXEC
47987+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
47988+ pax_flags |= MF_PAX_SEGMEXEC;
47989+#endif
47990+
47991+#ifdef CONFIG_PAX_EMUTRAMP
47992+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
47993+ pax_flags |= MF_PAX_EMUTRAMP;
47994+#endif
47995+
47996+#ifdef CONFIG_PAX_MPROTECT
47997+ if (pax_flags_softmode & MF_PAX_MPROTECT)
47998+ pax_flags |= MF_PAX_MPROTECT;
47999+#endif
48000+
48001+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48002+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48003+ pax_flags |= MF_PAX_RANDMMAP;
48004+#endif
48005+
48006+ return pax_flags;
48007+}
48008+#endif
48009+
48010+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48011+{
48012+ unsigned long pax_flags = 0UL;
48013+
48014+#ifdef CONFIG_PAX_PAGEEXEC
48015+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48016+ pax_flags |= MF_PAX_PAGEEXEC;
48017+#endif
48018+
48019+#ifdef CONFIG_PAX_SEGMEXEC
48020+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48021+ pax_flags |= MF_PAX_SEGMEXEC;
48022+#endif
48023+
48024+#ifdef CONFIG_PAX_EMUTRAMP
48025+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48026+ pax_flags |= MF_PAX_EMUTRAMP;
48027+#endif
48028+
48029+#ifdef CONFIG_PAX_MPROTECT
48030+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48031+ pax_flags |= MF_PAX_MPROTECT;
48032+#endif
48033+
48034+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48035+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48036+ pax_flags |= MF_PAX_RANDMMAP;
48037+#endif
48038+
48039+ return pax_flags;
48040+}
48041+#endif
48042+
48043+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48044+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48045+{
48046+ unsigned long pax_flags = 0UL;
48047+
48048+#ifdef CONFIG_PAX_EI_PAX
48049+
48050+#ifdef CONFIG_PAX_PAGEEXEC
48051+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48052+ pax_flags |= MF_PAX_PAGEEXEC;
48053+#endif
48054+
48055+#ifdef CONFIG_PAX_SEGMEXEC
48056+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48057+ pax_flags |= MF_PAX_SEGMEXEC;
48058+#endif
48059+
48060+#ifdef CONFIG_PAX_EMUTRAMP
48061+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48062+ pax_flags |= MF_PAX_EMUTRAMP;
48063+#endif
48064+
48065+#ifdef CONFIG_PAX_MPROTECT
48066+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48067+ pax_flags |= MF_PAX_MPROTECT;
48068+#endif
48069+
48070+#ifdef CONFIG_PAX_ASLR
48071+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48072+ pax_flags |= MF_PAX_RANDMMAP;
48073+#endif
48074+
48075+#else
48076+
48077+#ifdef CONFIG_PAX_PAGEEXEC
48078+ pax_flags |= MF_PAX_PAGEEXEC;
48079+#endif
48080+
48081+#ifdef CONFIG_PAX_SEGMEXEC
48082+ pax_flags |= MF_PAX_SEGMEXEC;
48083+#endif
48084+
48085+#ifdef CONFIG_PAX_MPROTECT
48086+ pax_flags |= MF_PAX_MPROTECT;
48087+#endif
48088+
48089+#ifdef CONFIG_PAX_RANDMMAP
48090+ if (randomize_va_space)
48091+ pax_flags |= MF_PAX_RANDMMAP;
48092+#endif
48093+
48094+#endif
48095+
48096+ return pax_flags;
48097+}
48098+
48099+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48100+{
48101+
48102+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48103+ unsigned long i;
48104+
48105+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48106+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48107+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48108+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48109+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48110+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48111+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48112+ return ~0UL;
48113+
48114+#ifdef CONFIG_PAX_SOFTMODE
48115+ if (pax_softmode)
48116+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48117+ else
48118+#endif
48119+
48120+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48121+ break;
48122+ }
48123+#endif
48124+
48125+ return ~0UL;
48126+}
48127+
48128+static unsigned long pax_parse_xattr_pax(struct file * const file)
48129+{
48130+
48131+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48132+ ssize_t xattr_size, i;
48133+ unsigned char xattr_value[5];
48134+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48135+
48136+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
48137+ if (xattr_size <= 0 || xattr_size > 5)
48138+ return ~0UL;
48139+
48140+ for (i = 0; i < xattr_size; i++)
48141+ switch (xattr_value[i]) {
48142+ default:
48143+ return ~0UL;
48144+
48145+#define parse_flag(option1, option2, flag) \
48146+ case option1: \
48147+ if (pax_flags_hardmode & MF_PAX_##flag) \
48148+ return ~0UL; \
48149+ pax_flags_hardmode |= MF_PAX_##flag; \
48150+ break; \
48151+ case option2: \
48152+ if (pax_flags_softmode & MF_PAX_##flag) \
48153+ return ~0UL; \
48154+ pax_flags_softmode |= MF_PAX_##flag; \
48155+ break;
48156+
48157+ parse_flag('p', 'P', PAGEEXEC);
48158+ parse_flag('e', 'E', EMUTRAMP);
48159+ parse_flag('m', 'M', MPROTECT);
48160+ parse_flag('r', 'R', RANDMMAP);
48161+ parse_flag('s', 'S', SEGMEXEC);
48162+
48163+#undef parse_flag
48164+ }
48165+
48166+ if (pax_flags_hardmode & pax_flags_softmode)
48167+ return ~0UL;
48168+
48169+#ifdef CONFIG_PAX_SOFTMODE
48170+ if (pax_softmode)
48171+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
48172+ else
48173+#endif
48174+
48175+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
48176+#else
48177+ return ~0UL;
48178+#endif
48179+
48180+}
48181+
48182+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
48183+{
48184+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
48185+
48186+ pax_flags = pax_parse_ei_pax(elf_ex);
48187+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
48188+ xattr_pax_flags = pax_parse_xattr_pax(file);
48189+
48190+ if (pt_pax_flags == ~0UL)
48191+ pt_pax_flags = xattr_pax_flags;
48192+ else if (xattr_pax_flags == ~0UL)
48193+ xattr_pax_flags = pt_pax_flags;
48194+ if (pt_pax_flags != xattr_pax_flags)
48195+ return -EINVAL;
48196+ if (pt_pax_flags != ~0UL)
48197+ pax_flags = pt_pax_flags;
48198+
48199+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
48200+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48201+ if ((__supported_pte_mask & _PAGE_NX))
48202+ pax_flags &= ~MF_PAX_SEGMEXEC;
48203+ else
48204+ pax_flags &= ~MF_PAX_PAGEEXEC;
48205+ }
48206+#endif
48207+
48208+ if (0 > pax_check_flags(&pax_flags))
48209+ return -EINVAL;
48210+
48211+ current->mm->pax_flags = pax_flags;
48212+ return 0;
48213+}
48214+#endif
48215+
48216 /*
48217 * These are the functions used to load ELF style executables and shared
48218 * libraries. There is no binary dependent code anywhere else.
48219@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
48220 {
48221 unsigned int random_variable = 0;
48222
48223+#ifdef CONFIG_PAX_RANDUSTACK
48224+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
48225+ return stack_top - current->mm->delta_stack;
48226+#endif
48227+
48228 if ((current->flags & PF_RANDOMIZE) &&
48229 !(current->personality & ADDR_NO_RANDOMIZE)) {
48230 random_variable = get_random_int() & STACK_RND_MASK;
48231@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
48232 unsigned long load_addr = 0, load_bias = 0;
48233 int load_addr_set = 0;
48234 char * elf_interpreter = NULL;
48235- unsigned long error;
48236+ unsigned long error = 0;
48237 struct elf_phdr *elf_ppnt, *elf_phdata;
48238 unsigned long elf_bss, elf_brk;
48239 int retval, i;
48240@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
48241 unsigned long start_code, end_code, start_data, end_data;
48242 unsigned long reloc_func_desc __maybe_unused = 0;
48243 int executable_stack = EXSTACK_DEFAULT;
48244- unsigned long def_flags = 0;
48245 struct pt_regs *regs = current_pt_regs();
48246 struct {
48247 struct elfhdr elf_ex;
48248 struct elfhdr interp_elf_ex;
48249 } *loc;
48250+ unsigned long pax_task_size = TASK_SIZE;
48251
48252 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
48253 if (!loc) {
48254@@ -715,11 +1050,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
48255 goto out_free_dentry;
48256
48257 /* OK, This is the point of no return */
48258- current->mm->def_flags = def_flags;
48259+
48260+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48261+ current->mm->pax_flags = 0UL;
48262+#endif
48263+
48264+#ifdef CONFIG_PAX_DLRESOLVE
48265+ current->mm->call_dl_resolve = 0UL;
48266+#endif
48267+
48268+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
48269+ current->mm->call_syscall = 0UL;
48270+#endif
48271+
48272+#ifdef CONFIG_PAX_ASLR
48273+ current->mm->delta_mmap = 0UL;
48274+ current->mm->delta_stack = 0UL;
48275+ current->mm->aslr_gap = 0UL;
48276+#endif
48277+
48278+ current->mm->def_flags = 0;
48279+
48280+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48281+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
48282+ send_sig(SIGKILL, current, 0);
48283+ goto out_free_dentry;
48284+ }
48285+#endif
48286+
48287+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
48288+ pax_set_initial_flags(bprm);
48289+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
48290+ if (pax_set_initial_flags_func)
48291+ (pax_set_initial_flags_func)(bprm);
48292+#endif
48293+
48294+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48295+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
48296+ current->mm->context.user_cs_limit = PAGE_SIZE;
48297+ current->mm->def_flags |= VM_PAGEEXEC;
48298+ }
48299+#endif
48300+
48301+#ifdef CONFIG_PAX_SEGMEXEC
48302+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
48303+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
48304+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
48305+ pax_task_size = SEGMEXEC_TASK_SIZE;
48306+ current->mm->def_flags |= VM_NOHUGEPAGE;
48307+ }
48308+#endif
48309+
48310+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
48311+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48312+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
48313+ put_cpu();
48314+ }
48315+#endif
48316
48317 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
48318 may depend on the personality. */
48319 SET_PERSONALITY(loc->elf_ex);
48320+
48321+#ifdef CONFIG_PAX_ASLR
48322+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48323+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
48324+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
48325+ }
48326+#endif
48327+
48328+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48329+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48330+ executable_stack = EXSTACK_DISABLE_X;
48331+ current->personality &= ~READ_IMPLIES_EXEC;
48332+ } else
48333+#endif
48334+
48335 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
48336 current->personality |= READ_IMPLIES_EXEC;
48337
48338@@ -810,6 +1216,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
48339 #else
48340 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
48341 #endif
48342+
48343+#ifdef CONFIG_PAX_RANDMMAP
48344+ /* PaX: randomize base address at the default exe base if requested */
48345+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
48346+#ifdef CONFIG_SPARC64
48347+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
48348+#else
48349+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
48350+#endif
48351+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
48352+ elf_flags |= MAP_FIXED;
48353+ }
48354+#endif
48355+
48356 }
48357
48358 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
48359@@ -842,9 +1262,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
48360 * allowed task size. Note that p_filesz must always be
48361 * <= p_memsz so it is only necessary to check p_memsz.
48362 */
48363- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48364- elf_ppnt->p_memsz > TASK_SIZE ||
48365- TASK_SIZE - elf_ppnt->p_memsz < k) {
48366+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48367+ elf_ppnt->p_memsz > pax_task_size ||
48368+ pax_task_size - elf_ppnt->p_memsz < k) {
48369 /* set_brk can never work. Avoid overflows. */
48370 send_sig(SIGKILL, current, 0);
48371 retval = -EINVAL;
48372@@ -883,17 +1303,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
48373 goto out_free_dentry;
48374 }
48375 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
48376- send_sig(SIGSEGV, current, 0);
48377- retval = -EFAULT; /* Nobody gets to see this, but.. */
48378- goto out_free_dentry;
48379+ /*
48380+ * This bss-zeroing can fail if the ELF
48381+ * file specifies odd protections. So
48382+ * we don't check the return value
48383+ */
48384 }
48385
48386+#ifdef CONFIG_PAX_RANDMMAP
48387+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48388+ unsigned long start, size;
48389+
48390+ start = ELF_PAGEALIGN(elf_brk);
48391+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
48392+ down_read(&current->mm->mmap_sem);
48393+ retval = -ENOMEM;
48394+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
48395+ unsigned long prot = PROT_NONE;
48396+
48397+ up_read(&current->mm->mmap_sem);
48398+// if (current->personality & ADDR_NO_RANDOMIZE)
48399+// prot = PROT_READ;
48400+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
48401+ retval = IS_ERR_VALUE(start) ? start : 0;
48402+ } else
48403+ up_read(&current->mm->mmap_sem);
48404+ if (retval == 0) {
48405+ current->mm->aslr_gap += PAGE_ALIGN(size) >> PAGE_SHIFT;
48406+ retval = set_brk(start + size, start + size + PAGE_SIZE);
48407+ }
48408+ if (retval < 0) {
48409+ send_sig(SIGKILL, current, 0);
48410+ goto out_free_dentry;
48411+ }
48412+ }
48413+#endif
48414+
48415 if (elf_interpreter) {
48416- unsigned long interp_map_addr = 0;
48417-
48418 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48419 interpreter,
48420- &interp_map_addr,
48421 load_bias);
48422 if (!IS_ERR((void *)elf_entry)) {
48423 /*
48424@@ -1115,7 +1563,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48425 * Decide what to dump of a segment, part, all or none.
48426 */
48427 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48428- unsigned long mm_flags)
48429+ unsigned long mm_flags, long signr)
48430 {
48431 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48432
48433@@ -1152,7 +1600,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48434 if (vma->vm_file == NULL)
48435 return 0;
48436
48437- if (FILTER(MAPPED_PRIVATE))
48438+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48439 goto whole;
48440
48441 /*
48442@@ -1374,9 +1822,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48443 {
48444 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48445 int i = 0;
48446- do
48447+ do {
48448 i += 2;
48449- while (auxv[i - 2] != AT_NULL);
48450+ } while (auxv[i - 2] != AT_NULL);
48451 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48452 }
48453
48454@@ -2006,14 +2454,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48455 }
48456
48457 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48458- unsigned long mm_flags)
48459+ struct coredump_params *cprm)
48460 {
48461 struct vm_area_struct *vma;
48462 size_t size = 0;
48463
48464 for (vma = first_vma(current, gate_vma); vma != NULL;
48465 vma = next_vma(vma, gate_vma))
48466- size += vma_dump_size(vma, mm_flags);
48467+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48468 return size;
48469 }
48470
48471@@ -2107,7 +2555,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48472
48473 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48474
48475- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48476+ offset += elf_core_vma_data_size(gate_vma, cprm);
48477 offset += elf_core_extra_data_size();
48478 e_shoff = offset;
48479
48480@@ -2121,10 +2569,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48481 offset = dataoff;
48482
48483 size += sizeof(*elf);
48484+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48485 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48486 goto end_coredump;
48487
48488 size += sizeof(*phdr4note);
48489+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48490 if (size > cprm->limit
48491 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48492 goto end_coredump;
48493@@ -2138,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48494 phdr.p_offset = offset;
48495 phdr.p_vaddr = vma->vm_start;
48496 phdr.p_paddr = 0;
48497- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48498+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48499 phdr.p_memsz = vma->vm_end - vma->vm_start;
48500 offset += phdr.p_filesz;
48501 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48502@@ -2149,6 +2599,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48503 phdr.p_align = ELF_EXEC_PAGESIZE;
48504
48505 size += sizeof(phdr);
48506+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48507 if (size > cprm->limit
48508 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48509 goto end_coredump;
48510@@ -2173,7 +2624,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48511 unsigned long addr;
48512 unsigned long end;
48513
48514- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48515+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48516
48517 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48518 struct page *page;
48519@@ -2182,6 +2633,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48520 page = get_dump_page(addr);
48521 if (page) {
48522 void *kaddr = kmap(page);
48523+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48524 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48525 !dump_write(cprm->file, kaddr,
48526 PAGE_SIZE);
48527@@ -2199,6 +2651,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48528
48529 if (e_phnum == PN_XNUM) {
48530 size += sizeof(*shdr4extnum);
48531+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48532 if (size > cprm->limit
48533 || !dump_write(cprm->file, shdr4extnum,
48534 sizeof(*shdr4extnum)))
48535@@ -2219,6 +2672,97 @@ out:
48536
48537 #endif /* CONFIG_ELF_CORE */
48538
48539+#ifdef CONFIG_PAX_MPROTECT
48540+/* PaX: non-PIC ELF libraries need relocations on their executable segments
48541+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48542+ * we'll remove VM_MAYWRITE for good on RELRO segments.
48543+ *
48544+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48545+ * basis because we want to allow the common case and not the special ones.
48546+ */
48547+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48548+{
48549+ struct elfhdr elf_h;
48550+ struct elf_phdr elf_p;
48551+ unsigned long i;
48552+ unsigned long oldflags;
48553+ bool is_textrel_rw, is_textrel_rx, is_relro;
48554+
48555+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48556+ return;
48557+
48558+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48559+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48560+
48561+#ifdef CONFIG_PAX_ELFRELOCS
48562+ /* possible TEXTREL */
48563+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48564+ 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);
48565+#else
48566+ is_textrel_rw = false;
48567+ is_textrel_rx = false;
48568+#endif
48569+
48570+ /* possible RELRO */
48571+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48572+
48573+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48574+ return;
48575+
48576+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48577+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48578+
48579+#ifdef CONFIG_PAX_ETEXECRELOCS
48580+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48581+#else
48582+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48583+#endif
48584+
48585+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48586+ !elf_check_arch(&elf_h) ||
48587+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48588+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48589+ return;
48590+
48591+ for (i = 0UL; i < elf_h.e_phnum; i++) {
48592+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48593+ return;
48594+ switch (elf_p.p_type) {
48595+ case PT_DYNAMIC:
48596+ if (!is_textrel_rw && !is_textrel_rx)
48597+ continue;
48598+ i = 0UL;
48599+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48600+ elf_dyn dyn;
48601+
48602+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48603+ return;
48604+ if (dyn.d_tag == DT_NULL)
48605+ return;
48606+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48607+ gr_log_textrel(vma);
48608+ if (is_textrel_rw)
48609+ vma->vm_flags |= VM_MAYWRITE;
48610+ else
48611+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48612+ vma->vm_flags &= ~VM_MAYWRITE;
48613+ return;
48614+ }
48615+ i++;
48616+ }
48617+ return;
48618+
48619+ case PT_GNU_RELRO:
48620+ if (!is_relro)
48621+ continue;
48622+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48623+ vma->vm_flags &= ~VM_MAYWRITE;
48624+ return;
48625+ }
48626+ }
48627+}
48628+#endif
48629+
48630 static int __init init_elf_binfmt(void)
48631 {
48632 register_binfmt(&elf_format);
48633diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48634index b563719..3868998 100644
48635--- a/fs/binfmt_flat.c
48636+++ b/fs/binfmt_flat.c
48637@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48638 realdatastart = (unsigned long) -ENOMEM;
48639 printk("Unable to allocate RAM for process data, errno %d\n",
48640 (int)-realdatastart);
48641+ down_write(&current->mm->mmap_sem);
48642 vm_munmap(textpos, text_len);
48643+ up_write(&current->mm->mmap_sem);
48644 ret = realdatastart;
48645 goto err;
48646 }
48647@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48648 }
48649 if (IS_ERR_VALUE(result)) {
48650 printk("Unable to read data+bss, errno %d\n", (int)-result);
48651+ down_write(&current->mm->mmap_sem);
48652 vm_munmap(textpos, text_len);
48653 vm_munmap(realdatastart, len);
48654+ up_write(&current->mm->mmap_sem);
48655 ret = result;
48656 goto err;
48657 }
48658@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48659 }
48660 if (IS_ERR_VALUE(result)) {
48661 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48662+ down_write(&current->mm->mmap_sem);
48663 vm_munmap(textpos, text_len + data_len + extra +
48664 MAX_SHARED_LIBS * sizeof(unsigned long));
48665+ up_write(&current->mm->mmap_sem);
48666 ret = result;
48667 goto err;
48668 }
48669diff --git a/fs/bio.c b/fs/bio.c
48670index b96fc6c..431d628 100644
48671--- a/fs/bio.c
48672+++ b/fs/bio.c
48673@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
48674 /*
48675 * Overflow, abort
48676 */
48677- if (end < start)
48678+ if (end < start || end - start > INT_MAX - nr_pages)
48679 return ERR_PTR(-EINVAL);
48680
48681 nr_pages += end - start;
48682@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
48683 /*
48684 * Overflow, abort
48685 */
48686- if (end < start)
48687+ if (end < start || end - start > INT_MAX - nr_pages)
48688 return ERR_PTR(-EINVAL);
48689
48690 nr_pages += end - start;
48691@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
48692 const int read = bio_data_dir(bio) == READ;
48693 struct bio_map_data *bmd = bio->bi_private;
48694 int i;
48695- char *p = bmd->sgvecs[0].iov_base;
48696+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
48697
48698 __bio_for_each_segment(bvec, bio, i, 0) {
48699 char *addr = page_address(bvec->bv_page);
48700diff --git a/fs/block_dev.c b/fs/block_dev.c
48701index 78333a3..23dcb4d 100644
48702--- a/fs/block_dev.c
48703+++ b/fs/block_dev.c
48704@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
48705 else if (bdev->bd_contains == bdev)
48706 return true; /* is a whole device which isn't held */
48707
48708- else if (whole->bd_holder == bd_may_claim)
48709+ else if (whole->bd_holder == (void *)bd_may_claim)
48710 return true; /* is a partition of a device that is being partitioned */
48711 else if (whole->bd_holder != NULL)
48712 return false; /* is a partition of a held device */
48713diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
48714index eea5da7..88fead70 100644
48715--- a/fs/btrfs/ctree.c
48716+++ b/fs/btrfs/ctree.c
48717@@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
48718 free_extent_buffer(buf);
48719 add_root_to_dirty_list(root);
48720 } else {
48721- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
48722- parent_start = parent->start;
48723- else
48724+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
48725+ if (parent)
48726+ parent_start = parent->start;
48727+ else
48728+ parent_start = 0;
48729+ } else
48730 parent_start = 0;
48731
48732 WARN_ON(trans->transid != btrfs_header_generation(parent));
48733diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
48734index 659ea81..0f63c1a 100644
48735--- a/fs/btrfs/inode.c
48736+++ b/fs/btrfs/inode.c
48737@@ -7300,7 +7300,7 @@ fail:
48738 return -ENOMEM;
48739 }
48740
48741-static int btrfs_getattr(struct vfsmount *mnt,
48742+int btrfs_getattr(struct vfsmount *mnt,
48743 struct dentry *dentry, struct kstat *stat)
48744 {
48745 struct inode *inode = dentry->d_inode;
48746@@ -7314,6 +7314,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
48747 return 0;
48748 }
48749
48750+EXPORT_SYMBOL(btrfs_getattr);
48751+
48752+dev_t get_btrfs_dev_from_inode(struct inode *inode)
48753+{
48754+ return BTRFS_I(inode)->root->anon_dev;
48755+}
48756+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
48757+
48758 /*
48759 * If a file is moved, it will inherit the cow and compression flags of the new
48760 * directory.
48761diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
48762index 338f259..b657640 100644
48763--- a/fs/btrfs/ioctl.c
48764+++ b/fs/btrfs/ioctl.c
48765@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48766 for (i = 0; i < num_types; i++) {
48767 struct btrfs_space_info *tmp;
48768
48769+ /* Don't copy in more than we allocated */
48770 if (!slot_count)
48771 break;
48772
48773+ slot_count--;
48774+
48775 info = NULL;
48776 rcu_read_lock();
48777 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
48778@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48779 memcpy(dest, &space, sizeof(space));
48780 dest++;
48781 space_args.total_spaces++;
48782- slot_count--;
48783 }
48784- if (!slot_count)
48785- break;
48786 }
48787 up_read(&info->groups_sem);
48788 }
48789diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
48790index 300e09a..9fe4539 100644
48791--- a/fs/btrfs/relocation.c
48792+++ b/fs/btrfs/relocation.c
48793@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
48794 }
48795 spin_unlock(&rc->reloc_root_tree.lock);
48796
48797- BUG_ON((struct btrfs_root *)node->data != root);
48798+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
48799
48800 if (!del) {
48801 spin_lock(&rc->reloc_root_tree.lock);
48802diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
48803index d8982e9..29a85fa 100644
48804--- a/fs/btrfs/super.c
48805+++ b/fs/btrfs/super.c
48806@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
48807 function, line, errstr);
48808 return;
48809 }
48810- ACCESS_ONCE(trans->transaction->aborted) = errno;
48811+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
48812 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
48813 }
48814 /*
48815diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
48816index 622f469..e8d2d55 100644
48817--- a/fs/cachefiles/bind.c
48818+++ b/fs/cachefiles/bind.c
48819@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
48820 args);
48821
48822 /* start by checking things over */
48823- ASSERT(cache->fstop_percent >= 0 &&
48824- cache->fstop_percent < cache->fcull_percent &&
48825+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
48826 cache->fcull_percent < cache->frun_percent &&
48827 cache->frun_percent < 100);
48828
48829- ASSERT(cache->bstop_percent >= 0 &&
48830- cache->bstop_percent < cache->bcull_percent &&
48831+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
48832 cache->bcull_percent < cache->brun_percent &&
48833 cache->brun_percent < 100);
48834
48835diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
48836index 0a1467b..6a53245 100644
48837--- a/fs/cachefiles/daemon.c
48838+++ b/fs/cachefiles/daemon.c
48839@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
48840 if (n > buflen)
48841 return -EMSGSIZE;
48842
48843- if (copy_to_user(_buffer, buffer, n) != 0)
48844+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
48845 return -EFAULT;
48846
48847 return n;
48848@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
48849 if (test_bit(CACHEFILES_DEAD, &cache->flags))
48850 return -EIO;
48851
48852- if (datalen < 0 || datalen > PAGE_SIZE - 1)
48853+ if (datalen > PAGE_SIZE - 1)
48854 return -EOPNOTSUPP;
48855
48856 /* drag the command string into the kernel so we can parse it */
48857@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
48858 if (args[0] != '%' || args[1] != '\0')
48859 return -EINVAL;
48860
48861- if (fstop < 0 || fstop >= cache->fcull_percent)
48862+ if (fstop >= cache->fcull_percent)
48863 return cachefiles_daemon_range_error(cache, args);
48864
48865 cache->fstop_percent = fstop;
48866@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
48867 if (args[0] != '%' || args[1] != '\0')
48868 return -EINVAL;
48869
48870- if (bstop < 0 || bstop >= cache->bcull_percent)
48871+ if (bstop >= cache->bcull_percent)
48872 return cachefiles_daemon_range_error(cache, args);
48873
48874 cache->bstop_percent = bstop;
48875diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
48876index 4938251..7e01445 100644
48877--- a/fs/cachefiles/internal.h
48878+++ b/fs/cachefiles/internal.h
48879@@ -59,7 +59,7 @@ struct cachefiles_cache {
48880 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
48881 struct rb_root active_nodes; /* active nodes (can't be culled) */
48882 rwlock_t active_lock; /* lock for active_nodes */
48883- atomic_t gravecounter; /* graveyard uniquifier */
48884+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
48885 unsigned frun_percent; /* when to stop culling (% files) */
48886 unsigned fcull_percent; /* when to start culling (% files) */
48887 unsigned fstop_percent; /* when to stop allocating (% files) */
48888@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
48889 * proc.c
48890 */
48891 #ifdef CONFIG_CACHEFILES_HISTOGRAM
48892-extern atomic_t cachefiles_lookup_histogram[HZ];
48893-extern atomic_t cachefiles_mkdir_histogram[HZ];
48894-extern atomic_t cachefiles_create_histogram[HZ];
48895+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48896+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48897+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
48898
48899 extern int __init cachefiles_proc_init(void);
48900 extern void cachefiles_proc_cleanup(void);
48901 static inline
48902-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
48903+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
48904 {
48905 unsigned long jif = jiffies - start_jif;
48906 if (jif >= HZ)
48907 jif = HZ - 1;
48908- atomic_inc(&histogram[jif]);
48909+ atomic_inc_unchecked(&histogram[jif]);
48910 }
48911
48912 #else
48913diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
48914index 8c01c5fc..15f982e 100644
48915--- a/fs/cachefiles/namei.c
48916+++ b/fs/cachefiles/namei.c
48917@@ -317,7 +317,7 @@ try_again:
48918 /* first step is to make up a grave dentry in the graveyard */
48919 sprintf(nbuffer, "%08x%08x",
48920 (uint32_t) get_seconds(),
48921- (uint32_t) atomic_inc_return(&cache->gravecounter));
48922+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
48923
48924 /* do the multiway lock magic */
48925 trap = lock_rename(cache->graveyard, dir);
48926diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
48927index eccd339..4c1d995 100644
48928--- a/fs/cachefiles/proc.c
48929+++ b/fs/cachefiles/proc.c
48930@@ -14,9 +14,9 @@
48931 #include <linux/seq_file.h>
48932 #include "internal.h"
48933
48934-atomic_t cachefiles_lookup_histogram[HZ];
48935-atomic_t cachefiles_mkdir_histogram[HZ];
48936-atomic_t cachefiles_create_histogram[HZ];
48937+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48938+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48939+atomic_unchecked_t cachefiles_create_histogram[HZ];
48940
48941 /*
48942 * display the latency histogram
48943@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
48944 return 0;
48945 default:
48946 index = (unsigned long) v - 3;
48947- x = atomic_read(&cachefiles_lookup_histogram[index]);
48948- y = atomic_read(&cachefiles_mkdir_histogram[index]);
48949- z = atomic_read(&cachefiles_create_histogram[index]);
48950+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
48951+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
48952+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
48953 if (x == 0 && y == 0 && z == 0)
48954 return 0;
48955
48956diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
48957index 4809922..aab2c39 100644
48958--- a/fs/cachefiles/rdwr.c
48959+++ b/fs/cachefiles/rdwr.c
48960@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
48961 old_fs = get_fs();
48962 set_fs(KERNEL_DS);
48963 ret = file->f_op->write(
48964- file, (const void __user *) data, len, &pos);
48965+ file, (const void __force_user *) data, len, &pos);
48966 set_fs(old_fs);
48967 kunmap(page);
48968 if (ret != len)
48969diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
48970index 8c1aabe..bbf856a 100644
48971--- a/fs/ceph/dir.c
48972+++ b/fs/ceph/dir.c
48973@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
48974 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
48975 struct ceph_mds_client *mdsc = fsc->mdsc;
48976 unsigned frag = fpos_frag(filp->f_pos);
48977- int off = fpos_off(filp->f_pos);
48978+ unsigned int off = fpos_off(filp->f_pos);
48979 int err;
48980 u32 ftype;
48981 struct ceph_mds_reply_info_parsed *rinfo;
48982diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
48983index d9ea6ed..1e6c8ac 100644
48984--- a/fs/cifs/cifs_debug.c
48985+++ b/fs/cifs/cifs_debug.c
48986@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48987
48988 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
48989 #ifdef CONFIG_CIFS_STATS2
48990- atomic_set(&totBufAllocCount, 0);
48991- atomic_set(&totSmBufAllocCount, 0);
48992+ atomic_set_unchecked(&totBufAllocCount, 0);
48993+ atomic_set_unchecked(&totSmBufAllocCount, 0);
48994 #endif /* CONFIG_CIFS_STATS2 */
48995 spin_lock(&cifs_tcp_ses_lock);
48996 list_for_each(tmp1, &cifs_tcp_ses_list) {
48997@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48998 tcon = list_entry(tmp3,
48999 struct cifs_tcon,
49000 tcon_list);
49001- atomic_set(&tcon->num_smbs_sent, 0);
49002+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49003 if (server->ops->clear_stats)
49004 server->ops->clear_stats(tcon);
49005 }
49006@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49007 smBufAllocCount.counter, cifs_min_small);
49008 #ifdef CONFIG_CIFS_STATS2
49009 seq_printf(m, "Total Large %d Small %d Allocations\n",
49010- atomic_read(&totBufAllocCount),
49011- atomic_read(&totSmBufAllocCount));
49012+ atomic_read_unchecked(&totBufAllocCount),
49013+ atomic_read_unchecked(&totSmBufAllocCount));
49014 #endif /* CONFIG_CIFS_STATS2 */
49015
49016 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49017@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49018 if (tcon->need_reconnect)
49019 seq_puts(m, "\tDISCONNECTED ");
49020 seq_printf(m, "\nSMBs: %d",
49021- atomic_read(&tcon->num_smbs_sent));
49022+ atomic_read_unchecked(&tcon->num_smbs_sent));
49023 if (server->ops->print_stats)
49024 server->ops->print_stats(m, tcon);
49025 }
49026diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49027index e328339..322228b 100644
49028--- a/fs/cifs/cifsfs.c
49029+++ b/fs/cifs/cifsfs.c
49030@@ -1002,7 +1002,7 @@ cifs_init_request_bufs(void)
49031 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49032 cifs_req_cachep = kmem_cache_create("cifs_request",
49033 CIFSMaxBufSize + max_hdr_size, 0,
49034- SLAB_HWCACHE_ALIGN, NULL);
49035+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49036 if (cifs_req_cachep == NULL)
49037 return -ENOMEM;
49038
49039@@ -1029,7 +1029,7 @@ cifs_init_request_bufs(void)
49040 efficient to alloc 1 per page off the slab compared to 17K (5page)
49041 alloc of large cifs buffers even when page debugging is on */
49042 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49043- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49044+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49045 NULL);
49046 if (cifs_sm_req_cachep == NULL) {
49047 mempool_destroy(cifs_req_poolp);
49048@@ -1114,8 +1114,8 @@ init_cifs(void)
49049 atomic_set(&bufAllocCount, 0);
49050 atomic_set(&smBufAllocCount, 0);
49051 #ifdef CONFIG_CIFS_STATS2
49052- atomic_set(&totBufAllocCount, 0);
49053- atomic_set(&totSmBufAllocCount, 0);
49054+ atomic_set_unchecked(&totBufAllocCount, 0);
49055+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49056 #endif /* CONFIG_CIFS_STATS2 */
49057
49058 atomic_set(&midCount, 0);
49059diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49060index e6899ce..d6b2920 100644
49061--- a/fs/cifs/cifsglob.h
49062+++ b/fs/cifs/cifsglob.h
49063@@ -751,35 +751,35 @@ struct cifs_tcon {
49064 __u16 Flags; /* optional support bits */
49065 enum statusEnum tidStatus;
49066 #ifdef CONFIG_CIFS_STATS
49067- atomic_t num_smbs_sent;
49068+ atomic_unchecked_t num_smbs_sent;
49069 union {
49070 struct {
49071- atomic_t num_writes;
49072- atomic_t num_reads;
49073- atomic_t num_flushes;
49074- atomic_t num_oplock_brks;
49075- atomic_t num_opens;
49076- atomic_t num_closes;
49077- atomic_t num_deletes;
49078- atomic_t num_mkdirs;
49079- atomic_t num_posixopens;
49080- atomic_t num_posixmkdirs;
49081- atomic_t num_rmdirs;
49082- atomic_t num_renames;
49083- atomic_t num_t2renames;
49084- atomic_t num_ffirst;
49085- atomic_t num_fnext;
49086- atomic_t num_fclose;
49087- atomic_t num_hardlinks;
49088- atomic_t num_symlinks;
49089- atomic_t num_locks;
49090- atomic_t num_acl_get;
49091- atomic_t num_acl_set;
49092+ atomic_unchecked_t num_writes;
49093+ atomic_unchecked_t num_reads;
49094+ atomic_unchecked_t num_flushes;
49095+ atomic_unchecked_t num_oplock_brks;
49096+ atomic_unchecked_t num_opens;
49097+ atomic_unchecked_t num_closes;
49098+ atomic_unchecked_t num_deletes;
49099+ atomic_unchecked_t num_mkdirs;
49100+ atomic_unchecked_t num_posixopens;
49101+ atomic_unchecked_t num_posixmkdirs;
49102+ atomic_unchecked_t num_rmdirs;
49103+ atomic_unchecked_t num_renames;
49104+ atomic_unchecked_t num_t2renames;
49105+ atomic_unchecked_t num_ffirst;
49106+ atomic_unchecked_t num_fnext;
49107+ atomic_unchecked_t num_fclose;
49108+ atomic_unchecked_t num_hardlinks;
49109+ atomic_unchecked_t num_symlinks;
49110+ atomic_unchecked_t num_locks;
49111+ atomic_unchecked_t num_acl_get;
49112+ atomic_unchecked_t num_acl_set;
49113 } cifs_stats;
49114 #ifdef CONFIG_CIFS_SMB2
49115 struct {
49116- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49117- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49118+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49119+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49120 } smb2_stats;
49121 #endif /* CONFIG_CIFS_SMB2 */
49122 } stats;
49123@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49124 }
49125
49126 #ifdef CONFIG_CIFS_STATS
49127-#define cifs_stats_inc atomic_inc
49128+#define cifs_stats_inc atomic_inc_unchecked
49129
49130 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49131 unsigned int bytes)
49132@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49133 /* Various Debug counters */
49134 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49135 #ifdef CONFIG_CIFS_STATS2
49136-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49137-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49138+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49139+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49140 #endif
49141 GLOBAL_EXTERN atomic_t smBufAllocCount;
49142 GLOBAL_EXTERN atomic_t midCount;
49143diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49144index 51dc2fb..1e12a33 100644
49145--- a/fs/cifs/link.c
49146+++ b/fs/cifs/link.c
49147@@ -616,7 +616,7 @@ symlink_exit:
49148
49149 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49150 {
49151- char *p = nd_get_link(nd);
49152+ const char *p = nd_get_link(nd);
49153 if (!IS_ERR(p))
49154 kfree(p);
49155 }
49156diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49157index 3a00c0d..42d901c 100644
49158--- a/fs/cifs/misc.c
49159+++ b/fs/cifs/misc.c
49160@@ -169,7 +169,7 @@ cifs_buf_get(void)
49161 memset(ret_buf, 0, buf_size + 3);
49162 atomic_inc(&bufAllocCount);
49163 #ifdef CONFIG_CIFS_STATS2
49164- atomic_inc(&totBufAllocCount);
49165+ atomic_inc_unchecked(&totBufAllocCount);
49166 #endif /* CONFIG_CIFS_STATS2 */
49167 }
49168
49169@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49170 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49171 atomic_inc(&smBufAllocCount);
49172 #ifdef CONFIG_CIFS_STATS2
49173- atomic_inc(&totSmBufAllocCount);
49174+ atomic_inc_unchecked(&totSmBufAllocCount);
49175 #endif /* CONFIG_CIFS_STATS2 */
49176
49177 }
49178diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
49179index 47bc5a8..10decbe 100644
49180--- a/fs/cifs/smb1ops.c
49181+++ b/fs/cifs/smb1ops.c
49182@@ -586,27 +586,27 @@ static void
49183 cifs_clear_stats(struct cifs_tcon *tcon)
49184 {
49185 #ifdef CONFIG_CIFS_STATS
49186- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
49187- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
49188- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
49189- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49190- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
49191- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
49192- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49193- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
49194- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
49195- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
49196- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
49197- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
49198- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
49199- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
49200- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
49201- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
49202- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
49203- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
49204- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
49205- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
49206- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
49207+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
49208+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
49209+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
49210+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49211+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
49212+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
49213+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49214+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
49215+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
49216+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
49217+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
49218+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
49219+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
49220+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
49221+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
49222+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
49223+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
49224+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
49225+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
49226+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
49227+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
49228 #endif
49229 }
49230
49231@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49232 {
49233 #ifdef CONFIG_CIFS_STATS
49234 seq_printf(m, " Oplocks breaks: %d",
49235- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
49236+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
49237 seq_printf(m, "\nReads: %d Bytes: %llu",
49238- atomic_read(&tcon->stats.cifs_stats.num_reads),
49239+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
49240 (long long)(tcon->bytes_read));
49241 seq_printf(m, "\nWrites: %d Bytes: %llu",
49242- atomic_read(&tcon->stats.cifs_stats.num_writes),
49243+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
49244 (long long)(tcon->bytes_written));
49245 seq_printf(m, "\nFlushes: %d",
49246- atomic_read(&tcon->stats.cifs_stats.num_flushes));
49247+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
49248 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
49249- atomic_read(&tcon->stats.cifs_stats.num_locks),
49250- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
49251- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
49252+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
49253+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
49254+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
49255 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
49256- atomic_read(&tcon->stats.cifs_stats.num_opens),
49257- atomic_read(&tcon->stats.cifs_stats.num_closes),
49258- atomic_read(&tcon->stats.cifs_stats.num_deletes));
49259+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
49260+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
49261+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
49262 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
49263- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
49264- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
49265+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
49266+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
49267 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
49268- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
49269- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
49270+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
49271+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
49272 seq_printf(m, "\nRenames: %d T2 Renames %d",
49273- atomic_read(&tcon->stats.cifs_stats.num_renames),
49274- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
49275+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
49276+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
49277 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
49278- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
49279- atomic_read(&tcon->stats.cifs_stats.num_fnext),
49280- atomic_read(&tcon->stats.cifs_stats.num_fclose));
49281+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
49282+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
49283+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
49284 #endif
49285 }
49286
49287diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
49288index bceffe7..cd1ae59 100644
49289--- a/fs/cifs/smb2ops.c
49290+++ b/fs/cifs/smb2ops.c
49291@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
49292 #ifdef CONFIG_CIFS_STATS
49293 int i;
49294 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
49295- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49296- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49297+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49298+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49299 }
49300 #endif
49301 }
49302@@ -284,66 +284,66 @@ static void
49303 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49304 {
49305 #ifdef CONFIG_CIFS_STATS
49306- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49307- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49308+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49309+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49310 seq_printf(m, "\nNegotiates: %d sent %d failed",
49311- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
49312- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
49313+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
49314+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
49315 seq_printf(m, "\nSessionSetups: %d sent %d failed",
49316- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
49317- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
49318+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
49319+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
49320 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
49321 seq_printf(m, "\nLogoffs: %d sent %d failed",
49322- atomic_read(&sent[SMB2_LOGOFF_HE]),
49323- atomic_read(&failed[SMB2_LOGOFF_HE]));
49324+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
49325+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
49326 seq_printf(m, "\nTreeConnects: %d sent %d failed",
49327- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
49328- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
49329+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
49330+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
49331 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
49332- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
49333- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
49334+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
49335+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
49336 seq_printf(m, "\nCreates: %d sent %d failed",
49337- atomic_read(&sent[SMB2_CREATE_HE]),
49338- atomic_read(&failed[SMB2_CREATE_HE]));
49339+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
49340+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
49341 seq_printf(m, "\nCloses: %d sent %d failed",
49342- atomic_read(&sent[SMB2_CLOSE_HE]),
49343- atomic_read(&failed[SMB2_CLOSE_HE]));
49344+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
49345+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
49346 seq_printf(m, "\nFlushes: %d sent %d failed",
49347- atomic_read(&sent[SMB2_FLUSH_HE]),
49348- atomic_read(&failed[SMB2_FLUSH_HE]));
49349+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
49350+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
49351 seq_printf(m, "\nReads: %d sent %d failed",
49352- atomic_read(&sent[SMB2_READ_HE]),
49353- atomic_read(&failed[SMB2_READ_HE]));
49354+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
49355+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
49356 seq_printf(m, "\nWrites: %d sent %d failed",
49357- atomic_read(&sent[SMB2_WRITE_HE]),
49358- atomic_read(&failed[SMB2_WRITE_HE]));
49359+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
49360+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
49361 seq_printf(m, "\nLocks: %d sent %d failed",
49362- atomic_read(&sent[SMB2_LOCK_HE]),
49363- atomic_read(&failed[SMB2_LOCK_HE]));
49364+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
49365+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
49366 seq_printf(m, "\nIOCTLs: %d sent %d failed",
49367- atomic_read(&sent[SMB2_IOCTL_HE]),
49368- atomic_read(&failed[SMB2_IOCTL_HE]));
49369+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
49370+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
49371 seq_printf(m, "\nCancels: %d sent %d failed",
49372- atomic_read(&sent[SMB2_CANCEL_HE]),
49373- atomic_read(&failed[SMB2_CANCEL_HE]));
49374+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
49375+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
49376 seq_printf(m, "\nEchos: %d sent %d failed",
49377- atomic_read(&sent[SMB2_ECHO_HE]),
49378- atomic_read(&failed[SMB2_ECHO_HE]));
49379+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
49380+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
49381 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
49382- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
49383- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
49384+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
49385+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
49386 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
49387- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
49388- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
49389+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
49390+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
49391 seq_printf(m, "\nQueryInfos: %d sent %d failed",
49392- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
49393- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
49394+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
49395+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
49396 seq_printf(m, "\nSetInfos: %d sent %d failed",
49397- atomic_read(&sent[SMB2_SET_INFO_HE]),
49398- atomic_read(&failed[SMB2_SET_INFO_HE]));
49399+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49400+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49401 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49402- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49403- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49404+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49405+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49406 #endif
49407 }
49408
49409diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49410index 41d9d07..dbb4772 100644
49411--- a/fs/cifs/smb2pdu.c
49412+++ b/fs/cifs/smb2pdu.c
49413@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49414 default:
49415 cERROR(1, "info level %u isn't supported",
49416 srch_inf->info_level);
49417- rc = -EINVAL;
49418- goto qdir_exit;
49419+ return -EINVAL;
49420 }
49421
49422 req->FileIndex = cpu_to_le32(index);
49423diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49424index 958ae0e..505c9d0 100644
49425--- a/fs/coda/cache.c
49426+++ b/fs/coda/cache.c
49427@@ -24,7 +24,7 @@
49428 #include "coda_linux.h"
49429 #include "coda_cache.h"
49430
49431-static atomic_t permission_epoch = ATOMIC_INIT(0);
49432+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49433
49434 /* replace or extend an acl cache hit */
49435 void coda_cache_enter(struct inode *inode, int mask)
49436@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49437 struct coda_inode_info *cii = ITOC(inode);
49438
49439 spin_lock(&cii->c_lock);
49440- cii->c_cached_epoch = atomic_read(&permission_epoch);
49441+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49442 if (cii->c_uid != current_fsuid()) {
49443 cii->c_uid = current_fsuid();
49444 cii->c_cached_perm = mask;
49445@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49446 {
49447 struct coda_inode_info *cii = ITOC(inode);
49448 spin_lock(&cii->c_lock);
49449- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49450+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49451 spin_unlock(&cii->c_lock);
49452 }
49453
49454 /* remove all acl caches */
49455 void coda_cache_clear_all(struct super_block *sb)
49456 {
49457- atomic_inc(&permission_epoch);
49458+ atomic_inc_unchecked(&permission_epoch);
49459 }
49460
49461
49462@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49463 spin_lock(&cii->c_lock);
49464 hit = (mask & cii->c_cached_perm) == mask &&
49465 cii->c_uid == current_fsuid() &&
49466- cii->c_cached_epoch == atomic_read(&permission_epoch);
49467+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49468 spin_unlock(&cii->c_lock);
49469
49470 return hit;
49471diff --git a/fs/compat.c b/fs/compat.c
49472index a06dcbc..dacb6d3 100644
49473--- a/fs/compat.c
49474+++ b/fs/compat.c
49475@@ -54,7 +54,7 @@
49476 #include <asm/ioctls.h>
49477 #include "internal.h"
49478
49479-int compat_log = 1;
49480+int compat_log = 0;
49481
49482 int compat_printk(const char *fmt, ...)
49483 {
49484@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49485
49486 set_fs(KERNEL_DS);
49487 /* The __user pointer cast is valid because of the set_fs() */
49488- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49489+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49490 set_fs(oldfs);
49491 /* truncating is ok because it's a user address */
49492 if (!ret)
49493@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49494 goto out;
49495
49496 ret = -EINVAL;
49497- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49498+ if (nr_segs > UIO_MAXIOV)
49499 goto out;
49500 if (nr_segs > fast_segs) {
49501 ret = -ENOMEM;
49502@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
49503
49504 struct compat_readdir_callback {
49505 struct compat_old_linux_dirent __user *dirent;
49506+ struct file * file;
49507 int result;
49508 };
49509
49510@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49511 buf->result = -EOVERFLOW;
49512 return -EOVERFLOW;
49513 }
49514+
49515+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49516+ return 0;
49517+
49518 buf->result++;
49519 dirent = buf->dirent;
49520 if (!access_ok(VERIFY_WRITE, dirent,
49521@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49522
49523 buf.result = 0;
49524 buf.dirent = dirent;
49525+ buf.file = f.file;
49526
49527 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49528 if (buf.result)
49529@@ -901,6 +907,7 @@ struct compat_linux_dirent {
49530 struct compat_getdents_callback {
49531 struct compat_linux_dirent __user *current_dir;
49532 struct compat_linux_dirent __user *previous;
49533+ struct file * file;
49534 int count;
49535 int error;
49536 };
49537@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49538 buf->error = -EOVERFLOW;
49539 return -EOVERFLOW;
49540 }
49541+
49542+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49543+ return 0;
49544+
49545 dirent = buf->previous;
49546 if (dirent) {
49547 if (__put_user(offset, &dirent->d_off))
49548@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49549 buf.previous = NULL;
49550 buf.count = count;
49551 buf.error = 0;
49552+ buf.file = f.file;
49553
49554 error = vfs_readdir(f.file, compat_filldir, &buf);
49555 if (error >= 0)
49556@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49557 struct compat_getdents_callback64 {
49558 struct linux_dirent64 __user *current_dir;
49559 struct linux_dirent64 __user *previous;
49560+ struct file * file;
49561 int count;
49562 int error;
49563 };
49564@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49565 buf->error = -EINVAL; /* only used if we fail.. */
49566 if (reclen > buf->count)
49567 return -EINVAL;
49568+
49569+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49570+ return 0;
49571+
49572 dirent = buf->previous;
49573
49574 if (dirent) {
49575@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49576 buf.previous = NULL;
49577 buf.count = count;
49578 buf.error = 0;
49579+ buf.file = f.file;
49580
49581 error = vfs_readdir(f.file, compat_filldir64, &buf);
49582 if (error >= 0)
49583 error = buf.error;
49584 lastdirent = buf.previous;
49585 if (lastdirent) {
49586- typeof(lastdirent->d_off) d_off = f.file->f_pos;
49587+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49588 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49589 error = -EFAULT;
49590 else
49591diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49592index a81147e..20bf2b5 100644
49593--- a/fs/compat_binfmt_elf.c
49594+++ b/fs/compat_binfmt_elf.c
49595@@ -30,11 +30,13 @@
49596 #undef elf_phdr
49597 #undef elf_shdr
49598 #undef elf_note
49599+#undef elf_dyn
49600 #undef elf_addr_t
49601 #define elfhdr elf32_hdr
49602 #define elf_phdr elf32_phdr
49603 #define elf_shdr elf32_shdr
49604 #define elf_note elf32_note
49605+#define elf_dyn Elf32_Dyn
49606 #define elf_addr_t Elf32_Addr
49607
49608 /*
49609diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49610index e2f57a0..3c78771 100644
49611--- a/fs/compat_ioctl.c
49612+++ b/fs/compat_ioctl.c
49613@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49614 return -EFAULT;
49615 if (__get_user(udata, &ss32->iomem_base))
49616 return -EFAULT;
49617- ss.iomem_base = compat_ptr(udata);
49618+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49619 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49620 __get_user(ss.port_high, &ss32->port_high))
49621 return -EFAULT;
49622@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49623 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49624 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49625 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49626- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49627+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49628 return -EFAULT;
49629
49630 return ioctl_preallocate(file, p);
49631@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49632 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49633 {
49634 unsigned int a, b;
49635- a = *(unsigned int *)p;
49636- b = *(unsigned int *)q;
49637+ a = *(const unsigned int *)p;
49638+ b = *(const unsigned int *)q;
49639 if (a > b)
49640 return 1;
49641 if (a < b)
49642diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49643index 712b10f..c33c4ca 100644
49644--- a/fs/configfs/dir.c
49645+++ b/fs/configfs/dir.c
49646@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
49647 static int configfs_depend_prep(struct dentry *origin,
49648 struct config_item *target)
49649 {
49650- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
49651+ struct configfs_dirent *child_sd, *sd;
49652 int ret = 0;
49653
49654- BUG_ON(!origin || !sd);
49655+ BUG_ON(!origin || !origin->d_fsdata);
49656+ sd = origin->d_fsdata;
49657
49658 if (sd->s_element == target) /* Boo-yah */
49659 goto out;
49660@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49661 }
49662 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49663 struct configfs_dirent *next;
49664- const char * name;
49665+ const unsigned char * name;
49666+ char d_name[sizeof(next->s_dentry->d_iname)];
49667 int len;
49668 struct inode *inode = NULL;
49669
49670@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49671 continue;
49672
49673 name = configfs_get_name(next);
49674- len = strlen(name);
49675+ if (next->s_dentry && name == next->s_dentry->d_iname) {
49676+ len = next->s_dentry->d_name.len;
49677+ memcpy(d_name, name, len);
49678+ name = d_name;
49679+ } else
49680+ len = strlen(name);
49681
49682 /*
49683 * We'll have a dentry and an inode for
49684diff --git a/fs/coredump.c b/fs/coredump.c
49685index 1774932..5812106 100644
49686--- a/fs/coredump.c
49687+++ b/fs/coredump.c
49688@@ -52,7 +52,7 @@ struct core_name {
49689 char *corename;
49690 int used, size;
49691 };
49692-static atomic_t call_count = ATOMIC_INIT(1);
49693+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49694
49695 /* The maximal length of core_pattern is also specified in sysctl.c */
49696
49697@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49698 {
49699 char *old_corename = cn->corename;
49700
49701- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49702+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49703 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49704
49705 if (!cn->corename) {
49706@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49707 int pid_in_pattern = 0;
49708 int err = 0;
49709
49710- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49711+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49712 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49713 cn->used = 0;
49714
49715@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49716 pipe = file->f_path.dentry->d_inode->i_pipe;
49717
49718 pipe_lock(pipe);
49719- pipe->readers++;
49720- pipe->writers--;
49721+ atomic_inc(&pipe->readers);
49722+ atomic_dec(&pipe->writers);
49723
49724- while ((pipe->readers > 1) && (!signal_pending(current))) {
49725+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
49726 wake_up_interruptible_sync(&pipe->wait);
49727 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49728 pipe_wait(pipe);
49729 }
49730
49731- pipe->readers--;
49732- pipe->writers++;
49733+ atomic_dec(&pipe->readers);
49734+ atomic_inc(&pipe->writers);
49735 pipe_unlock(pipe);
49736
49737 }
49738@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
49739 int ispipe;
49740 struct files_struct *displaced;
49741 bool need_nonrelative = false;
49742- static atomic_t core_dump_count = ATOMIC_INIT(0);
49743+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
49744+ long signr = siginfo->si_signo;
49745 struct coredump_params cprm = {
49746 .siginfo = siginfo,
49747 .regs = signal_pt_regs(),
49748@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
49749 .mm_flags = mm->flags,
49750 };
49751
49752- audit_core_dumps(siginfo->si_signo);
49753+ audit_core_dumps(signr);
49754+
49755+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
49756+ gr_handle_brute_attach(cprm.mm_flags);
49757
49758 binfmt = mm->binfmt;
49759 if (!binfmt || !binfmt->core_dump)
49760@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
49761 need_nonrelative = true;
49762 }
49763
49764- retval = coredump_wait(siginfo->si_signo, &core_state);
49765+ retval = coredump_wait(signr, &core_state);
49766 if (retval < 0)
49767 goto fail_creds;
49768
49769@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
49770 }
49771 cprm.limit = RLIM_INFINITY;
49772
49773- dump_count = atomic_inc_return(&core_dump_count);
49774+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
49775 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
49776 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
49777 task_tgid_vnr(current), current->comm);
49778@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
49779 } else {
49780 struct inode *inode;
49781
49782+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
49783+
49784 if (cprm.limit < binfmt->min_coredump)
49785 goto fail_unlock;
49786
49787@@ -640,7 +646,7 @@ close_fail:
49788 filp_close(cprm.file, NULL);
49789 fail_dropcount:
49790 if (ispipe)
49791- atomic_dec(&core_dump_count);
49792+ atomic_dec_unchecked(&core_dump_count);
49793 fail_unlock:
49794 kfree(cn.corename);
49795 fail_corename:
49796@@ -659,7 +665,7 @@ fail:
49797 */
49798 int dump_write(struct file *file, const void *addr, int nr)
49799 {
49800- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
49801+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
49802 }
49803 EXPORT_SYMBOL(dump_write);
49804
49805diff --git a/fs/dcache.c b/fs/dcache.c
49806index 19153a0..428c2f5 100644
49807--- a/fs/dcache.c
49808+++ b/fs/dcache.c
49809@@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
49810 mempages -= reserve;
49811
49812 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
49813- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
49814+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
49815
49816 dcache_init();
49817 inode_init();
49818diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
49819index a5f12b7..4ee8a6f 100644
49820--- a/fs/debugfs/inode.c
49821+++ b/fs/debugfs/inode.c
49822@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
49823 */
49824 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
49825 {
49826+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49827+ return __create_file(name, S_IFDIR | S_IRWXU,
49828+#else
49829 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49830+#endif
49831 parent, NULL, NULL);
49832 }
49833 EXPORT_SYMBOL_GPL(debugfs_create_dir);
49834diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
49835index cc7709e..7e7211f 100644
49836--- a/fs/ecryptfs/inode.c
49837+++ b/fs/ecryptfs/inode.c
49838@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
49839 old_fs = get_fs();
49840 set_fs(get_ds());
49841 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
49842- (char __user *)lower_buf,
49843+ (char __force_user *)lower_buf,
49844 PATH_MAX);
49845 set_fs(old_fs);
49846 if (rc < 0)
49847@@ -706,7 +706,7 @@ out:
49848 static void
49849 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
49850 {
49851- char *buf = nd_get_link(nd);
49852+ const char *buf = nd_get_link(nd);
49853 if (!IS_ERR(buf)) {
49854 /* Free the char* */
49855 kfree(buf);
49856diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
49857index 412e6ed..4292d22 100644
49858--- a/fs/ecryptfs/miscdev.c
49859+++ b/fs/ecryptfs/miscdev.c
49860@@ -315,7 +315,7 @@ check_list:
49861 goto out_unlock_msg_ctx;
49862 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
49863 if (msg_ctx->msg) {
49864- if (copy_to_user(&buf[i], packet_length, packet_length_size))
49865+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
49866 goto out_unlock_msg_ctx;
49867 i += packet_length_size;
49868 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
49869diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
49870index b2a34a1..162fa69 100644
49871--- a/fs/ecryptfs/read_write.c
49872+++ b/fs/ecryptfs/read_write.c
49873@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
49874 return -EIO;
49875 fs_save = get_fs();
49876 set_fs(get_ds());
49877- rc = vfs_write(lower_file, data, size, &offset);
49878+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
49879 set_fs(fs_save);
49880 mark_inode_dirty_sync(ecryptfs_inode);
49881 return rc;
49882@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
49883 return -EIO;
49884 fs_save = get_fs();
49885 set_fs(get_ds());
49886- rc = vfs_read(lower_file, data, size, &offset);
49887+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
49888 set_fs(fs_save);
49889 return rc;
49890 }
49891diff --git a/fs/exec.c b/fs/exec.c
49892index 20df02c..860e87f 100644
49893--- a/fs/exec.c
49894+++ b/fs/exec.c
49895@@ -55,6 +55,17 @@
49896 #include <linux/pipe_fs_i.h>
49897 #include <linux/oom.h>
49898 #include <linux/compat.h>
49899+#include <linux/random.h>
49900+#include <linux/seq_file.h>
49901+#include <linux/coredump.h>
49902+#include <linux/mman.h>
49903+
49904+#ifdef CONFIG_PAX_REFCOUNT
49905+#include <linux/kallsyms.h>
49906+#include <linux/kdebug.h>
49907+#endif
49908+
49909+#include <trace/events/fs.h>
49910
49911 #include <asm/uaccess.h>
49912 #include <asm/mmu_context.h>
49913@@ -66,6 +77,18 @@
49914
49915 #include <trace/events/sched.h>
49916
49917+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49918+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
49919+{
49920+ 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");
49921+}
49922+#endif
49923+
49924+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
49925+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
49926+EXPORT_SYMBOL(pax_set_initial_flags_func);
49927+#endif
49928+
49929 int suid_dumpable = 0;
49930
49931 static LIST_HEAD(formats);
49932@@ -75,8 +98,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
49933 {
49934 BUG_ON(!fmt);
49935 write_lock(&binfmt_lock);
49936- insert ? list_add(&fmt->lh, &formats) :
49937- list_add_tail(&fmt->lh, &formats);
49938+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
49939+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
49940 write_unlock(&binfmt_lock);
49941 }
49942
49943@@ -85,7 +108,7 @@ EXPORT_SYMBOL(__register_binfmt);
49944 void unregister_binfmt(struct linux_binfmt * fmt)
49945 {
49946 write_lock(&binfmt_lock);
49947- list_del(&fmt->lh);
49948+ pax_list_del((struct list_head *)&fmt->lh);
49949 write_unlock(&binfmt_lock);
49950 }
49951
49952@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49953 int write)
49954 {
49955 struct page *page;
49956- int ret;
49957
49958-#ifdef CONFIG_STACK_GROWSUP
49959- if (write) {
49960- ret = expand_downwards(bprm->vma, pos);
49961- if (ret < 0)
49962- return NULL;
49963- }
49964-#endif
49965- ret = get_user_pages(current, bprm->mm, pos,
49966- 1, write, 1, &page, NULL);
49967- if (ret <= 0)
49968+ if (0 > expand_downwards(bprm->vma, pos))
49969+ return NULL;
49970+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
49971 return NULL;
49972
49973 if (write) {
49974@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49975 if (size <= ARG_MAX)
49976 return page;
49977
49978+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49979+ // only allow 512KB for argv+env on suid/sgid binaries
49980+ // to prevent easy ASLR exhaustion
49981+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
49982+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
49983+ (size > (512 * 1024))) {
49984+ put_page(page);
49985+ return NULL;
49986+ }
49987+#endif
49988+
49989 /*
49990 * Limit to 1/4-th the stack size for the argv+env strings.
49991 * This ensures that:
49992@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49993 vma->vm_end = STACK_TOP_MAX;
49994 vma->vm_start = vma->vm_end - PAGE_SIZE;
49995 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
49996+
49997+#ifdef CONFIG_PAX_SEGMEXEC
49998+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
49999+#endif
50000+
50001 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50002 INIT_LIST_HEAD(&vma->anon_vma_chain);
50003
50004@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50005 mm->stack_vm = mm->total_vm = 1;
50006 up_write(&mm->mmap_sem);
50007 bprm->p = vma->vm_end - sizeof(void *);
50008+
50009+#ifdef CONFIG_PAX_RANDUSTACK
50010+ if (randomize_va_space)
50011+ bprm->p ^= random32() & ~PAGE_MASK;
50012+#endif
50013+
50014 return 0;
50015 err:
50016 up_write(&mm->mmap_sem);
50017@@ -396,7 +433,7 @@ struct user_arg_ptr {
50018 } ptr;
50019 };
50020
50021-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50022+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50023 {
50024 const char __user *native;
50025
50026@@ -405,14 +442,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50027 compat_uptr_t compat;
50028
50029 if (get_user(compat, argv.ptr.compat + nr))
50030- return ERR_PTR(-EFAULT);
50031+ return (const char __force_user *)ERR_PTR(-EFAULT);
50032
50033 return compat_ptr(compat);
50034 }
50035 #endif
50036
50037 if (get_user(native, argv.ptr.native + nr))
50038- return ERR_PTR(-EFAULT);
50039+ return (const char __force_user *)ERR_PTR(-EFAULT);
50040
50041 return native;
50042 }
50043@@ -431,7 +468,7 @@ static int count(struct user_arg_ptr argv, int max)
50044 if (!p)
50045 break;
50046
50047- if (IS_ERR(p))
50048+ if (IS_ERR((const char __force_kernel *)p))
50049 return -EFAULT;
50050
50051 if (i >= max)
50052@@ -466,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50053
50054 ret = -EFAULT;
50055 str = get_user_arg_ptr(argv, argc);
50056- if (IS_ERR(str))
50057+ if (IS_ERR((const char __force_kernel *)str))
50058 goto out;
50059
50060 len = strnlen_user(str, MAX_ARG_STRLEN);
50061@@ -548,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50062 int r;
50063 mm_segment_t oldfs = get_fs();
50064 struct user_arg_ptr argv = {
50065- .ptr.native = (const char __user *const __user *)__argv,
50066+ .ptr.native = (const char __force_user *const __force_user *)__argv,
50067 };
50068
50069 set_fs(KERNEL_DS);
50070@@ -583,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50071 unsigned long new_end = old_end - shift;
50072 struct mmu_gather tlb;
50073
50074- BUG_ON(new_start > new_end);
50075+ if (new_start >= new_end || new_start < mmap_min_addr)
50076+ return -ENOMEM;
50077
50078 /*
50079 * ensure there are no vmas between where we want to go
50080@@ -592,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50081 if (vma != find_vma(mm, new_start))
50082 return -EFAULT;
50083
50084+#ifdef CONFIG_PAX_SEGMEXEC
50085+ BUG_ON(pax_find_mirror_vma(vma));
50086+#endif
50087+
50088 /*
50089 * cover the whole range: [new_start, old_end)
50090 */
50091@@ -672,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50092 stack_top = arch_align_stack(stack_top);
50093 stack_top = PAGE_ALIGN(stack_top);
50094
50095- if (unlikely(stack_top < mmap_min_addr) ||
50096- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50097- return -ENOMEM;
50098-
50099 stack_shift = vma->vm_end - stack_top;
50100
50101 bprm->p -= stack_shift;
50102@@ -687,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50103 bprm->exec -= stack_shift;
50104
50105 down_write(&mm->mmap_sem);
50106+
50107+ /* Move stack pages down in memory. */
50108+ if (stack_shift) {
50109+ ret = shift_arg_pages(vma, stack_shift);
50110+ if (ret)
50111+ goto out_unlock;
50112+ }
50113+
50114 vm_flags = VM_STACK_FLAGS;
50115
50116+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50117+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50118+ vm_flags &= ~VM_EXEC;
50119+
50120+#ifdef CONFIG_PAX_MPROTECT
50121+ if (mm->pax_flags & MF_PAX_MPROTECT)
50122+ vm_flags &= ~VM_MAYEXEC;
50123+#endif
50124+
50125+ }
50126+#endif
50127+
50128 /*
50129 * Adjust stack execute permissions; explicitly enable for
50130 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50131@@ -707,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50132 goto out_unlock;
50133 BUG_ON(prev != vma);
50134
50135- /* Move stack pages down in memory. */
50136- if (stack_shift) {
50137- ret = shift_arg_pages(vma, stack_shift);
50138- if (ret)
50139- goto out_unlock;
50140- }
50141-
50142 /* mprotect_fixup is overkill to remove the temporary stack flags */
50143 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50144
50145@@ -737,6 +788,30 @@ int setup_arg_pages(struct linux_binprm *bprm,
50146 #endif
50147 current->mm->start_stack = bprm->p;
50148 ret = expand_stack(vma, stack_base);
50149+
50150+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
50151+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50152+ unsigned long size, flags, vm_flags;
50153+
50154+ size = STACK_TOP - vma->vm_end;
50155+ flags = MAP_FIXED | MAP_PRIVATE;
50156+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50157+
50158+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
50159+
50160+#ifdef CONFIG_X86
50161+ if (!ret) {
50162+ current->mm->aslr_gap += size >> PAGE_SHIFT;
50163+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50164+ ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
50165+ if (!ret)
50166+ current->mm->aslr_gap += size >> PAGE_SHIFT;
50167+ }
50168+#endif
50169+
50170+ }
50171+#endif
50172+
50173 if (ret)
50174 ret = -EFAULT;
50175
50176@@ -772,6 +847,8 @@ struct file *open_exec(const char *name)
50177
50178 fsnotify_open(file);
50179
50180+ trace_open_exec(name);
50181+
50182 err = deny_write_access(file);
50183 if (err)
50184 goto exit;
50185@@ -795,7 +872,7 @@ int kernel_read(struct file *file, loff_t offset,
50186 old_fs = get_fs();
50187 set_fs(get_ds());
50188 /* The cast to a user pointer is valid due to the set_fs() */
50189- result = vfs_read(file, (void __user *)addr, count, &pos);
50190+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
50191 set_fs(old_fs);
50192 return result;
50193 }
50194@@ -1247,7 +1324,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
50195 }
50196 rcu_read_unlock();
50197
50198- if (p->fs->users > n_fs) {
50199+ if (atomic_read(&p->fs->users) > n_fs) {
50200 bprm->unsafe |= LSM_UNSAFE_SHARE;
50201 } else {
50202 res = -EAGAIN;
50203@@ -1447,6 +1524,31 @@ int search_binary_handler(struct linux_binprm *bprm)
50204
50205 EXPORT_SYMBOL(search_binary_handler);
50206
50207+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50208+static DEFINE_PER_CPU(u64, exec_counter);
50209+static int __init init_exec_counters(void)
50210+{
50211+ unsigned int cpu;
50212+
50213+ for_each_possible_cpu(cpu) {
50214+ per_cpu(exec_counter, cpu) = (u64)cpu;
50215+ }
50216+
50217+ return 0;
50218+}
50219+early_initcall(init_exec_counters);
50220+static inline void increment_exec_counter(void)
50221+{
50222+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
50223+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
50224+}
50225+#else
50226+static inline void increment_exec_counter(void) {}
50227+#endif
50228+
50229+extern void gr_handle_exec_args(struct linux_binprm *bprm,
50230+ struct user_arg_ptr argv);
50231+
50232 /*
50233 * sys_execve() executes a new program.
50234 */
50235@@ -1454,6 +1556,11 @@ static int do_execve_common(const char *filename,
50236 struct user_arg_ptr argv,
50237 struct user_arg_ptr envp)
50238 {
50239+#ifdef CONFIG_GRKERNSEC
50240+ struct file *old_exec_file;
50241+ struct acl_subject_label *old_acl;
50242+ struct rlimit old_rlim[RLIM_NLIMITS];
50243+#endif
50244 struct linux_binprm *bprm;
50245 struct file *file;
50246 struct files_struct *displaced;
50247@@ -1461,6 +1568,8 @@ static int do_execve_common(const char *filename,
50248 int retval;
50249 const struct cred *cred = current_cred();
50250
50251+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
50252+
50253 /*
50254 * We move the actual failure in case of RLIMIT_NPROC excess from
50255 * set*uid() to execve() because too many poorly written programs
50256@@ -1501,12 +1610,27 @@ static int do_execve_common(const char *filename,
50257 if (IS_ERR(file))
50258 goto out_unmark;
50259
50260+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
50261+ retval = -EPERM;
50262+ goto out_file;
50263+ }
50264+
50265 sched_exec();
50266
50267 bprm->file = file;
50268 bprm->filename = filename;
50269 bprm->interp = filename;
50270
50271+ if (gr_process_user_ban()) {
50272+ retval = -EPERM;
50273+ goto out_file;
50274+ }
50275+
50276+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
50277+ retval = -EACCES;
50278+ goto out_file;
50279+ }
50280+
50281 retval = bprm_mm_init(bprm);
50282 if (retval)
50283 goto out_file;
50284@@ -1523,24 +1647,65 @@ static int do_execve_common(const char *filename,
50285 if (retval < 0)
50286 goto out;
50287
50288+#ifdef CONFIG_GRKERNSEC
50289+ old_acl = current->acl;
50290+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
50291+ old_exec_file = current->exec_file;
50292+ get_file(file);
50293+ current->exec_file = file;
50294+#endif
50295+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50296+ /* limit suid stack to 8MB
50297+ * we saved the old limits above and will restore them if this exec fails
50298+ */
50299+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
50300+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
50301+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
50302+#endif
50303+
50304+ if (!gr_tpe_allow(file)) {
50305+ retval = -EACCES;
50306+ goto out_fail;
50307+ }
50308+
50309+ if (gr_check_crash_exec(file)) {
50310+ retval = -EACCES;
50311+ goto out_fail;
50312+ }
50313+
50314+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
50315+ bprm->unsafe);
50316+ if (retval < 0)
50317+ goto out_fail;
50318+
50319 retval = copy_strings_kernel(1, &bprm->filename, bprm);
50320 if (retval < 0)
50321- goto out;
50322+ goto out_fail;
50323
50324 bprm->exec = bprm->p;
50325 retval = copy_strings(bprm->envc, envp, bprm);
50326 if (retval < 0)
50327- goto out;
50328+ goto out_fail;
50329
50330 retval = copy_strings(bprm->argc, argv, bprm);
50331 if (retval < 0)
50332- goto out;
50333+ goto out_fail;
50334+
50335+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
50336+
50337+ gr_handle_exec_args(bprm, argv);
50338
50339 retval = search_binary_handler(bprm);
50340 if (retval < 0)
50341- goto out;
50342+ goto out_fail;
50343+#ifdef CONFIG_GRKERNSEC
50344+ if (old_exec_file)
50345+ fput(old_exec_file);
50346+#endif
50347
50348 /* execve succeeded */
50349+
50350+ increment_exec_counter();
50351 current->fs->in_exec = 0;
50352 current->in_execve = 0;
50353 acct_update_integrals(current);
50354@@ -1549,6 +1714,14 @@ static int do_execve_common(const char *filename,
50355 put_files_struct(displaced);
50356 return retval;
50357
50358+out_fail:
50359+#ifdef CONFIG_GRKERNSEC
50360+ current->acl = old_acl;
50361+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
50362+ fput(current->exec_file);
50363+ current->exec_file = old_exec_file;
50364+#endif
50365+
50366 out:
50367 if (bprm->mm) {
50368 acct_arg_size(bprm, 0);
50369@@ -1697,3 +1870,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
50370 return error;
50371 }
50372 #endif
50373+
50374+int pax_check_flags(unsigned long *flags)
50375+{
50376+ int retval = 0;
50377+
50378+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
50379+ if (*flags & MF_PAX_SEGMEXEC)
50380+ {
50381+ *flags &= ~MF_PAX_SEGMEXEC;
50382+ retval = -EINVAL;
50383+ }
50384+#endif
50385+
50386+ if ((*flags & MF_PAX_PAGEEXEC)
50387+
50388+#ifdef CONFIG_PAX_PAGEEXEC
50389+ && (*flags & MF_PAX_SEGMEXEC)
50390+#endif
50391+
50392+ )
50393+ {
50394+ *flags &= ~MF_PAX_PAGEEXEC;
50395+ retval = -EINVAL;
50396+ }
50397+
50398+ if ((*flags & MF_PAX_MPROTECT)
50399+
50400+#ifdef CONFIG_PAX_MPROTECT
50401+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50402+#endif
50403+
50404+ )
50405+ {
50406+ *flags &= ~MF_PAX_MPROTECT;
50407+ retval = -EINVAL;
50408+ }
50409+
50410+ if ((*flags & MF_PAX_EMUTRAMP)
50411+
50412+#ifdef CONFIG_PAX_EMUTRAMP
50413+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50414+#endif
50415+
50416+ )
50417+ {
50418+ *flags &= ~MF_PAX_EMUTRAMP;
50419+ retval = -EINVAL;
50420+ }
50421+
50422+ return retval;
50423+}
50424+
50425+EXPORT_SYMBOL(pax_check_flags);
50426+
50427+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50428+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50429+{
50430+ struct task_struct *tsk = current;
50431+ struct mm_struct *mm = current->mm;
50432+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50433+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50434+ char *path_exec = NULL;
50435+ char *path_fault = NULL;
50436+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
50437+ siginfo_t info = { };
50438+
50439+ if (buffer_exec && buffer_fault) {
50440+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50441+
50442+ down_read(&mm->mmap_sem);
50443+ vma = mm->mmap;
50444+ while (vma && (!vma_exec || !vma_fault)) {
50445+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50446+ vma_exec = vma;
50447+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50448+ vma_fault = vma;
50449+ vma = vma->vm_next;
50450+ }
50451+ if (vma_exec) {
50452+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50453+ if (IS_ERR(path_exec))
50454+ path_exec = "<path too long>";
50455+ else {
50456+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50457+ if (path_exec) {
50458+ *path_exec = 0;
50459+ path_exec = buffer_exec;
50460+ } else
50461+ path_exec = "<path too long>";
50462+ }
50463+ }
50464+ if (vma_fault) {
50465+ start = vma_fault->vm_start;
50466+ end = vma_fault->vm_end;
50467+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50468+ if (vma_fault->vm_file) {
50469+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50470+ if (IS_ERR(path_fault))
50471+ path_fault = "<path too long>";
50472+ else {
50473+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50474+ if (path_fault) {
50475+ *path_fault = 0;
50476+ path_fault = buffer_fault;
50477+ } else
50478+ path_fault = "<path too long>";
50479+ }
50480+ } else
50481+ path_fault = "<anonymous mapping>";
50482+ }
50483+ up_read(&mm->mmap_sem);
50484+ }
50485+ if (tsk->signal->curr_ip)
50486+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50487+ else
50488+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50489+ 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),
50490+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
50491+ free_page((unsigned long)buffer_exec);
50492+ free_page((unsigned long)buffer_fault);
50493+ pax_report_insns(regs, pc, sp);
50494+ info.si_signo = SIGKILL;
50495+ info.si_errno = 0;
50496+ info.si_code = SI_KERNEL;
50497+ info.si_pid = 0;
50498+ info.si_uid = 0;
50499+ do_coredump(&info);
50500+}
50501+#endif
50502+
50503+#ifdef CONFIG_PAX_REFCOUNT
50504+void pax_report_refcount_overflow(struct pt_regs *regs)
50505+{
50506+ if (current->signal->curr_ip)
50507+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50508+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
50509+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50510+ else
50511+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50512+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50513+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50514+ show_regs(regs);
50515+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50516+}
50517+#endif
50518+
50519+#ifdef CONFIG_PAX_USERCOPY
50520+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50521+static noinline int check_stack_object(const void *obj, unsigned long len)
50522+{
50523+ const void * const stack = task_stack_page(current);
50524+ const void * const stackend = stack + THREAD_SIZE;
50525+
50526+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50527+ const void *frame = NULL;
50528+ const void *oldframe;
50529+#endif
50530+
50531+ if (obj + len < obj)
50532+ return -1;
50533+
50534+ if (obj + len <= stack || stackend <= obj)
50535+ return 0;
50536+
50537+ if (obj < stack || stackend < obj + len)
50538+ return -1;
50539+
50540+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50541+ oldframe = __builtin_frame_address(1);
50542+ if (oldframe)
50543+ frame = __builtin_frame_address(2);
50544+ /*
50545+ low ----------------------------------------------> high
50546+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
50547+ ^----------------^
50548+ allow copies only within here
50549+ */
50550+ while (stack <= frame && frame < stackend) {
50551+ /* if obj + len extends past the last frame, this
50552+ check won't pass and the next frame will be 0,
50553+ causing us to bail out and correctly report
50554+ the copy as invalid
50555+ */
50556+ if (obj + len <= frame)
50557+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50558+ oldframe = frame;
50559+ frame = *(const void * const *)frame;
50560+ }
50561+ return -1;
50562+#else
50563+ return 1;
50564+#endif
50565+}
50566+
50567+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
50568+{
50569+ if (current->signal->curr_ip)
50570+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50571+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50572+ else
50573+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50574+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50575+ dump_stack();
50576+ gr_handle_kernel_exploit();
50577+ do_group_exit(SIGKILL);
50578+}
50579+#endif
50580+
50581+void __check_object_size(const void *ptr, unsigned long n, bool to)
50582+{
50583+
50584+#ifdef CONFIG_PAX_USERCOPY
50585+ const char *type;
50586+
50587+ if (!n)
50588+ return;
50589+
50590+ type = check_heap_object(ptr, n);
50591+ if (!type) {
50592+ if (check_stack_object(ptr, n) != -1)
50593+ return;
50594+ type = "<process stack>";
50595+ }
50596+
50597+ pax_report_usercopy(ptr, n, to, type);
50598+#endif
50599+
50600+}
50601+EXPORT_SYMBOL(__check_object_size);
50602+
50603+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50604+void pax_track_stack(void)
50605+{
50606+ unsigned long sp = (unsigned long)&sp;
50607+ if (sp < current_thread_info()->lowest_stack &&
50608+ sp > (unsigned long)task_stack_page(current))
50609+ current_thread_info()->lowest_stack = sp;
50610+}
50611+EXPORT_SYMBOL(pax_track_stack);
50612+#endif
50613+
50614+#ifdef CONFIG_PAX_SIZE_OVERFLOW
50615+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50616+{
50617+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50618+ dump_stack();
50619+ do_group_exit(SIGKILL);
50620+}
50621+EXPORT_SYMBOL(report_size_overflow);
50622+#endif
50623diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50624index 2616d0e..2ffdec9 100644
50625--- a/fs/ext2/balloc.c
50626+++ b/fs/ext2/balloc.c
50627@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50628
50629 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50630 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50631- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50632+ if (free_blocks < root_blocks + 1 &&
50633 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50634 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50635- !in_group_p (sbi->s_resgid))) {
50636+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50637 return 0;
50638 }
50639 return 1;
50640diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50641index 22548f5..41521d8 100644
50642--- a/fs/ext3/balloc.c
50643+++ b/fs/ext3/balloc.c
50644@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50645
50646 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50647 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50648- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50649+ if (free_blocks < root_blocks + 1 &&
50650 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50651 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50652- !in_group_p (sbi->s_resgid))) {
50653+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50654 return 0;
50655 }
50656 return 1;
50657diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50658index 92e68b3..115d987 100644
50659--- a/fs/ext4/balloc.c
50660+++ b/fs/ext4/balloc.c
50661@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50662 /* Hm, nope. Are (enough) root reserved clusters available? */
50663 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50664 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50665- capable(CAP_SYS_RESOURCE) ||
50666- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50667+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50668+ capable_nolog(CAP_SYS_RESOURCE)) {
50669
50670 if (free_clusters >= (nclusters + dirty_clusters))
50671 return 1;
50672diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50673index 8462eb3..4a71af6 100644
50674--- a/fs/ext4/ext4.h
50675+++ b/fs/ext4/ext4.h
50676@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
50677 unsigned long s_mb_last_start;
50678
50679 /* stats for buddy allocator */
50680- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50681- atomic_t s_bal_success; /* we found long enough chunks */
50682- atomic_t s_bal_allocated; /* in blocks */
50683- atomic_t s_bal_ex_scanned; /* total extents scanned */
50684- atomic_t s_bal_goals; /* goal hits */
50685- atomic_t s_bal_breaks; /* too long searches */
50686- atomic_t s_bal_2orders; /* 2^order hits */
50687+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50688+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50689+ atomic_unchecked_t s_bal_allocated; /* in blocks */
50690+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50691+ atomic_unchecked_t s_bal_goals; /* goal hits */
50692+ atomic_unchecked_t s_bal_breaks; /* too long searches */
50693+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50694 spinlock_t s_bal_lock;
50695 unsigned long s_mb_buddies_generated;
50696 unsigned long long s_mb_generation_time;
50697- atomic_t s_mb_lost_chunks;
50698- atomic_t s_mb_preallocated;
50699- atomic_t s_mb_discarded;
50700+ atomic_unchecked_t s_mb_lost_chunks;
50701+ atomic_unchecked_t s_mb_preallocated;
50702+ atomic_unchecked_t s_mb_discarded;
50703 atomic_t s_lock_busy;
50704
50705 /* locality groups */
50706diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
50707index 28bbf9b..75ca7c1 100644
50708--- a/fs/ext4/mballoc.c
50709+++ b/fs/ext4/mballoc.c
50710@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
50711 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
50712
50713 if (EXT4_SB(sb)->s_mb_stats)
50714- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
50715+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
50716
50717 break;
50718 }
50719@@ -2044,7 +2044,7 @@ repeat:
50720 ac->ac_status = AC_STATUS_CONTINUE;
50721 ac->ac_flags |= EXT4_MB_HINT_FIRST;
50722 cr = 3;
50723- atomic_inc(&sbi->s_mb_lost_chunks);
50724+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
50725 goto repeat;
50726 }
50727 }
50728@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
50729 if (sbi->s_mb_stats) {
50730 ext4_msg(sb, KERN_INFO,
50731 "mballoc: %u blocks %u reqs (%u success)",
50732- atomic_read(&sbi->s_bal_allocated),
50733- atomic_read(&sbi->s_bal_reqs),
50734- atomic_read(&sbi->s_bal_success));
50735+ atomic_read_unchecked(&sbi->s_bal_allocated),
50736+ atomic_read_unchecked(&sbi->s_bal_reqs),
50737+ atomic_read_unchecked(&sbi->s_bal_success));
50738 ext4_msg(sb, KERN_INFO,
50739 "mballoc: %u extents scanned, %u goal hits, "
50740 "%u 2^N hits, %u breaks, %u lost",
50741- atomic_read(&sbi->s_bal_ex_scanned),
50742- atomic_read(&sbi->s_bal_goals),
50743- atomic_read(&sbi->s_bal_2orders),
50744- atomic_read(&sbi->s_bal_breaks),
50745- atomic_read(&sbi->s_mb_lost_chunks));
50746+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
50747+ atomic_read_unchecked(&sbi->s_bal_goals),
50748+ atomic_read_unchecked(&sbi->s_bal_2orders),
50749+ atomic_read_unchecked(&sbi->s_bal_breaks),
50750+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
50751 ext4_msg(sb, KERN_INFO,
50752 "mballoc: %lu generated and it took %Lu",
50753 sbi->s_mb_buddies_generated,
50754 sbi->s_mb_generation_time);
50755 ext4_msg(sb, KERN_INFO,
50756 "mballoc: %u preallocated, %u discarded",
50757- atomic_read(&sbi->s_mb_preallocated),
50758- atomic_read(&sbi->s_mb_discarded));
50759+ atomic_read_unchecked(&sbi->s_mb_preallocated),
50760+ atomic_read_unchecked(&sbi->s_mb_discarded));
50761 }
50762
50763 free_percpu(sbi->s_locality_groups);
50764@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
50765 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
50766
50767 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
50768- atomic_inc(&sbi->s_bal_reqs);
50769- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50770+ atomic_inc_unchecked(&sbi->s_bal_reqs);
50771+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50772 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
50773- atomic_inc(&sbi->s_bal_success);
50774- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
50775+ atomic_inc_unchecked(&sbi->s_bal_success);
50776+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
50777 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
50778 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
50779- atomic_inc(&sbi->s_bal_goals);
50780+ atomic_inc_unchecked(&sbi->s_bal_goals);
50781 if (ac->ac_found > sbi->s_mb_max_to_scan)
50782- atomic_inc(&sbi->s_bal_breaks);
50783+ atomic_inc_unchecked(&sbi->s_bal_breaks);
50784 }
50785
50786 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
50787@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
50788 trace_ext4_mb_new_inode_pa(ac, pa);
50789
50790 ext4_mb_use_inode_pa(ac, pa);
50791- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
50792+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
50793
50794 ei = EXT4_I(ac->ac_inode);
50795 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50796@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
50797 trace_ext4_mb_new_group_pa(ac, pa);
50798
50799 ext4_mb_use_group_pa(ac, pa);
50800- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50801+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50802
50803 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50804 lg = ac->ac_lg;
50805@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
50806 * from the bitmap and continue.
50807 */
50808 }
50809- atomic_add(free, &sbi->s_mb_discarded);
50810+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
50811
50812 return err;
50813 }
50814@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
50815 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
50816 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
50817 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
50818- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50819+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50820 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
50821
50822 return 0;
50823diff --git a/fs/ext4/super.c b/fs/ext4/super.c
50824index 5fa223d..12fa738 100644
50825--- a/fs/ext4/super.c
50826+++ b/fs/ext4/super.c
50827@@ -2429,7 +2429,7 @@ struct ext4_attr {
50828 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
50829 const char *, size_t);
50830 int offset;
50831-};
50832+} __do_const;
50833
50834 static int parse_strtoul(const char *buf,
50835 unsigned long max, unsigned long *value)
50836diff --git a/fs/fcntl.c b/fs/fcntl.c
50837index 71a600a..20d87b1 100644
50838--- a/fs/fcntl.c
50839+++ b/fs/fcntl.c
50840@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
50841 if (err)
50842 return err;
50843
50844+ if (gr_handle_chroot_fowner(pid, type))
50845+ return -ENOENT;
50846+ if (gr_check_protected_task_fowner(pid, type))
50847+ return -EACCES;
50848+
50849 f_modown(filp, pid, type, force);
50850 return 0;
50851 }
50852diff --git a/fs/fhandle.c b/fs/fhandle.c
50853index 999ff5c..41f4109 100644
50854--- a/fs/fhandle.c
50855+++ b/fs/fhandle.c
50856@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
50857 } else
50858 retval = 0;
50859 /* copy the mount id */
50860- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
50861- sizeof(*mnt_id)) ||
50862+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
50863 copy_to_user(ufh, handle,
50864 sizeof(struct file_handle) + handle_bytes))
50865 retval = -EFAULT;
50866diff --git a/fs/fifo.c b/fs/fifo.c
50867index cf6f434..3d7942c 100644
50868--- a/fs/fifo.c
50869+++ b/fs/fifo.c
50870@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
50871 */
50872 filp->f_op = &read_pipefifo_fops;
50873 pipe->r_counter++;
50874- if (pipe->readers++ == 0)
50875+ if (atomic_inc_return(&pipe->readers) == 1)
50876 wake_up_partner(inode);
50877
50878- if (!pipe->writers) {
50879+ if (!atomic_read(&pipe->writers)) {
50880 if ((filp->f_flags & O_NONBLOCK)) {
50881 /* suppress POLLHUP until we have
50882 * seen a writer */
50883@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
50884 * errno=ENXIO when there is no process reading the FIFO.
50885 */
50886 ret = -ENXIO;
50887- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
50888+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
50889 goto err;
50890
50891 filp->f_op = &write_pipefifo_fops;
50892 pipe->w_counter++;
50893- if (!pipe->writers++)
50894+ if (atomic_inc_return(&pipe->writers) == 1)
50895 wake_up_partner(inode);
50896
50897- if (!pipe->readers) {
50898+ if (!atomic_read(&pipe->readers)) {
50899 if (wait_for_partner(inode, &pipe->r_counter))
50900 goto err_wr;
50901 }
50902@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
50903 */
50904 filp->f_op = &rdwr_pipefifo_fops;
50905
50906- pipe->readers++;
50907- pipe->writers++;
50908+ atomic_inc(&pipe->readers);
50909+ atomic_inc(&pipe->writers);
50910 pipe->r_counter++;
50911 pipe->w_counter++;
50912- if (pipe->readers == 1 || pipe->writers == 1)
50913+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
50914 wake_up_partner(inode);
50915 break;
50916
50917@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
50918 return 0;
50919
50920 err_rd:
50921- if (!--pipe->readers)
50922+ if (atomic_dec_and_test(&pipe->readers))
50923 wake_up_interruptible(&pipe->wait);
50924 ret = -ERESTARTSYS;
50925 goto err;
50926
50927 err_wr:
50928- if (!--pipe->writers)
50929+ if (atomic_dec_and_test(&pipe->writers))
50930 wake_up_interruptible(&pipe->wait);
50931 ret = -ERESTARTSYS;
50932 goto err;
50933
50934 err:
50935- if (!pipe->readers && !pipe->writers)
50936+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
50937 free_pipe_info(inode);
50938
50939 err_nocleanup:
50940diff --git a/fs/file.c b/fs/file.c
50941index 2b3570b..c57924b 100644
50942--- a/fs/file.c
50943+++ b/fs/file.c
50944@@ -16,6 +16,7 @@
50945 #include <linux/slab.h>
50946 #include <linux/vmalloc.h>
50947 #include <linux/file.h>
50948+#include <linux/security.h>
50949 #include <linux/fdtable.h>
50950 #include <linux/bitops.h>
50951 #include <linux/interrupt.h>
50952@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
50953 if (!file)
50954 return __close_fd(files, fd);
50955
50956+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
50957 if (fd >= rlimit(RLIMIT_NOFILE))
50958 return -EBADF;
50959
50960@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
50961 if (unlikely(oldfd == newfd))
50962 return -EINVAL;
50963
50964+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
50965 if (newfd >= rlimit(RLIMIT_NOFILE))
50966 return -EBADF;
50967
50968@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
50969 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
50970 {
50971 int err;
50972+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
50973 if (from >= rlimit(RLIMIT_NOFILE))
50974 return -EINVAL;
50975 err = alloc_fd(from, flags);
50976diff --git a/fs/filesystems.c b/fs/filesystems.c
50977index da165f6..3671bdb 100644
50978--- a/fs/filesystems.c
50979+++ b/fs/filesystems.c
50980@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
50981 int len = dot ? dot - name : strlen(name);
50982
50983 fs = __get_fs_type(name, len);
50984+
50985+#ifdef CONFIG_GRKERNSEC_MODHARDEN
50986+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
50987+#else
50988 if (!fs && (request_module("%.*s", len, name) == 0))
50989+#endif
50990 fs = __get_fs_type(name, len);
50991
50992 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
50993diff --git a/fs/fs_struct.c b/fs/fs_struct.c
50994index fe6ca58..65318cf 100644
50995--- a/fs/fs_struct.c
50996+++ b/fs/fs_struct.c
50997@@ -4,6 +4,7 @@
50998 #include <linux/path.h>
50999 #include <linux/slab.h>
51000 #include <linux/fs_struct.h>
51001+#include <linux/grsecurity.h>
51002 #include "internal.h"
51003
51004 /*
51005@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
51006 write_seqcount_begin(&fs->seq);
51007 old_root = fs->root;
51008 fs->root = *path;
51009+ gr_set_chroot_entries(current, path);
51010 write_seqcount_end(&fs->seq);
51011 spin_unlock(&fs->lock);
51012 if (old_root.dentry)
51013@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
51014 return 1;
51015 }
51016
51017+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
51018+{
51019+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
51020+ return 0;
51021+ *p = *new;
51022+
51023+ /* This function is only called from pivot_root(). Leave our
51024+ gr_chroot_dentry and is_chrooted flags as-is, so that a
51025+ pivoted root isn't treated as a chroot
51026+ */
51027+ //gr_set_chroot_entries(task, new);
51028+
51029+ return 1;
51030+}
51031+
51032 void chroot_fs_refs(struct path *old_root, struct path *new_root)
51033 {
51034 struct task_struct *g, *p;
51035@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
51036 int hits = 0;
51037 spin_lock(&fs->lock);
51038 write_seqcount_begin(&fs->seq);
51039- hits += replace_path(&fs->root, old_root, new_root);
51040+ hits += replace_root_path(p, &fs->root, old_root, new_root);
51041 hits += replace_path(&fs->pwd, old_root, new_root);
51042 write_seqcount_end(&fs->seq);
51043 while (hits--) {
51044@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
51045 task_lock(tsk);
51046 spin_lock(&fs->lock);
51047 tsk->fs = NULL;
51048- kill = !--fs->users;
51049+ gr_clear_chroot_entries(tsk);
51050+ kill = !atomic_dec_return(&fs->users);
51051 spin_unlock(&fs->lock);
51052 task_unlock(tsk);
51053 if (kill)
51054@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51055 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51056 /* We don't need to lock fs - think why ;-) */
51057 if (fs) {
51058- fs->users = 1;
51059+ atomic_set(&fs->users, 1);
51060 fs->in_exec = 0;
51061 spin_lock_init(&fs->lock);
51062 seqcount_init(&fs->seq);
51063@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51064 spin_lock(&old->lock);
51065 fs->root = old->root;
51066 path_get(&fs->root);
51067+ /* instead of calling gr_set_chroot_entries here,
51068+ we call it from every caller of this function
51069+ */
51070 fs->pwd = old->pwd;
51071 path_get(&fs->pwd);
51072 spin_unlock(&old->lock);
51073@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
51074
51075 task_lock(current);
51076 spin_lock(&fs->lock);
51077- kill = !--fs->users;
51078+ kill = !atomic_dec_return(&fs->users);
51079 current->fs = new_fs;
51080+ gr_set_chroot_entries(current, &new_fs->root);
51081 spin_unlock(&fs->lock);
51082 task_unlock(current);
51083
51084@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51085
51086 int current_umask(void)
51087 {
51088- return current->fs->umask;
51089+ return current->fs->umask | gr_acl_umask();
51090 }
51091 EXPORT_SYMBOL(current_umask);
51092
51093 /* to be mentioned only in INIT_TASK */
51094 struct fs_struct init_fs = {
51095- .users = 1,
51096+ .users = ATOMIC_INIT(1),
51097 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51098 .seq = SEQCNT_ZERO,
51099 .umask = 0022,
51100diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51101index 8dcb114..b1072e2 100644
51102--- a/fs/fscache/cookie.c
51103+++ b/fs/fscache/cookie.c
51104@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51105 parent ? (char *) parent->def->name : "<no-parent>",
51106 def->name, netfs_data);
51107
51108- fscache_stat(&fscache_n_acquires);
51109+ fscache_stat_unchecked(&fscache_n_acquires);
51110
51111 /* if there's no parent cookie, then we don't create one here either */
51112 if (!parent) {
51113- fscache_stat(&fscache_n_acquires_null);
51114+ fscache_stat_unchecked(&fscache_n_acquires_null);
51115 _leave(" [no parent]");
51116 return NULL;
51117 }
51118@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51119 /* allocate and initialise a cookie */
51120 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51121 if (!cookie) {
51122- fscache_stat(&fscache_n_acquires_oom);
51123+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51124 _leave(" [ENOMEM]");
51125 return NULL;
51126 }
51127@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51128
51129 switch (cookie->def->type) {
51130 case FSCACHE_COOKIE_TYPE_INDEX:
51131- fscache_stat(&fscache_n_cookie_index);
51132+ fscache_stat_unchecked(&fscache_n_cookie_index);
51133 break;
51134 case FSCACHE_COOKIE_TYPE_DATAFILE:
51135- fscache_stat(&fscache_n_cookie_data);
51136+ fscache_stat_unchecked(&fscache_n_cookie_data);
51137 break;
51138 default:
51139- fscache_stat(&fscache_n_cookie_special);
51140+ fscache_stat_unchecked(&fscache_n_cookie_special);
51141 break;
51142 }
51143
51144@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51145 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51146 atomic_dec(&parent->n_children);
51147 __fscache_cookie_put(cookie);
51148- fscache_stat(&fscache_n_acquires_nobufs);
51149+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51150 _leave(" = NULL");
51151 return NULL;
51152 }
51153 }
51154
51155- fscache_stat(&fscache_n_acquires_ok);
51156+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51157 _leave(" = %p", cookie);
51158 return cookie;
51159 }
51160@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51161 cache = fscache_select_cache_for_object(cookie->parent);
51162 if (!cache) {
51163 up_read(&fscache_addremove_sem);
51164- fscache_stat(&fscache_n_acquires_no_cache);
51165+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51166 _leave(" = -ENOMEDIUM [no cache]");
51167 return -ENOMEDIUM;
51168 }
51169@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51170 object = cache->ops->alloc_object(cache, cookie);
51171 fscache_stat_d(&fscache_n_cop_alloc_object);
51172 if (IS_ERR(object)) {
51173- fscache_stat(&fscache_n_object_no_alloc);
51174+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51175 ret = PTR_ERR(object);
51176 goto error;
51177 }
51178
51179- fscache_stat(&fscache_n_object_alloc);
51180+ fscache_stat_unchecked(&fscache_n_object_alloc);
51181
51182 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51183
51184@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51185
51186 _enter("{%s}", cookie->def->name);
51187
51188- fscache_stat(&fscache_n_invalidates);
51189+ fscache_stat_unchecked(&fscache_n_invalidates);
51190
51191 /* Only permit invalidation of data files. Invalidating an index will
51192 * require the caller to release all its attachments to the tree rooted
51193@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
51194 struct fscache_object *object;
51195 struct hlist_node *_p;
51196
51197- fscache_stat(&fscache_n_updates);
51198+ fscache_stat_unchecked(&fscache_n_updates);
51199
51200 if (!cookie) {
51201- fscache_stat(&fscache_n_updates_null);
51202+ fscache_stat_unchecked(&fscache_n_updates_null);
51203 _leave(" [no cookie]");
51204 return;
51205 }
51206@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51207 struct fscache_object *object;
51208 unsigned long event;
51209
51210- fscache_stat(&fscache_n_relinquishes);
51211+ fscache_stat_unchecked(&fscache_n_relinquishes);
51212 if (retire)
51213- fscache_stat(&fscache_n_relinquishes_retire);
51214+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
51215
51216 if (!cookie) {
51217- fscache_stat(&fscache_n_relinquishes_null);
51218+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
51219 _leave(" [no cookie]");
51220 return;
51221 }
51222@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51223
51224 /* wait for the cookie to finish being instantiated (or to fail) */
51225 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
51226- fscache_stat(&fscache_n_relinquishes_waitcrt);
51227+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
51228 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
51229 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
51230 }
51231diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
51232index ee38fef..0a326d4 100644
51233--- a/fs/fscache/internal.h
51234+++ b/fs/fscache/internal.h
51235@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
51236 * stats.c
51237 */
51238 #ifdef CONFIG_FSCACHE_STATS
51239-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51240-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51241+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51242+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51243
51244-extern atomic_t fscache_n_op_pend;
51245-extern atomic_t fscache_n_op_run;
51246-extern atomic_t fscache_n_op_enqueue;
51247-extern atomic_t fscache_n_op_deferred_release;
51248-extern atomic_t fscache_n_op_release;
51249-extern atomic_t fscache_n_op_gc;
51250-extern atomic_t fscache_n_op_cancelled;
51251-extern atomic_t fscache_n_op_rejected;
51252+extern atomic_unchecked_t fscache_n_op_pend;
51253+extern atomic_unchecked_t fscache_n_op_run;
51254+extern atomic_unchecked_t fscache_n_op_enqueue;
51255+extern atomic_unchecked_t fscache_n_op_deferred_release;
51256+extern atomic_unchecked_t fscache_n_op_release;
51257+extern atomic_unchecked_t fscache_n_op_gc;
51258+extern atomic_unchecked_t fscache_n_op_cancelled;
51259+extern atomic_unchecked_t fscache_n_op_rejected;
51260
51261-extern atomic_t fscache_n_attr_changed;
51262-extern atomic_t fscache_n_attr_changed_ok;
51263-extern atomic_t fscache_n_attr_changed_nobufs;
51264-extern atomic_t fscache_n_attr_changed_nomem;
51265-extern atomic_t fscache_n_attr_changed_calls;
51266+extern atomic_unchecked_t fscache_n_attr_changed;
51267+extern atomic_unchecked_t fscache_n_attr_changed_ok;
51268+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
51269+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
51270+extern atomic_unchecked_t fscache_n_attr_changed_calls;
51271
51272-extern atomic_t fscache_n_allocs;
51273-extern atomic_t fscache_n_allocs_ok;
51274-extern atomic_t fscache_n_allocs_wait;
51275-extern atomic_t fscache_n_allocs_nobufs;
51276-extern atomic_t fscache_n_allocs_intr;
51277-extern atomic_t fscache_n_allocs_object_dead;
51278-extern atomic_t fscache_n_alloc_ops;
51279-extern atomic_t fscache_n_alloc_op_waits;
51280+extern atomic_unchecked_t fscache_n_allocs;
51281+extern atomic_unchecked_t fscache_n_allocs_ok;
51282+extern atomic_unchecked_t fscache_n_allocs_wait;
51283+extern atomic_unchecked_t fscache_n_allocs_nobufs;
51284+extern atomic_unchecked_t fscache_n_allocs_intr;
51285+extern atomic_unchecked_t fscache_n_allocs_object_dead;
51286+extern atomic_unchecked_t fscache_n_alloc_ops;
51287+extern atomic_unchecked_t fscache_n_alloc_op_waits;
51288
51289-extern atomic_t fscache_n_retrievals;
51290-extern atomic_t fscache_n_retrievals_ok;
51291-extern atomic_t fscache_n_retrievals_wait;
51292-extern atomic_t fscache_n_retrievals_nodata;
51293-extern atomic_t fscache_n_retrievals_nobufs;
51294-extern atomic_t fscache_n_retrievals_intr;
51295-extern atomic_t fscache_n_retrievals_nomem;
51296-extern atomic_t fscache_n_retrievals_object_dead;
51297-extern atomic_t fscache_n_retrieval_ops;
51298-extern atomic_t fscache_n_retrieval_op_waits;
51299+extern atomic_unchecked_t fscache_n_retrievals;
51300+extern atomic_unchecked_t fscache_n_retrievals_ok;
51301+extern atomic_unchecked_t fscache_n_retrievals_wait;
51302+extern atomic_unchecked_t fscache_n_retrievals_nodata;
51303+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
51304+extern atomic_unchecked_t fscache_n_retrievals_intr;
51305+extern atomic_unchecked_t fscache_n_retrievals_nomem;
51306+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
51307+extern atomic_unchecked_t fscache_n_retrieval_ops;
51308+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
51309
51310-extern atomic_t fscache_n_stores;
51311-extern atomic_t fscache_n_stores_ok;
51312-extern atomic_t fscache_n_stores_again;
51313-extern atomic_t fscache_n_stores_nobufs;
51314-extern atomic_t fscache_n_stores_oom;
51315-extern atomic_t fscache_n_store_ops;
51316-extern atomic_t fscache_n_store_calls;
51317-extern atomic_t fscache_n_store_pages;
51318-extern atomic_t fscache_n_store_radix_deletes;
51319-extern atomic_t fscache_n_store_pages_over_limit;
51320+extern atomic_unchecked_t fscache_n_stores;
51321+extern atomic_unchecked_t fscache_n_stores_ok;
51322+extern atomic_unchecked_t fscache_n_stores_again;
51323+extern atomic_unchecked_t fscache_n_stores_nobufs;
51324+extern atomic_unchecked_t fscache_n_stores_oom;
51325+extern atomic_unchecked_t fscache_n_store_ops;
51326+extern atomic_unchecked_t fscache_n_store_calls;
51327+extern atomic_unchecked_t fscache_n_store_pages;
51328+extern atomic_unchecked_t fscache_n_store_radix_deletes;
51329+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
51330
51331-extern atomic_t fscache_n_store_vmscan_not_storing;
51332-extern atomic_t fscache_n_store_vmscan_gone;
51333-extern atomic_t fscache_n_store_vmscan_busy;
51334-extern atomic_t fscache_n_store_vmscan_cancelled;
51335-extern atomic_t fscache_n_store_vmscan_wait;
51336+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51337+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
51338+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
51339+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51340+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
51341
51342-extern atomic_t fscache_n_marks;
51343-extern atomic_t fscache_n_uncaches;
51344+extern atomic_unchecked_t fscache_n_marks;
51345+extern atomic_unchecked_t fscache_n_uncaches;
51346
51347-extern atomic_t fscache_n_acquires;
51348-extern atomic_t fscache_n_acquires_null;
51349-extern atomic_t fscache_n_acquires_no_cache;
51350-extern atomic_t fscache_n_acquires_ok;
51351-extern atomic_t fscache_n_acquires_nobufs;
51352-extern atomic_t fscache_n_acquires_oom;
51353+extern atomic_unchecked_t fscache_n_acquires;
51354+extern atomic_unchecked_t fscache_n_acquires_null;
51355+extern atomic_unchecked_t fscache_n_acquires_no_cache;
51356+extern atomic_unchecked_t fscache_n_acquires_ok;
51357+extern atomic_unchecked_t fscache_n_acquires_nobufs;
51358+extern atomic_unchecked_t fscache_n_acquires_oom;
51359
51360-extern atomic_t fscache_n_invalidates;
51361-extern atomic_t fscache_n_invalidates_run;
51362+extern atomic_unchecked_t fscache_n_invalidates;
51363+extern atomic_unchecked_t fscache_n_invalidates_run;
51364
51365-extern atomic_t fscache_n_updates;
51366-extern atomic_t fscache_n_updates_null;
51367-extern atomic_t fscache_n_updates_run;
51368+extern atomic_unchecked_t fscache_n_updates;
51369+extern atomic_unchecked_t fscache_n_updates_null;
51370+extern atomic_unchecked_t fscache_n_updates_run;
51371
51372-extern atomic_t fscache_n_relinquishes;
51373-extern atomic_t fscache_n_relinquishes_null;
51374-extern atomic_t fscache_n_relinquishes_waitcrt;
51375-extern atomic_t fscache_n_relinquishes_retire;
51376+extern atomic_unchecked_t fscache_n_relinquishes;
51377+extern atomic_unchecked_t fscache_n_relinquishes_null;
51378+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51379+extern atomic_unchecked_t fscache_n_relinquishes_retire;
51380
51381-extern atomic_t fscache_n_cookie_index;
51382-extern atomic_t fscache_n_cookie_data;
51383-extern atomic_t fscache_n_cookie_special;
51384+extern atomic_unchecked_t fscache_n_cookie_index;
51385+extern atomic_unchecked_t fscache_n_cookie_data;
51386+extern atomic_unchecked_t fscache_n_cookie_special;
51387
51388-extern atomic_t fscache_n_object_alloc;
51389-extern atomic_t fscache_n_object_no_alloc;
51390-extern atomic_t fscache_n_object_lookups;
51391-extern atomic_t fscache_n_object_lookups_negative;
51392-extern atomic_t fscache_n_object_lookups_positive;
51393-extern atomic_t fscache_n_object_lookups_timed_out;
51394-extern atomic_t fscache_n_object_created;
51395-extern atomic_t fscache_n_object_avail;
51396-extern atomic_t fscache_n_object_dead;
51397+extern atomic_unchecked_t fscache_n_object_alloc;
51398+extern atomic_unchecked_t fscache_n_object_no_alloc;
51399+extern atomic_unchecked_t fscache_n_object_lookups;
51400+extern atomic_unchecked_t fscache_n_object_lookups_negative;
51401+extern atomic_unchecked_t fscache_n_object_lookups_positive;
51402+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51403+extern atomic_unchecked_t fscache_n_object_created;
51404+extern atomic_unchecked_t fscache_n_object_avail;
51405+extern atomic_unchecked_t fscache_n_object_dead;
51406
51407-extern atomic_t fscache_n_checkaux_none;
51408-extern atomic_t fscache_n_checkaux_okay;
51409-extern atomic_t fscache_n_checkaux_update;
51410-extern atomic_t fscache_n_checkaux_obsolete;
51411+extern atomic_unchecked_t fscache_n_checkaux_none;
51412+extern atomic_unchecked_t fscache_n_checkaux_okay;
51413+extern atomic_unchecked_t fscache_n_checkaux_update;
51414+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51415
51416 extern atomic_t fscache_n_cop_alloc_object;
51417 extern atomic_t fscache_n_cop_lookup_object;
51418@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51419 atomic_inc(stat);
51420 }
51421
51422+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51423+{
51424+ atomic_inc_unchecked(stat);
51425+}
51426+
51427 static inline void fscache_stat_d(atomic_t *stat)
51428 {
51429 atomic_dec(stat);
51430@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51431
51432 #define __fscache_stat(stat) (NULL)
51433 #define fscache_stat(stat) do {} while (0)
51434+#define fscache_stat_unchecked(stat) do {} while (0)
51435 #define fscache_stat_d(stat) do {} while (0)
51436 #endif
51437
51438diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51439index 50d41c1..10ee117 100644
51440--- a/fs/fscache/object.c
51441+++ b/fs/fscache/object.c
51442@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51443 /* Invalidate an object on disk */
51444 case FSCACHE_OBJECT_INVALIDATING:
51445 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51446- fscache_stat(&fscache_n_invalidates_run);
51447+ fscache_stat_unchecked(&fscache_n_invalidates_run);
51448 fscache_stat(&fscache_n_cop_invalidate_object);
51449 fscache_invalidate_object(object);
51450 fscache_stat_d(&fscache_n_cop_invalidate_object);
51451@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51452 /* update the object metadata on disk */
51453 case FSCACHE_OBJECT_UPDATING:
51454 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51455- fscache_stat(&fscache_n_updates_run);
51456+ fscache_stat_unchecked(&fscache_n_updates_run);
51457 fscache_stat(&fscache_n_cop_update_object);
51458 object->cache->ops->update_object(object);
51459 fscache_stat_d(&fscache_n_cop_update_object);
51460@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51461 spin_lock(&object->lock);
51462 object->state = FSCACHE_OBJECT_DEAD;
51463 spin_unlock(&object->lock);
51464- fscache_stat(&fscache_n_object_dead);
51465+ fscache_stat_unchecked(&fscache_n_object_dead);
51466 goto terminal_transit;
51467
51468 /* handle the parent cache of this object being withdrawn from
51469@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51470 spin_lock(&object->lock);
51471 object->state = FSCACHE_OBJECT_DEAD;
51472 spin_unlock(&object->lock);
51473- fscache_stat(&fscache_n_object_dead);
51474+ fscache_stat_unchecked(&fscache_n_object_dead);
51475 goto terminal_transit;
51476
51477 /* complain about the object being woken up once it is
51478@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51479 parent->cookie->def->name, cookie->def->name,
51480 object->cache->tag->name);
51481
51482- fscache_stat(&fscache_n_object_lookups);
51483+ fscache_stat_unchecked(&fscache_n_object_lookups);
51484 fscache_stat(&fscache_n_cop_lookup_object);
51485 ret = object->cache->ops->lookup_object(object);
51486 fscache_stat_d(&fscache_n_cop_lookup_object);
51487@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51488 if (ret == -ETIMEDOUT) {
51489 /* probably stuck behind another object, so move this one to
51490 * the back of the queue */
51491- fscache_stat(&fscache_n_object_lookups_timed_out);
51492+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51493 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51494 }
51495
51496@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51497
51498 spin_lock(&object->lock);
51499 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51500- fscache_stat(&fscache_n_object_lookups_negative);
51501+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51502
51503 /* transit here to allow write requests to begin stacking up
51504 * and read requests to begin returning ENODATA */
51505@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51506 * result, in which case there may be data available */
51507 spin_lock(&object->lock);
51508 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51509- fscache_stat(&fscache_n_object_lookups_positive);
51510+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51511
51512 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51513
51514@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51515 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51516 } else {
51517 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51518- fscache_stat(&fscache_n_object_created);
51519+ fscache_stat_unchecked(&fscache_n_object_created);
51520
51521 object->state = FSCACHE_OBJECT_AVAILABLE;
51522 spin_unlock(&object->lock);
51523@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51524 fscache_enqueue_dependents(object);
51525
51526 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51527- fscache_stat(&fscache_n_object_avail);
51528+ fscache_stat_unchecked(&fscache_n_object_avail);
51529
51530 _leave("");
51531 }
51532@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51533 enum fscache_checkaux result;
51534
51535 if (!object->cookie->def->check_aux) {
51536- fscache_stat(&fscache_n_checkaux_none);
51537+ fscache_stat_unchecked(&fscache_n_checkaux_none);
51538 return FSCACHE_CHECKAUX_OKAY;
51539 }
51540
51541@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51542 switch (result) {
51543 /* entry okay as is */
51544 case FSCACHE_CHECKAUX_OKAY:
51545- fscache_stat(&fscache_n_checkaux_okay);
51546+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
51547 break;
51548
51549 /* entry requires update */
51550 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51551- fscache_stat(&fscache_n_checkaux_update);
51552+ fscache_stat_unchecked(&fscache_n_checkaux_update);
51553 break;
51554
51555 /* entry requires deletion */
51556 case FSCACHE_CHECKAUX_OBSOLETE:
51557- fscache_stat(&fscache_n_checkaux_obsolete);
51558+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51559 break;
51560
51561 default:
51562diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51563index 762a9ec..2023284 100644
51564--- a/fs/fscache/operation.c
51565+++ b/fs/fscache/operation.c
51566@@ -17,7 +17,7 @@
51567 #include <linux/slab.h>
51568 #include "internal.h"
51569
51570-atomic_t fscache_op_debug_id;
51571+atomic_unchecked_t fscache_op_debug_id;
51572 EXPORT_SYMBOL(fscache_op_debug_id);
51573
51574 /**
51575@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51576 ASSERTCMP(atomic_read(&op->usage), >, 0);
51577 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51578
51579- fscache_stat(&fscache_n_op_enqueue);
51580+ fscache_stat_unchecked(&fscache_n_op_enqueue);
51581 switch (op->flags & FSCACHE_OP_TYPE) {
51582 case FSCACHE_OP_ASYNC:
51583 _debug("queue async");
51584@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51585 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51586 if (op->processor)
51587 fscache_enqueue_operation(op);
51588- fscache_stat(&fscache_n_op_run);
51589+ fscache_stat_unchecked(&fscache_n_op_run);
51590 }
51591
51592 /*
51593@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51594 if (object->n_in_progress > 0) {
51595 atomic_inc(&op->usage);
51596 list_add_tail(&op->pend_link, &object->pending_ops);
51597- fscache_stat(&fscache_n_op_pend);
51598+ fscache_stat_unchecked(&fscache_n_op_pend);
51599 } else if (!list_empty(&object->pending_ops)) {
51600 atomic_inc(&op->usage);
51601 list_add_tail(&op->pend_link, &object->pending_ops);
51602- fscache_stat(&fscache_n_op_pend);
51603+ fscache_stat_unchecked(&fscache_n_op_pend);
51604 fscache_start_operations(object);
51605 } else {
51606 ASSERTCMP(object->n_in_progress, ==, 0);
51607@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51608 object->n_exclusive++; /* reads and writes must wait */
51609 atomic_inc(&op->usage);
51610 list_add_tail(&op->pend_link, &object->pending_ops);
51611- fscache_stat(&fscache_n_op_pend);
51612+ fscache_stat_unchecked(&fscache_n_op_pend);
51613 ret = 0;
51614 } else {
51615 /* If we're in any other state, there must have been an I/O
51616@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51617 if (object->n_exclusive > 0) {
51618 atomic_inc(&op->usage);
51619 list_add_tail(&op->pend_link, &object->pending_ops);
51620- fscache_stat(&fscache_n_op_pend);
51621+ fscache_stat_unchecked(&fscache_n_op_pend);
51622 } else if (!list_empty(&object->pending_ops)) {
51623 atomic_inc(&op->usage);
51624 list_add_tail(&op->pend_link, &object->pending_ops);
51625- fscache_stat(&fscache_n_op_pend);
51626+ fscache_stat_unchecked(&fscache_n_op_pend);
51627 fscache_start_operations(object);
51628 } else {
51629 ASSERTCMP(object->n_exclusive, ==, 0);
51630@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51631 object->n_ops++;
51632 atomic_inc(&op->usage);
51633 list_add_tail(&op->pend_link, &object->pending_ops);
51634- fscache_stat(&fscache_n_op_pend);
51635+ fscache_stat_unchecked(&fscache_n_op_pend);
51636 ret = 0;
51637 } else if (object->state == FSCACHE_OBJECT_DYING ||
51638 object->state == FSCACHE_OBJECT_LC_DYING ||
51639 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51640- fscache_stat(&fscache_n_op_rejected);
51641+ fscache_stat_unchecked(&fscache_n_op_rejected);
51642 op->state = FSCACHE_OP_ST_CANCELLED;
51643 ret = -ENOBUFS;
51644 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51645@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51646 ret = -EBUSY;
51647 if (op->state == FSCACHE_OP_ST_PENDING) {
51648 ASSERT(!list_empty(&op->pend_link));
51649- fscache_stat(&fscache_n_op_cancelled);
51650+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51651 list_del_init(&op->pend_link);
51652 if (do_cancel)
51653 do_cancel(op);
51654@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51655 while (!list_empty(&object->pending_ops)) {
51656 op = list_entry(object->pending_ops.next,
51657 struct fscache_operation, pend_link);
51658- fscache_stat(&fscache_n_op_cancelled);
51659+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51660 list_del_init(&op->pend_link);
51661
51662 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51663@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51664 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51665 op->state = FSCACHE_OP_ST_DEAD;
51666
51667- fscache_stat(&fscache_n_op_release);
51668+ fscache_stat_unchecked(&fscache_n_op_release);
51669
51670 if (op->release) {
51671 op->release(op);
51672@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51673 * lock, and defer it otherwise */
51674 if (!spin_trylock(&object->lock)) {
51675 _debug("defer put");
51676- fscache_stat(&fscache_n_op_deferred_release);
51677+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
51678
51679 cache = object->cache;
51680 spin_lock(&cache->op_gc_list_lock);
51681@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51682
51683 _debug("GC DEFERRED REL OBJ%x OP%x",
51684 object->debug_id, op->debug_id);
51685- fscache_stat(&fscache_n_op_gc);
51686+ fscache_stat_unchecked(&fscache_n_op_gc);
51687
51688 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51689 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51690diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51691index ff000e5..c44ec6d 100644
51692--- a/fs/fscache/page.c
51693+++ b/fs/fscache/page.c
51694@@ -61,7 +61,7 @@ try_again:
51695 val = radix_tree_lookup(&cookie->stores, page->index);
51696 if (!val) {
51697 rcu_read_unlock();
51698- fscache_stat(&fscache_n_store_vmscan_not_storing);
51699+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51700 __fscache_uncache_page(cookie, page);
51701 return true;
51702 }
51703@@ -91,11 +91,11 @@ try_again:
51704 spin_unlock(&cookie->stores_lock);
51705
51706 if (xpage) {
51707- fscache_stat(&fscache_n_store_vmscan_cancelled);
51708- fscache_stat(&fscache_n_store_radix_deletes);
51709+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51710+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51711 ASSERTCMP(xpage, ==, page);
51712 } else {
51713- fscache_stat(&fscache_n_store_vmscan_gone);
51714+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51715 }
51716
51717 wake_up_bit(&cookie->flags, 0);
51718@@ -110,11 +110,11 @@ page_busy:
51719 * sleeping on memory allocation, so we may need to impose a timeout
51720 * too. */
51721 if (!(gfp & __GFP_WAIT)) {
51722- fscache_stat(&fscache_n_store_vmscan_busy);
51723+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
51724 return false;
51725 }
51726
51727- fscache_stat(&fscache_n_store_vmscan_wait);
51728+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
51729 __fscache_wait_on_page_write(cookie, page);
51730 gfp &= ~__GFP_WAIT;
51731 goto try_again;
51732@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
51733 FSCACHE_COOKIE_STORING_TAG);
51734 if (!radix_tree_tag_get(&cookie->stores, page->index,
51735 FSCACHE_COOKIE_PENDING_TAG)) {
51736- fscache_stat(&fscache_n_store_radix_deletes);
51737+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51738 xpage = radix_tree_delete(&cookie->stores, page->index);
51739 }
51740 spin_unlock(&cookie->stores_lock);
51741@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
51742
51743 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
51744
51745- fscache_stat(&fscache_n_attr_changed_calls);
51746+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
51747
51748 if (fscache_object_is_active(object)) {
51749 fscache_stat(&fscache_n_cop_attr_changed);
51750@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51751
51752 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51753
51754- fscache_stat(&fscache_n_attr_changed);
51755+ fscache_stat_unchecked(&fscache_n_attr_changed);
51756
51757 op = kzalloc(sizeof(*op), GFP_KERNEL);
51758 if (!op) {
51759- fscache_stat(&fscache_n_attr_changed_nomem);
51760+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
51761 _leave(" = -ENOMEM");
51762 return -ENOMEM;
51763 }
51764@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51765 if (fscache_submit_exclusive_op(object, op) < 0)
51766 goto nobufs;
51767 spin_unlock(&cookie->lock);
51768- fscache_stat(&fscache_n_attr_changed_ok);
51769+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
51770 fscache_put_operation(op);
51771 _leave(" = 0");
51772 return 0;
51773@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51774 nobufs:
51775 spin_unlock(&cookie->lock);
51776 kfree(op);
51777- fscache_stat(&fscache_n_attr_changed_nobufs);
51778+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
51779 _leave(" = %d", -ENOBUFS);
51780 return -ENOBUFS;
51781 }
51782@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
51783 /* allocate a retrieval operation and attempt to submit it */
51784 op = kzalloc(sizeof(*op), GFP_NOIO);
51785 if (!op) {
51786- fscache_stat(&fscache_n_retrievals_nomem);
51787+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51788 return NULL;
51789 }
51790
51791@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
51792 return 0;
51793 }
51794
51795- fscache_stat(&fscache_n_retrievals_wait);
51796+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
51797
51798 jif = jiffies;
51799 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
51800 fscache_wait_bit_interruptible,
51801 TASK_INTERRUPTIBLE) != 0) {
51802- fscache_stat(&fscache_n_retrievals_intr);
51803+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51804 _leave(" = -ERESTARTSYS");
51805 return -ERESTARTSYS;
51806 }
51807@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
51808 */
51809 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51810 struct fscache_retrieval *op,
51811- atomic_t *stat_op_waits,
51812- atomic_t *stat_object_dead)
51813+ atomic_unchecked_t *stat_op_waits,
51814+ atomic_unchecked_t *stat_object_dead)
51815 {
51816 int ret;
51817
51818@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51819 goto check_if_dead;
51820
51821 _debug(">>> WT");
51822- fscache_stat(stat_op_waits);
51823+ fscache_stat_unchecked(stat_op_waits);
51824 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
51825 fscache_wait_bit_interruptible,
51826 TASK_INTERRUPTIBLE) != 0) {
51827@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51828
51829 check_if_dead:
51830 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
51831- fscache_stat(stat_object_dead);
51832+ fscache_stat_unchecked(stat_object_dead);
51833 _leave(" = -ENOBUFS [cancelled]");
51834 return -ENOBUFS;
51835 }
51836 if (unlikely(fscache_object_is_dead(object))) {
51837 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
51838 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
51839- fscache_stat(stat_object_dead);
51840+ fscache_stat_unchecked(stat_object_dead);
51841 return -ENOBUFS;
51842 }
51843 return 0;
51844@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51845
51846 _enter("%p,%p,,,", cookie, page);
51847
51848- fscache_stat(&fscache_n_retrievals);
51849+ fscache_stat_unchecked(&fscache_n_retrievals);
51850
51851 if (hlist_empty(&cookie->backing_objects))
51852 goto nobufs;
51853@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51854 goto nobufs_unlock_dec;
51855 spin_unlock(&cookie->lock);
51856
51857- fscache_stat(&fscache_n_retrieval_ops);
51858+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
51859
51860 /* pin the netfs read context in case we need to do the actual netfs
51861 * read because we've encountered a cache read failure */
51862@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51863
51864 error:
51865 if (ret == -ENOMEM)
51866- fscache_stat(&fscache_n_retrievals_nomem);
51867+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51868 else if (ret == -ERESTARTSYS)
51869- fscache_stat(&fscache_n_retrievals_intr);
51870+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51871 else if (ret == -ENODATA)
51872- fscache_stat(&fscache_n_retrievals_nodata);
51873+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51874 else if (ret < 0)
51875- fscache_stat(&fscache_n_retrievals_nobufs);
51876+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51877 else
51878- fscache_stat(&fscache_n_retrievals_ok);
51879+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
51880
51881 fscache_put_retrieval(op);
51882 _leave(" = %d", ret);
51883@@ -467,7 +467,7 @@ nobufs_unlock:
51884 spin_unlock(&cookie->lock);
51885 kfree(op);
51886 nobufs:
51887- fscache_stat(&fscache_n_retrievals_nobufs);
51888+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51889 _leave(" = -ENOBUFS");
51890 return -ENOBUFS;
51891 }
51892@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51893
51894 _enter("%p,,%d,,,", cookie, *nr_pages);
51895
51896- fscache_stat(&fscache_n_retrievals);
51897+ fscache_stat_unchecked(&fscache_n_retrievals);
51898
51899 if (hlist_empty(&cookie->backing_objects))
51900 goto nobufs;
51901@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51902 goto nobufs_unlock_dec;
51903 spin_unlock(&cookie->lock);
51904
51905- fscache_stat(&fscache_n_retrieval_ops);
51906+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
51907
51908 /* pin the netfs read context in case we need to do the actual netfs
51909 * read because we've encountered a cache read failure */
51910@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51911
51912 error:
51913 if (ret == -ENOMEM)
51914- fscache_stat(&fscache_n_retrievals_nomem);
51915+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51916 else if (ret == -ERESTARTSYS)
51917- fscache_stat(&fscache_n_retrievals_intr);
51918+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51919 else if (ret == -ENODATA)
51920- fscache_stat(&fscache_n_retrievals_nodata);
51921+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51922 else if (ret < 0)
51923- fscache_stat(&fscache_n_retrievals_nobufs);
51924+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51925 else
51926- fscache_stat(&fscache_n_retrievals_ok);
51927+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
51928
51929 fscache_put_retrieval(op);
51930 _leave(" = %d", ret);
51931@@ -591,7 +591,7 @@ nobufs_unlock:
51932 spin_unlock(&cookie->lock);
51933 kfree(op);
51934 nobufs:
51935- fscache_stat(&fscache_n_retrievals_nobufs);
51936+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51937 _leave(" = -ENOBUFS");
51938 return -ENOBUFS;
51939 }
51940@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51941
51942 _enter("%p,%p,,,", cookie, page);
51943
51944- fscache_stat(&fscache_n_allocs);
51945+ fscache_stat_unchecked(&fscache_n_allocs);
51946
51947 if (hlist_empty(&cookie->backing_objects))
51948 goto nobufs;
51949@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51950 goto nobufs_unlock;
51951 spin_unlock(&cookie->lock);
51952
51953- fscache_stat(&fscache_n_alloc_ops);
51954+ fscache_stat_unchecked(&fscache_n_alloc_ops);
51955
51956 ret = fscache_wait_for_retrieval_activation(
51957 object, op,
51958@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51959
51960 error:
51961 if (ret == -ERESTARTSYS)
51962- fscache_stat(&fscache_n_allocs_intr);
51963+ fscache_stat_unchecked(&fscache_n_allocs_intr);
51964 else if (ret < 0)
51965- fscache_stat(&fscache_n_allocs_nobufs);
51966+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51967 else
51968- fscache_stat(&fscache_n_allocs_ok);
51969+ fscache_stat_unchecked(&fscache_n_allocs_ok);
51970
51971 fscache_put_retrieval(op);
51972 _leave(" = %d", ret);
51973@@ -677,7 +677,7 @@ nobufs_unlock:
51974 spin_unlock(&cookie->lock);
51975 kfree(op);
51976 nobufs:
51977- fscache_stat(&fscache_n_allocs_nobufs);
51978+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51979 _leave(" = -ENOBUFS");
51980 return -ENOBUFS;
51981 }
51982@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51983
51984 spin_lock(&cookie->stores_lock);
51985
51986- fscache_stat(&fscache_n_store_calls);
51987+ fscache_stat_unchecked(&fscache_n_store_calls);
51988
51989 /* find a page to store */
51990 page = NULL;
51991@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51992 page = results[0];
51993 _debug("gang %d [%lx]", n, page->index);
51994 if (page->index > op->store_limit) {
51995- fscache_stat(&fscache_n_store_pages_over_limit);
51996+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
51997 goto superseded;
51998 }
51999
52000@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52001 spin_unlock(&cookie->stores_lock);
52002 spin_unlock(&object->lock);
52003
52004- fscache_stat(&fscache_n_store_pages);
52005+ fscache_stat_unchecked(&fscache_n_store_pages);
52006 fscache_stat(&fscache_n_cop_write_page);
52007 ret = object->cache->ops->write_page(op, page);
52008 fscache_stat_d(&fscache_n_cop_write_page);
52009@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52010 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52011 ASSERT(PageFsCache(page));
52012
52013- fscache_stat(&fscache_n_stores);
52014+ fscache_stat_unchecked(&fscache_n_stores);
52015
52016 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52017 _leave(" = -ENOBUFS [invalidating]");
52018@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52019 spin_unlock(&cookie->stores_lock);
52020 spin_unlock(&object->lock);
52021
52022- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52023+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52024 op->store_limit = object->store_limit;
52025
52026 if (fscache_submit_op(object, &op->op) < 0)
52027@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52028
52029 spin_unlock(&cookie->lock);
52030 radix_tree_preload_end();
52031- fscache_stat(&fscache_n_store_ops);
52032- fscache_stat(&fscache_n_stores_ok);
52033+ fscache_stat_unchecked(&fscache_n_store_ops);
52034+ fscache_stat_unchecked(&fscache_n_stores_ok);
52035
52036 /* the work queue now carries its own ref on the object */
52037 fscache_put_operation(&op->op);
52038@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52039 return 0;
52040
52041 already_queued:
52042- fscache_stat(&fscache_n_stores_again);
52043+ fscache_stat_unchecked(&fscache_n_stores_again);
52044 already_pending:
52045 spin_unlock(&cookie->stores_lock);
52046 spin_unlock(&object->lock);
52047 spin_unlock(&cookie->lock);
52048 radix_tree_preload_end();
52049 kfree(op);
52050- fscache_stat(&fscache_n_stores_ok);
52051+ fscache_stat_unchecked(&fscache_n_stores_ok);
52052 _leave(" = 0");
52053 return 0;
52054
52055@@ -959,14 +959,14 @@ nobufs:
52056 spin_unlock(&cookie->lock);
52057 radix_tree_preload_end();
52058 kfree(op);
52059- fscache_stat(&fscache_n_stores_nobufs);
52060+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52061 _leave(" = -ENOBUFS");
52062 return -ENOBUFS;
52063
52064 nomem_free:
52065 kfree(op);
52066 nomem:
52067- fscache_stat(&fscache_n_stores_oom);
52068+ fscache_stat_unchecked(&fscache_n_stores_oom);
52069 _leave(" = -ENOMEM");
52070 return -ENOMEM;
52071 }
52072@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52073 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52074 ASSERTCMP(page, !=, NULL);
52075
52076- fscache_stat(&fscache_n_uncaches);
52077+ fscache_stat_unchecked(&fscache_n_uncaches);
52078
52079 /* cache withdrawal may beat us to it */
52080 if (!PageFsCache(page))
52081@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52082 struct fscache_cookie *cookie = op->op.object->cookie;
52083
52084 #ifdef CONFIG_FSCACHE_STATS
52085- atomic_inc(&fscache_n_marks);
52086+ atomic_inc_unchecked(&fscache_n_marks);
52087 #endif
52088
52089 _debug("- mark %p{%lx}", page, page->index);
52090diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52091index 8179e8b..5072cc7 100644
52092--- a/fs/fscache/stats.c
52093+++ b/fs/fscache/stats.c
52094@@ -18,99 +18,99 @@
52095 /*
52096 * operation counters
52097 */
52098-atomic_t fscache_n_op_pend;
52099-atomic_t fscache_n_op_run;
52100-atomic_t fscache_n_op_enqueue;
52101-atomic_t fscache_n_op_requeue;
52102-atomic_t fscache_n_op_deferred_release;
52103-atomic_t fscache_n_op_release;
52104-atomic_t fscache_n_op_gc;
52105-atomic_t fscache_n_op_cancelled;
52106-atomic_t fscache_n_op_rejected;
52107+atomic_unchecked_t fscache_n_op_pend;
52108+atomic_unchecked_t fscache_n_op_run;
52109+atomic_unchecked_t fscache_n_op_enqueue;
52110+atomic_unchecked_t fscache_n_op_requeue;
52111+atomic_unchecked_t fscache_n_op_deferred_release;
52112+atomic_unchecked_t fscache_n_op_release;
52113+atomic_unchecked_t fscache_n_op_gc;
52114+atomic_unchecked_t fscache_n_op_cancelled;
52115+atomic_unchecked_t fscache_n_op_rejected;
52116
52117-atomic_t fscache_n_attr_changed;
52118-atomic_t fscache_n_attr_changed_ok;
52119-atomic_t fscache_n_attr_changed_nobufs;
52120-atomic_t fscache_n_attr_changed_nomem;
52121-atomic_t fscache_n_attr_changed_calls;
52122+atomic_unchecked_t fscache_n_attr_changed;
52123+atomic_unchecked_t fscache_n_attr_changed_ok;
52124+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52125+atomic_unchecked_t fscache_n_attr_changed_nomem;
52126+atomic_unchecked_t fscache_n_attr_changed_calls;
52127
52128-atomic_t fscache_n_allocs;
52129-atomic_t fscache_n_allocs_ok;
52130-atomic_t fscache_n_allocs_wait;
52131-atomic_t fscache_n_allocs_nobufs;
52132-atomic_t fscache_n_allocs_intr;
52133-atomic_t fscache_n_allocs_object_dead;
52134-atomic_t fscache_n_alloc_ops;
52135-atomic_t fscache_n_alloc_op_waits;
52136+atomic_unchecked_t fscache_n_allocs;
52137+atomic_unchecked_t fscache_n_allocs_ok;
52138+atomic_unchecked_t fscache_n_allocs_wait;
52139+atomic_unchecked_t fscache_n_allocs_nobufs;
52140+atomic_unchecked_t fscache_n_allocs_intr;
52141+atomic_unchecked_t fscache_n_allocs_object_dead;
52142+atomic_unchecked_t fscache_n_alloc_ops;
52143+atomic_unchecked_t fscache_n_alloc_op_waits;
52144
52145-atomic_t fscache_n_retrievals;
52146-atomic_t fscache_n_retrievals_ok;
52147-atomic_t fscache_n_retrievals_wait;
52148-atomic_t fscache_n_retrievals_nodata;
52149-atomic_t fscache_n_retrievals_nobufs;
52150-atomic_t fscache_n_retrievals_intr;
52151-atomic_t fscache_n_retrievals_nomem;
52152-atomic_t fscache_n_retrievals_object_dead;
52153-atomic_t fscache_n_retrieval_ops;
52154-atomic_t fscache_n_retrieval_op_waits;
52155+atomic_unchecked_t fscache_n_retrievals;
52156+atomic_unchecked_t fscache_n_retrievals_ok;
52157+atomic_unchecked_t fscache_n_retrievals_wait;
52158+atomic_unchecked_t fscache_n_retrievals_nodata;
52159+atomic_unchecked_t fscache_n_retrievals_nobufs;
52160+atomic_unchecked_t fscache_n_retrievals_intr;
52161+atomic_unchecked_t fscache_n_retrievals_nomem;
52162+atomic_unchecked_t fscache_n_retrievals_object_dead;
52163+atomic_unchecked_t fscache_n_retrieval_ops;
52164+atomic_unchecked_t fscache_n_retrieval_op_waits;
52165
52166-atomic_t fscache_n_stores;
52167-atomic_t fscache_n_stores_ok;
52168-atomic_t fscache_n_stores_again;
52169-atomic_t fscache_n_stores_nobufs;
52170-atomic_t fscache_n_stores_oom;
52171-atomic_t fscache_n_store_ops;
52172-atomic_t fscache_n_store_calls;
52173-atomic_t fscache_n_store_pages;
52174-atomic_t fscache_n_store_radix_deletes;
52175-atomic_t fscache_n_store_pages_over_limit;
52176+atomic_unchecked_t fscache_n_stores;
52177+atomic_unchecked_t fscache_n_stores_ok;
52178+atomic_unchecked_t fscache_n_stores_again;
52179+atomic_unchecked_t fscache_n_stores_nobufs;
52180+atomic_unchecked_t fscache_n_stores_oom;
52181+atomic_unchecked_t fscache_n_store_ops;
52182+atomic_unchecked_t fscache_n_store_calls;
52183+atomic_unchecked_t fscache_n_store_pages;
52184+atomic_unchecked_t fscache_n_store_radix_deletes;
52185+atomic_unchecked_t fscache_n_store_pages_over_limit;
52186
52187-atomic_t fscache_n_store_vmscan_not_storing;
52188-atomic_t fscache_n_store_vmscan_gone;
52189-atomic_t fscache_n_store_vmscan_busy;
52190-atomic_t fscache_n_store_vmscan_cancelled;
52191-atomic_t fscache_n_store_vmscan_wait;
52192+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52193+atomic_unchecked_t fscache_n_store_vmscan_gone;
52194+atomic_unchecked_t fscache_n_store_vmscan_busy;
52195+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52196+atomic_unchecked_t fscache_n_store_vmscan_wait;
52197
52198-atomic_t fscache_n_marks;
52199-atomic_t fscache_n_uncaches;
52200+atomic_unchecked_t fscache_n_marks;
52201+atomic_unchecked_t fscache_n_uncaches;
52202
52203-atomic_t fscache_n_acquires;
52204-atomic_t fscache_n_acquires_null;
52205-atomic_t fscache_n_acquires_no_cache;
52206-atomic_t fscache_n_acquires_ok;
52207-atomic_t fscache_n_acquires_nobufs;
52208-atomic_t fscache_n_acquires_oom;
52209+atomic_unchecked_t fscache_n_acquires;
52210+atomic_unchecked_t fscache_n_acquires_null;
52211+atomic_unchecked_t fscache_n_acquires_no_cache;
52212+atomic_unchecked_t fscache_n_acquires_ok;
52213+atomic_unchecked_t fscache_n_acquires_nobufs;
52214+atomic_unchecked_t fscache_n_acquires_oom;
52215
52216-atomic_t fscache_n_invalidates;
52217-atomic_t fscache_n_invalidates_run;
52218+atomic_unchecked_t fscache_n_invalidates;
52219+atomic_unchecked_t fscache_n_invalidates_run;
52220
52221-atomic_t fscache_n_updates;
52222-atomic_t fscache_n_updates_null;
52223-atomic_t fscache_n_updates_run;
52224+atomic_unchecked_t fscache_n_updates;
52225+atomic_unchecked_t fscache_n_updates_null;
52226+atomic_unchecked_t fscache_n_updates_run;
52227
52228-atomic_t fscache_n_relinquishes;
52229-atomic_t fscache_n_relinquishes_null;
52230-atomic_t fscache_n_relinquishes_waitcrt;
52231-atomic_t fscache_n_relinquishes_retire;
52232+atomic_unchecked_t fscache_n_relinquishes;
52233+atomic_unchecked_t fscache_n_relinquishes_null;
52234+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52235+atomic_unchecked_t fscache_n_relinquishes_retire;
52236
52237-atomic_t fscache_n_cookie_index;
52238-atomic_t fscache_n_cookie_data;
52239-atomic_t fscache_n_cookie_special;
52240+atomic_unchecked_t fscache_n_cookie_index;
52241+atomic_unchecked_t fscache_n_cookie_data;
52242+atomic_unchecked_t fscache_n_cookie_special;
52243
52244-atomic_t fscache_n_object_alloc;
52245-atomic_t fscache_n_object_no_alloc;
52246-atomic_t fscache_n_object_lookups;
52247-atomic_t fscache_n_object_lookups_negative;
52248-atomic_t fscache_n_object_lookups_positive;
52249-atomic_t fscache_n_object_lookups_timed_out;
52250-atomic_t fscache_n_object_created;
52251-atomic_t fscache_n_object_avail;
52252-atomic_t fscache_n_object_dead;
52253+atomic_unchecked_t fscache_n_object_alloc;
52254+atomic_unchecked_t fscache_n_object_no_alloc;
52255+atomic_unchecked_t fscache_n_object_lookups;
52256+atomic_unchecked_t fscache_n_object_lookups_negative;
52257+atomic_unchecked_t fscache_n_object_lookups_positive;
52258+atomic_unchecked_t fscache_n_object_lookups_timed_out;
52259+atomic_unchecked_t fscache_n_object_created;
52260+atomic_unchecked_t fscache_n_object_avail;
52261+atomic_unchecked_t fscache_n_object_dead;
52262
52263-atomic_t fscache_n_checkaux_none;
52264-atomic_t fscache_n_checkaux_okay;
52265-atomic_t fscache_n_checkaux_update;
52266-atomic_t fscache_n_checkaux_obsolete;
52267+atomic_unchecked_t fscache_n_checkaux_none;
52268+atomic_unchecked_t fscache_n_checkaux_okay;
52269+atomic_unchecked_t fscache_n_checkaux_update;
52270+atomic_unchecked_t fscache_n_checkaux_obsolete;
52271
52272 atomic_t fscache_n_cop_alloc_object;
52273 atomic_t fscache_n_cop_lookup_object;
52274@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
52275 seq_puts(m, "FS-Cache statistics\n");
52276
52277 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
52278- atomic_read(&fscache_n_cookie_index),
52279- atomic_read(&fscache_n_cookie_data),
52280- atomic_read(&fscache_n_cookie_special));
52281+ atomic_read_unchecked(&fscache_n_cookie_index),
52282+ atomic_read_unchecked(&fscache_n_cookie_data),
52283+ atomic_read_unchecked(&fscache_n_cookie_special));
52284
52285 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
52286- atomic_read(&fscache_n_object_alloc),
52287- atomic_read(&fscache_n_object_no_alloc),
52288- atomic_read(&fscache_n_object_avail),
52289- atomic_read(&fscache_n_object_dead));
52290+ atomic_read_unchecked(&fscache_n_object_alloc),
52291+ atomic_read_unchecked(&fscache_n_object_no_alloc),
52292+ atomic_read_unchecked(&fscache_n_object_avail),
52293+ atomic_read_unchecked(&fscache_n_object_dead));
52294 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
52295- atomic_read(&fscache_n_checkaux_none),
52296- atomic_read(&fscache_n_checkaux_okay),
52297- atomic_read(&fscache_n_checkaux_update),
52298- atomic_read(&fscache_n_checkaux_obsolete));
52299+ atomic_read_unchecked(&fscache_n_checkaux_none),
52300+ atomic_read_unchecked(&fscache_n_checkaux_okay),
52301+ atomic_read_unchecked(&fscache_n_checkaux_update),
52302+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
52303
52304 seq_printf(m, "Pages : mrk=%u unc=%u\n",
52305- atomic_read(&fscache_n_marks),
52306- atomic_read(&fscache_n_uncaches));
52307+ atomic_read_unchecked(&fscache_n_marks),
52308+ atomic_read_unchecked(&fscache_n_uncaches));
52309
52310 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
52311 " oom=%u\n",
52312- atomic_read(&fscache_n_acquires),
52313- atomic_read(&fscache_n_acquires_null),
52314- atomic_read(&fscache_n_acquires_no_cache),
52315- atomic_read(&fscache_n_acquires_ok),
52316- atomic_read(&fscache_n_acquires_nobufs),
52317- atomic_read(&fscache_n_acquires_oom));
52318+ atomic_read_unchecked(&fscache_n_acquires),
52319+ atomic_read_unchecked(&fscache_n_acquires_null),
52320+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
52321+ atomic_read_unchecked(&fscache_n_acquires_ok),
52322+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
52323+ atomic_read_unchecked(&fscache_n_acquires_oom));
52324
52325 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
52326- atomic_read(&fscache_n_object_lookups),
52327- atomic_read(&fscache_n_object_lookups_negative),
52328- atomic_read(&fscache_n_object_lookups_positive),
52329- atomic_read(&fscache_n_object_created),
52330- atomic_read(&fscache_n_object_lookups_timed_out));
52331+ atomic_read_unchecked(&fscache_n_object_lookups),
52332+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
52333+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
52334+ atomic_read_unchecked(&fscache_n_object_created),
52335+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
52336
52337 seq_printf(m, "Invals : n=%u run=%u\n",
52338- atomic_read(&fscache_n_invalidates),
52339- atomic_read(&fscache_n_invalidates_run));
52340+ atomic_read_unchecked(&fscache_n_invalidates),
52341+ atomic_read_unchecked(&fscache_n_invalidates_run));
52342
52343 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
52344- atomic_read(&fscache_n_updates),
52345- atomic_read(&fscache_n_updates_null),
52346- atomic_read(&fscache_n_updates_run));
52347+ atomic_read_unchecked(&fscache_n_updates),
52348+ atomic_read_unchecked(&fscache_n_updates_null),
52349+ atomic_read_unchecked(&fscache_n_updates_run));
52350
52351 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
52352- atomic_read(&fscache_n_relinquishes),
52353- atomic_read(&fscache_n_relinquishes_null),
52354- atomic_read(&fscache_n_relinquishes_waitcrt),
52355- atomic_read(&fscache_n_relinquishes_retire));
52356+ atomic_read_unchecked(&fscache_n_relinquishes),
52357+ atomic_read_unchecked(&fscache_n_relinquishes_null),
52358+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
52359+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
52360
52361 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
52362- atomic_read(&fscache_n_attr_changed),
52363- atomic_read(&fscache_n_attr_changed_ok),
52364- atomic_read(&fscache_n_attr_changed_nobufs),
52365- atomic_read(&fscache_n_attr_changed_nomem),
52366- atomic_read(&fscache_n_attr_changed_calls));
52367+ atomic_read_unchecked(&fscache_n_attr_changed),
52368+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
52369+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
52370+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
52371+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
52372
52373 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
52374- atomic_read(&fscache_n_allocs),
52375- atomic_read(&fscache_n_allocs_ok),
52376- atomic_read(&fscache_n_allocs_wait),
52377- atomic_read(&fscache_n_allocs_nobufs),
52378- atomic_read(&fscache_n_allocs_intr));
52379+ atomic_read_unchecked(&fscache_n_allocs),
52380+ atomic_read_unchecked(&fscache_n_allocs_ok),
52381+ atomic_read_unchecked(&fscache_n_allocs_wait),
52382+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
52383+ atomic_read_unchecked(&fscache_n_allocs_intr));
52384 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
52385- atomic_read(&fscache_n_alloc_ops),
52386- atomic_read(&fscache_n_alloc_op_waits),
52387- atomic_read(&fscache_n_allocs_object_dead));
52388+ atomic_read_unchecked(&fscache_n_alloc_ops),
52389+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
52390+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
52391
52392 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52393 " int=%u oom=%u\n",
52394- atomic_read(&fscache_n_retrievals),
52395- atomic_read(&fscache_n_retrievals_ok),
52396- atomic_read(&fscache_n_retrievals_wait),
52397- atomic_read(&fscache_n_retrievals_nodata),
52398- atomic_read(&fscache_n_retrievals_nobufs),
52399- atomic_read(&fscache_n_retrievals_intr),
52400- atomic_read(&fscache_n_retrievals_nomem));
52401+ atomic_read_unchecked(&fscache_n_retrievals),
52402+ atomic_read_unchecked(&fscache_n_retrievals_ok),
52403+ atomic_read_unchecked(&fscache_n_retrievals_wait),
52404+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
52405+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52406+ atomic_read_unchecked(&fscache_n_retrievals_intr),
52407+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
52408 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52409- atomic_read(&fscache_n_retrieval_ops),
52410- atomic_read(&fscache_n_retrieval_op_waits),
52411- atomic_read(&fscache_n_retrievals_object_dead));
52412+ atomic_read_unchecked(&fscache_n_retrieval_ops),
52413+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52414+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52415
52416 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52417- atomic_read(&fscache_n_stores),
52418- atomic_read(&fscache_n_stores_ok),
52419- atomic_read(&fscache_n_stores_again),
52420- atomic_read(&fscache_n_stores_nobufs),
52421- atomic_read(&fscache_n_stores_oom));
52422+ atomic_read_unchecked(&fscache_n_stores),
52423+ atomic_read_unchecked(&fscache_n_stores_ok),
52424+ atomic_read_unchecked(&fscache_n_stores_again),
52425+ atomic_read_unchecked(&fscache_n_stores_nobufs),
52426+ atomic_read_unchecked(&fscache_n_stores_oom));
52427 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52428- atomic_read(&fscache_n_store_ops),
52429- atomic_read(&fscache_n_store_calls),
52430- atomic_read(&fscache_n_store_pages),
52431- atomic_read(&fscache_n_store_radix_deletes),
52432- atomic_read(&fscache_n_store_pages_over_limit));
52433+ atomic_read_unchecked(&fscache_n_store_ops),
52434+ atomic_read_unchecked(&fscache_n_store_calls),
52435+ atomic_read_unchecked(&fscache_n_store_pages),
52436+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
52437+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52438
52439 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52440- atomic_read(&fscache_n_store_vmscan_not_storing),
52441- atomic_read(&fscache_n_store_vmscan_gone),
52442- atomic_read(&fscache_n_store_vmscan_busy),
52443- atomic_read(&fscache_n_store_vmscan_cancelled),
52444- atomic_read(&fscache_n_store_vmscan_wait));
52445+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52446+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52447+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52448+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52449+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52450
52451 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52452- atomic_read(&fscache_n_op_pend),
52453- atomic_read(&fscache_n_op_run),
52454- atomic_read(&fscache_n_op_enqueue),
52455- atomic_read(&fscache_n_op_cancelled),
52456- atomic_read(&fscache_n_op_rejected));
52457+ atomic_read_unchecked(&fscache_n_op_pend),
52458+ atomic_read_unchecked(&fscache_n_op_run),
52459+ atomic_read_unchecked(&fscache_n_op_enqueue),
52460+ atomic_read_unchecked(&fscache_n_op_cancelled),
52461+ atomic_read_unchecked(&fscache_n_op_rejected));
52462 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52463- atomic_read(&fscache_n_op_deferred_release),
52464- atomic_read(&fscache_n_op_release),
52465- atomic_read(&fscache_n_op_gc));
52466+ atomic_read_unchecked(&fscache_n_op_deferred_release),
52467+ atomic_read_unchecked(&fscache_n_op_release),
52468+ atomic_read_unchecked(&fscache_n_op_gc));
52469
52470 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52471 atomic_read(&fscache_n_cop_alloc_object),
52472diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52473index e397b67..b0d8709 100644
52474--- a/fs/fuse/cuse.c
52475+++ b/fs/fuse/cuse.c
52476@@ -593,10 +593,12 @@ static int __init cuse_init(void)
52477 INIT_LIST_HEAD(&cuse_conntbl[i]);
52478
52479 /* inherit and extend fuse_dev_operations */
52480- cuse_channel_fops = fuse_dev_operations;
52481- cuse_channel_fops.owner = THIS_MODULE;
52482- cuse_channel_fops.open = cuse_channel_open;
52483- cuse_channel_fops.release = cuse_channel_release;
52484+ pax_open_kernel();
52485+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52486+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52487+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
52488+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
52489+ pax_close_kernel();
52490
52491 cuse_class = class_create(THIS_MODULE, "cuse");
52492 if (IS_ERR(cuse_class))
52493diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52494index e83351a..41e3c9c 100644
52495--- a/fs/fuse/dev.c
52496+++ b/fs/fuse/dev.c
52497@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52498 ret = 0;
52499 pipe_lock(pipe);
52500
52501- if (!pipe->readers) {
52502+ if (!atomic_read(&pipe->readers)) {
52503 send_sig(SIGPIPE, current, 0);
52504 if (!ret)
52505 ret = -EPIPE;
52506diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52507index 315e1f8..91f890c 100644
52508--- a/fs/fuse/dir.c
52509+++ b/fs/fuse/dir.c
52510@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
52511 return link;
52512 }
52513
52514-static void free_link(char *link)
52515+static void free_link(const char *link)
52516 {
52517 if (!IS_ERR(link))
52518 free_page((unsigned long) link);
52519diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52520index 2b6f569..fcb4d1f 100644
52521--- a/fs/gfs2/inode.c
52522+++ b/fs/gfs2/inode.c
52523@@ -1499,7 +1499,7 @@ out:
52524
52525 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52526 {
52527- char *s = nd_get_link(nd);
52528+ const char *s = nd_get_link(nd);
52529 if (!IS_ERR(s))
52530 kfree(s);
52531 }
52532diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52533index 78bde32..767e906 100644
52534--- a/fs/hugetlbfs/inode.c
52535+++ b/fs/hugetlbfs/inode.c
52536@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52537 struct mm_struct *mm = current->mm;
52538 struct vm_area_struct *vma;
52539 struct hstate *h = hstate_file(file);
52540+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52541 struct vm_unmapped_area_info info;
52542
52543 if (len & ~huge_page_mask(h))
52544@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52545 return addr;
52546 }
52547
52548+#ifdef CONFIG_PAX_RANDMMAP
52549+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52550+#endif
52551+
52552 if (addr) {
52553 addr = ALIGN(addr, huge_page_size(h));
52554 vma = find_vma(mm, addr);
52555- if (TASK_SIZE - len >= addr &&
52556- (!vma || addr + len <= vma->vm_start))
52557+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52558 return addr;
52559 }
52560
52561 info.flags = 0;
52562 info.length = len;
52563 info.low_limit = TASK_UNMAPPED_BASE;
52564+
52565+#ifdef CONFIG_PAX_RANDMMAP
52566+ if (mm->pax_flags & MF_PAX_RANDMMAP)
52567+ info.low_limit += mm->delta_mmap;
52568+#endif
52569+
52570 info.high_limit = TASK_SIZE;
52571 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52572 info.align_offset = 0;
52573@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52574 .kill_sb = kill_litter_super,
52575 };
52576
52577-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52578+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52579
52580 static int can_do_hugetlb_shm(void)
52581 {
52582diff --git a/fs/inode.c b/fs/inode.c
52583index 14084b7..29af1d9 100644
52584--- a/fs/inode.c
52585+++ b/fs/inode.c
52586@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
52587
52588 #ifdef CONFIG_SMP
52589 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52590- static atomic_t shared_last_ino;
52591- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52592+ static atomic_unchecked_t shared_last_ino;
52593+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52594
52595 res = next - LAST_INO_BATCH;
52596 }
52597diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52598index 4a6cf28..d3a29d3 100644
52599--- a/fs/jffs2/erase.c
52600+++ b/fs/jffs2/erase.c
52601@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52602 struct jffs2_unknown_node marker = {
52603 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52604 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52605- .totlen = cpu_to_je32(c->cleanmarker_size)
52606+ .totlen = cpu_to_je32(c->cleanmarker_size),
52607+ .hdr_crc = cpu_to_je32(0)
52608 };
52609
52610 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52611diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52612index a6597d6..41b30ec 100644
52613--- a/fs/jffs2/wbuf.c
52614+++ b/fs/jffs2/wbuf.c
52615@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52616 {
52617 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52618 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52619- .totlen = constant_cpu_to_je32(8)
52620+ .totlen = constant_cpu_to_je32(8),
52621+ .hdr_crc = constant_cpu_to_je32(0)
52622 };
52623
52624 /*
52625diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52626index 1a543be..a4e1363 100644
52627--- a/fs/jfs/super.c
52628+++ b/fs/jfs/super.c
52629@@ -225,7 +225,7 @@ static const match_table_t tokens = {
52630 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52631 int *flag)
52632 {
52633- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
52634+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
52635 char *p;
52636 struct jfs_sb_info *sbi = JFS_SBI(sb);
52637
52638@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52639 /* Don't do anything ;-) */
52640 break;
52641 case Opt_iocharset:
52642- if (nls_map && nls_map != (void *) -1)
52643+ if (nls_map && nls_map != (const void *) -1)
52644 unload_nls(nls_map);
52645 if (!strcmp(args[0].from, "none"))
52646 nls_map = NULL;
52647@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
52648
52649 jfs_inode_cachep =
52650 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52651- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52652+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52653 init_once);
52654 if (jfs_inode_cachep == NULL)
52655 return -ENOMEM;
52656diff --git a/fs/libfs.c b/fs/libfs.c
52657index 916da8c..1588998 100644
52658--- a/fs/libfs.c
52659+++ b/fs/libfs.c
52660@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52661
52662 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52663 struct dentry *next;
52664+ char d_name[sizeof(next->d_iname)];
52665+ const unsigned char *name;
52666+
52667 next = list_entry(p, struct dentry, d_u.d_child);
52668 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52669 if (!simple_positive(next)) {
52670@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52671
52672 spin_unlock(&next->d_lock);
52673 spin_unlock(&dentry->d_lock);
52674- if (filldir(dirent, next->d_name.name,
52675+ name = next->d_name.name;
52676+ if (name == next->d_iname) {
52677+ memcpy(d_name, name, next->d_name.len);
52678+ name = d_name;
52679+ }
52680+ if (filldir(dirent, name,
52681 next->d_name.len, filp->f_pos,
52682 next->d_inode->i_ino,
52683 dt_type(next->d_inode)) < 0)
52684diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52685index 52e5120..808936e 100644
52686--- a/fs/lockd/clntproc.c
52687+++ b/fs/lockd/clntproc.c
52688@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52689 /*
52690 * Cookie counter for NLM requests
52691 */
52692-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52693+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52694
52695 void nlmclnt_next_cookie(struct nlm_cookie *c)
52696 {
52697- u32 cookie = atomic_inc_return(&nlm_cookie);
52698+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52699
52700 memcpy(c->data, &cookie, 4);
52701 c->len=4;
52702diff --git a/fs/locks.c b/fs/locks.c
52703index a94e331..060bce3 100644
52704--- a/fs/locks.c
52705+++ b/fs/locks.c
52706@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52707 return;
52708
52709 if (filp->f_op && filp->f_op->flock) {
52710- struct file_lock fl = {
52711+ struct file_lock flock = {
52712 .fl_pid = current->tgid,
52713 .fl_file = filp,
52714 .fl_flags = FL_FLOCK,
52715 .fl_type = F_UNLCK,
52716 .fl_end = OFFSET_MAX,
52717 };
52718- filp->f_op->flock(filp, F_SETLKW, &fl);
52719- if (fl.fl_ops && fl.fl_ops->fl_release_private)
52720- fl.fl_ops->fl_release_private(&fl);
52721+ filp->f_op->flock(filp, F_SETLKW, &flock);
52722+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
52723+ flock.fl_ops->fl_release_private(&flock);
52724 }
52725
52726 lock_flocks();
52727diff --git a/fs/namei.c b/fs/namei.c
52728index ec97aef..6e33759 100644
52729--- a/fs/namei.c
52730+++ b/fs/namei.c
52731@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52732 if (ret != -EACCES)
52733 return ret;
52734
52735+#ifdef CONFIG_GRKERNSEC
52736+ /* we'll block if we have to log due to a denied capability use */
52737+ if (mask & MAY_NOT_BLOCK)
52738+ return -ECHILD;
52739+#endif
52740+
52741 if (S_ISDIR(inode->i_mode)) {
52742 /* DACs are overridable for directories */
52743- if (inode_capable(inode, CAP_DAC_OVERRIDE))
52744- return 0;
52745 if (!(mask & MAY_WRITE))
52746- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52747+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52748+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52749 return 0;
52750+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
52751+ return 0;
52752 return -EACCES;
52753 }
52754 /*
52755+ * Searching includes executable on directories, else just read.
52756+ */
52757+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52758+ if (mask == MAY_READ)
52759+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52760+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52761+ return 0;
52762+
52763+ /*
52764 * Read/write DACs are always overridable.
52765 * Executable DACs are overridable when there is
52766 * at least one exec bit set.
52767@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
52768 if (inode_capable(inode, CAP_DAC_OVERRIDE))
52769 return 0;
52770
52771- /*
52772- * Searching includes executable on directories, else just read.
52773- */
52774- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52775- if (mask == MAY_READ)
52776- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52777- return 0;
52778-
52779 return -EACCES;
52780 }
52781
52782@@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52783 {
52784 struct dentry *dentry = link->dentry;
52785 int error;
52786- char *s;
52787+ const char *s;
52788
52789 BUG_ON(nd->flags & LOOKUP_RCU);
52790
52791@@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52792 if (error)
52793 goto out_put_nd_path;
52794
52795+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
52796+ dentry->d_inode, dentry, nd->path.mnt)) {
52797+ error = -EACCES;
52798+ goto out_put_nd_path;
52799+ }
52800+
52801 nd->last_type = LAST_BIND;
52802 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
52803 error = PTR_ERR(*p);
52804@@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
52805 break;
52806 res = walk_component(nd, path, &nd->last,
52807 nd->last_type, LOOKUP_FOLLOW);
52808+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
52809+ res = -EACCES;
52810 put_link(nd, &link, cookie);
52811 } while (res > 0);
52812
52813@@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
52814 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
52815 {
52816 unsigned long a, b, adata, bdata, mask, hash, len;
52817- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52818+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52819
52820 hash = a = 0;
52821 len = -sizeof(unsigned long);
52822@@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
52823 if (err)
52824 break;
52825 err = lookup_last(nd, &path);
52826+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
52827+ err = -EACCES;
52828 put_link(nd, &link, cookie);
52829 }
52830 }
52831@@ -1984,6 +2002,19 @@ static int path_lookupat(int dfd, const char *name,
52832 if (!err)
52833 err = complete_walk(nd);
52834
52835+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
52836+#ifdef CONFIG_GRKERNSEC
52837+ if (flags & LOOKUP_RCU) {
52838+ path_put(&nd->path);
52839+ err = -ECHILD;
52840+ } else
52841+#endif
52842+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52843+ path_put(&nd->path);
52844+ err = -ENOENT;
52845+ }
52846+ }
52847+
52848 if (!err && nd->flags & LOOKUP_DIRECTORY) {
52849 if (!nd->inode->i_op->lookup) {
52850 path_put(&nd->path);
52851@@ -2011,8 +2042,21 @@ static int filename_lookup(int dfd, struct filename *name,
52852 retval = path_lookupat(dfd, name->name,
52853 flags | LOOKUP_REVAL, nd);
52854
52855- if (likely(!retval))
52856+ if (likely(!retval)) {
52857 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
52858+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
52859+#ifdef CONFIG_GRKERNSEC
52860+ if (flags & LOOKUP_RCU) {
52861+ path_put(&nd->path);
52862+ return -ECHILD;
52863+ }
52864+#endif
52865+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
52866+ path_put(&nd->path);
52867+ return -ENOENT;
52868+ }
52869+ }
52870+ }
52871 return retval;
52872 }
52873
52874@@ -2390,6 +2434,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
52875 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
52876 return -EPERM;
52877
52878+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
52879+ return -EPERM;
52880+ if (gr_handle_rawio(inode))
52881+ return -EPERM;
52882+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
52883+ return -EACCES;
52884+
52885 return 0;
52886 }
52887
52888@@ -2611,7 +2662,7 @@ looked_up:
52889 * cleared otherwise prior to returning.
52890 */
52891 static int lookup_open(struct nameidata *nd, struct path *path,
52892- struct file *file,
52893+ struct path *link, struct file *file,
52894 const struct open_flags *op,
52895 bool got_write, int *opened)
52896 {
52897@@ -2646,6 +2697,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52898 /* Negative dentry, just create the file */
52899 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
52900 umode_t mode = op->mode;
52901+
52902+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
52903+ error = -EACCES;
52904+ goto out_dput;
52905+ }
52906+
52907+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
52908+ error = -EACCES;
52909+ goto out_dput;
52910+ }
52911+
52912 if (!IS_POSIXACL(dir->d_inode))
52913 mode &= ~current_umask();
52914 /*
52915@@ -2667,6 +2729,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52916 nd->flags & LOOKUP_EXCL);
52917 if (error)
52918 goto out_dput;
52919+ else
52920+ gr_handle_create(dentry, nd->path.mnt);
52921 }
52922 out_no_open:
52923 path->dentry = dentry;
52924@@ -2681,7 +2745,7 @@ out_dput:
52925 /*
52926 * Handle the last step of open()
52927 */
52928-static int do_last(struct nameidata *nd, struct path *path,
52929+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
52930 struct file *file, const struct open_flags *op,
52931 int *opened, struct filename *name)
52932 {
52933@@ -2710,16 +2774,44 @@ static int do_last(struct nameidata *nd, struct path *path,
52934 error = complete_walk(nd);
52935 if (error)
52936 return error;
52937+#ifdef CONFIG_GRKERNSEC
52938+ if (nd->flags & LOOKUP_RCU) {
52939+ error = -ECHILD;
52940+ goto out;
52941+ }
52942+#endif
52943+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52944+ error = -ENOENT;
52945+ goto out;
52946+ }
52947 audit_inode(name, nd->path.dentry, 0);
52948 if (open_flag & O_CREAT) {
52949 error = -EISDIR;
52950 goto out;
52951 }
52952+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
52953+ error = -EACCES;
52954+ goto out;
52955+ }
52956 goto finish_open;
52957 case LAST_BIND:
52958 error = complete_walk(nd);
52959 if (error)
52960 return error;
52961+#ifdef CONFIG_GRKERNSEC
52962+ if (nd->flags & LOOKUP_RCU) {
52963+ error = -ECHILD;
52964+ goto out;
52965+ }
52966+#endif
52967+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
52968+ error = -ENOENT;
52969+ goto out;
52970+ }
52971+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
52972+ error = -EACCES;
52973+ goto out;
52974+ }
52975 audit_inode(name, dir, 0);
52976 goto finish_open;
52977 }
52978@@ -2768,7 +2860,7 @@ retry_lookup:
52979 */
52980 }
52981 mutex_lock(&dir->d_inode->i_mutex);
52982- error = lookup_open(nd, path, file, op, got_write, opened);
52983+ error = lookup_open(nd, path, link, file, op, got_write, opened);
52984 mutex_unlock(&dir->d_inode->i_mutex);
52985
52986 if (error <= 0) {
52987@@ -2792,11 +2884,28 @@ retry_lookup:
52988 goto finish_open_created;
52989 }
52990
52991+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
52992+ error = -ENOENT;
52993+ goto exit_dput;
52994+ }
52995+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
52996+ error = -EACCES;
52997+ goto exit_dput;
52998+ }
52999+
53000 /*
53001 * create/update audit record if it already exists.
53002 */
53003- if (path->dentry->d_inode)
53004+ if (path->dentry->d_inode) {
53005+ /* only check if O_CREAT is specified, all other checks need to go
53006+ into may_open */
53007+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53008+ error = -EACCES;
53009+ goto exit_dput;
53010+ }
53011+
53012 audit_inode(name, path->dentry, 0);
53013+ }
53014
53015 /*
53016 * If atomic_open() acquired write access it is dropped now due to
53017@@ -2837,6 +2946,11 @@ finish_lookup:
53018 }
53019 }
53020 BUG_ON(inode != path->dentry->d_inode);
53021+ /* if we're resolving a symlink to another symlink */
53022+ if (link && gr_handle_symlink_owner(link, inode)) {
53023+ error = -EACCES;
53024+ goto out;
53025+ }
53026 return 1;
53027 }
53028
53029@@ -2846,7 +2960,6 @@ finish_lookup:
53030 save_parent.dentry = nd->path.dentry;
53031 save_parent.mnt = mntget(path->mnt);
53032 nd->path.dentry = path->dentry;
53033-
53034 }
53035 nd->inode = inode;
53036 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53037@@ -2855,6 +2968,22 @@ finish_lookup:
53038 path_put(&save_parent);
53039 return error;
53040 }
53041+
53042+#ifdef CONFIG_GRKERNSEC
53043+ if (nd->flags & LOOKUP_RCU) {
53044+ error = -ECHILD;
53045+ goto out;
53046+ }
53047+#endif
53048+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53049+ error = -ENOENT;
53050+ goto out;
53051+ }
53052+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53053+ error = -EACCES;
53054+ goto out;
53055+ }
53056+
53057 error = -EISDIR;
53058 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53059 goto out;
53060@@ -2953,7 +3082,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53061 if (unlikely(error))
53062 goto out;
53063
53064- error = do_last(nd, &path, file, op, &opened, pathname);
53065+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53066 while (unlikely(error > 0)) { /* trailing symlink */
53067 struct path link = path;
53068 void *cookie;
53069@@ -2971,7 +3100,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53070 error = follow_link(&link, nd, &cookie);
53071 if (unlikely(error))
53072 break;
53073- error = do_last(nd, &path, file, op, &opened, pathname);
53074+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53075 put_link(nd, &link, cookie);
53076 }
53077 out:
53078@@ -3071,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53079 goto unlock;
53080
53081 error = -EEXIST;
53082- if (dentry->d_inode)
53083+ if (dentry->d_inode) {
53084+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53085+ error = -ENOENT;
53086+ }
53087 goto fail;
53088+ }
53089 /*
53090 * Special case - lookup gave negative, but... we had foo/bar/
53091 * From the vfs_mknod() POV we just have a negative dentry -
53092@@ -3124,6 +3257,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53093 }
53094 EXPORT_SYMBOL(user_path_create);
53095
53096+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53097+{
53098+ struct filename *tmp = getname(pathname);
53099+ struct dentry *res;
53100+ if (IS_ERR(tmp))
53101+ return ERR_CAST(tmp);
53102+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53103+ if (IS_ERR(res))
53104+ putname(tmp);
53105+ else
53106+ *to = tmp;
53107+ return res;
53108+}
53109+
53110 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53111 {
53112 int error = may_create(dir, dentry);
53113@@ -3186,6 +3333,17 @@ retry:
53114
53115 if (!IS_POSIXACL(path.dentry->d_inode))
53116 mode &= ~current_umask();
53117+
53118+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53119+ error = -EPERM;
53120+ goto out;
53121+ }
53122+
53123+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53124+ error = -EACCES;
53125+ goto out;
53126+ }
53127+
53128 error = security_path_mknod(&path, dentry, mode, dev);
53129 if (error)
53130 goto out;
53131@@ -3202,6 +3360,8 @@ retry:
53132 break;
53133 }
53134 out:
53135+ if (!error)
53136+ gr_handle_create(dentry, path.mnt);
53137 done_path_create(&path, dentry);
53138 if (retry_estale(error, lookup_flags)) {
53139 lookup_flags |= LOOKUP_REVAL;
53140@@ -3254,9 +3414,16 @@ retry:
53141
53142 if (!IS_POSIXACL(path.dentry->d_inode))
53143 mode &= ~current_umask();
53144+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53145+ error = -EACCES;
53146+ goto out;
53147+ }
53148 error = security_path_mkdir(&path, dentry, mode);
53149 if (!error)
53150 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53151+ if (!error)
53152+ gr_handle_create(dentry, path.mnt);
53153+out:
53154 done_path_create(&path, dentry);
53155 if (retry_estale(error, lookup_flags)) {
53156 lookup_flags |= LOOKUP_REVAL;
53157@@ -3337,6 +3504,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53158 struct filename *name;
53159 struct dentry *dentry;
53160 struct nameidata nd;
53161+ ino_t saved_ino = 0;
53162+ dev_t saved_dev = 0;
53163 unsigned int lookup_flags = 0;
53164 retry:
53165 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53166@@ -3369,10 +3538,21 @@ retry:
53167 error = -ENOENT;
53168 goto exit3;
53169 }
53170+
53171+ saved_ino = dentry->d_inode->i_ino;
53172+ saved_dev = gr_get_dev_from_dentry(dentry);
53173+
53174+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53175+ error = -EACCES;
53176+ goto exit3;
53177+ }
53178+
53179 error = security_path_rmdir(&nd.path, dentry);
53180 if (error)
53181 goto exit3;
53182 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53183+ if (!error && (saved_dev || saved_ino))
53184+ gr_handle_delete(saved_ino, saved_dev);
53185 exit3:
53186 dput(dentry);
53187 exit2:
53188@@ -3438,6 +3618,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53189 struct dentry *dentry;
53190 struct nameidata nd;
53191 struct inode *inode = NULL;
53192+ ino_t saved_ino = 0;
53193+ dev_t saved_dev = 0;
53194 unsigned int lookup_flags = 0;
53195 retry:
53196 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53197@@ -3464,10 +3646,22 @@ retry:
53198 if (!inode)
53199 goto slashes;
53200 ihold(inode);
53201+
53202+ if (inode->i_nlink <= 1) {
53203+ saved_ino = inode->i_ino;
53204+ saved_dev = gr_get_dev_from_dentry(dentry);
53205+ }
53206+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53207+ error = -EACCES;
53208+ goto exit2;
53209+ }
53210+
53211 error = security_path_unlink(&nd.path, dentry);
53212 if (error)
53213 goto exit2;
53214 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53215+ if (!error && (saved_ino || saved_dev))
53216+ gr_handle_delete(saved_ino, saved_dev);
53217 exit2:
53218 dput(dentry);
53219 }
53220@@ -3545,9 +3739,17 @@ retry:
53221 if (IS_ERR(dentry))
53222 goto out_putname;
53223
53224+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
53225+ error = -EACCES;
53226+ goto out;
53227+ }
53228+
53229 error = security_path_symlink(&path, dentry, from->name);
53230 if (!error)
53231 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
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@@ -3621,6 +3823,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
53239 {
53240 struct dentry *new_dentry;
53241 struct path old_path, new_path;
53242+ struct filename *to = NULL;
53243 int how = 0;
53244 int error;
53245
53246@@ -3644,7 +3847,7 @@ retry:
53247 if (error)
53248 return error;
53249
53250- new_dentry = user_path_create(newdfd, newname, &new_path,
53251+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
53252 (how & LOOKUP_REVAL));
53253 error = PTR_ERR(new_dentry);
53254 if (IS_ERR(new_dentry))
53255@@ -3656,11 +3859,28 @@ retry:
53256 error = may_linkat(&old_path);
53257 if (unlikely(error))
53258 goto out_dput;
53259+
53260+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
53261+ old_path.dentry->d_inode,
53262+ old_path.dentry->d_inode->i_mode, to)) {
53263+ error = -EACCES;
53264+ goto out_dput;
53265+ }
53266+
53267+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
53268+ old_path.dentry, old_path.mnt, to)) {
53269+ error = -EACCES;
53270+ goto out_dput;
53271+ }
53272+
53273 error = security_path_link(old_path.dentry, &new_path, new_dentry);
53274 if (error)
53275 goto out_dput;
53276 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
53277+ if (!error)
53278+ gr_handle_create(new_dentry, new_path.mnt);
53279 out_dput:
53280+ putname(to);
53281 done_path_create(&new_path, new_dentry);
53282 if (retry_estale(error, how)) {
53283 how |= LOOKUP_REVAL;
53284@@ -3906,12 +4126,21 @@ retry:
53285 if (new_dentry == trap)
53286 goto exit5;
53287
53288+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
53289+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
53290+ to);
53291+ if (error)
53292+ goto exit5;
53293+
53294 error = security_path_rename(&oldnd.path, old_dentry,
53295 &newnd.path, new_dentry);
53296 if (error)
53297 goto exit5;
53298 error = vfs_rename(old_dir->d_inode, old_dentry,
53299 new_dir->d_inode, new_dentry);
53300+ if (!error)
53301+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
53302+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
53303 exit5:
53304 dput(new_dentry);
53305 exit4:
53306@@ -3943,6 +4172,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
53307
53308 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
53309 {
53310+ char tmpbuf[64];
53311+ const char *newlink;
53312 int len;
53313
53314 len = PTR_ERR(link);
53315@@ -3952,7 +4183,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
53316 len = strlen(link);
53317 if (len > (unsigned) buflen)
53318 len = buflen;
53319- if (copy_to_user(buffer, link, len))
53320+
53321+ if (len < sizeof(tmpbuf)) {
53322+ memcpy(tmpbuf, link, len);
53323+ newlink = tmpbuf;
53324+ } else
53325+ newlink = link;
53326+
53327+ if (copy_to_user(buffer, newlink, len))
53328 len = -EFAULT;
53329 out:
53330 return len;
53331diff --git a/fs/namespace.c b/fs/namespace.c
53332index a51054f..f9b53e5 100644
53333--- a/fs/namespace.c
53334+++ b/fs/namespace.c
53335@@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
53336 if (!(sb->s_flags & MS_RDONLY))
53337 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
53338 up_write(&sb->s_umount);
53339+
53340+ gr_log_remount(mnt->mnt_devname, retval);
53341+
53342 return retval;
53343 }
53344
53345@@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
53346 br_write_unlock(&vfsmount_lock);
53347 up_write(&namespace_sem);
53348 release_mounts(&umount_list);
53349+
53350+ gr_log_unmount(mnt->mnt_devname, retval);
53351+
53352 return retval;
53353 }
53354
53355@@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
53356 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
53357 MS_STRICTATIME);
53358
53359+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
53360+ retval = -EPERM;
53361+ goto dput_out;
53362+ }
53363+
53364+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
53365+ retval = -EPERM;
53366+ goto dput_out;
53367+ }
53368+
53369 if (flags & MS_REMOUNT)
53370 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
53371 data_page);
53372@@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
53373 dev_name, data_page);
53374 dput_out:
53375 path_put(&path);
53376+
53377+ gr_log_mount(dev_name, dir_name, retval);
53378+
53379 return retval;
53380 }
53381
53382@@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
53383 if (error)
53384 goto out2;
53385
53386+ if (gr_handle_chroot_pivot()) {
53387+ error = -EPERM;
53388+ goto out2;
53389+ }
53390+
53391 get_fs_root(current->fs, &root);
53392 error = lock_mount(&old);
53393 if (error)
53394@@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53395 !nsown_capable(CAP_SYS_ADMIN))
53396 return -EPERM;
53397
53398- if (fs->users != 1)
53399+ if (atomic_read(&fs->users) != 1)
53400 return -EINVAL;
53401
53402 get_mnt_ns(mnt_ns);
53403diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53404index 59461c9..b17c57e 100644
53405--- a/fs/nfs/callback_xdr.c
53406+++ b/fs/nfs/callback_xdr.c
53407@@ -51,7 +51,7 @@ struct callback_op {
53408 callback_decode_arg_t decode_args;
53409 callback_encode_res_t encode_res;
53410 long res_maxsize;
53411-};
53412+} __do_const;
53413
53414 static struct callback_op callback_ops[];
53415
53416diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53417index ebeb94c..ff35337 100644
53418--- a/fs/nfs/inode.c
53419+++ b/fs/nfs/inode.c
53420@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53421 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53422 }
53423
53424-static atomic_long_t nfs_attr_generation_counter;
53425+static atomic_long_unchecked_t nfs_attr_generation_counter;
53426
53427 static unsigned long nfs_read_attr_generation_counter(void)
53428 {
53429- return atomic_long_read(&nfs_attr_generation_counter);
53430+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53431 }
53432
53433 unsigned long nfs_inc_attr_generation_counter(void)
53434 {
53435- return atomic_long_inc_return(&nfs_attr_generation_counter);
53436+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53437 }
53438
53439 void nfs_fattr_init(struct nfs_fattr *fattr)
53440diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53441index 9d1c5db..1e13db8 100644
53442--- a/fs/nfsd/nfs4proc.c
53443+++ b/fs/nfsd/nfs4proc.c
53444@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
53445 nfsd4op_rsize op_rsize_bop;
53446 stateid_getter op_get_currentstateid;
53447 stateid_setter op_set_currentstateid;
53448-};
53449+} __do_const;
53450
53451 static struct nfsd4_operation nfsd4_ops[];
53452
53453diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53454index 0dc1158..ccf0338 100644
53455--- a/fs/nfsd/nfs4xdr.c
53456+++ b/fs/nfsd/nfs4xdr.c
53457@@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53458
53459 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53460
53461-static nfsd4_dec nfsd4_dec_ops[] = {
53462+static const nfsd4_dec nfsd4_dec_ops[] = {
53463 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53464 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53465 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53466@@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53467 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53468 };
53469
53470-static nfsd4_dec nfsd41_dec_ops[] = {
53471+static const nfsd4_dec nfsd41_dec_ops[] = {
53472 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53473 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53474 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53475@@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53476 };
53477
53478 struct nfsd4_minorversion_ops {
53479- nfsd4_dec *decoders;
53480+ const nfsd4_dec *decoders;
53481 int nops;
53482 };
53483
53484diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53485index d586117..143d568 100644
53486--- a/fs/nfsd/vfs.c
53487+++ b/fs/nfsd/vfs.c
53488@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53489 } else {
53490 oldfs = get_fs();
53491 set_fs(KERNEL_DS);
53492- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53493+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53494 set_fs(oldfs);
53495 }
53496
53497@@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53498
53499 /* Write the data. */
53500 oldfs = get_fs(); set_fs(KERNEL_DS);
53501- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
53502+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
53503 set_fs(oldfs);
53504 if (host_err < 0)
53505 goto out_nfserr;
53506@@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53507 */
53508
53509 oldfs = get_fs(); set_fs(KERNEL_DS);
53510- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53511+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53512 set_fs(oldfs);
53513
53514 if (host_err < 0)
53515diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53516index fea6bd5..8ee9d81 100644
53517--- a/fs/nls/nls_base.c
53518+++ b/fs/nls/nls_base.c
53519@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53520
53521 int register_nls(struct nls_table * nls)
53522 {
53523- struct nls_table ** tmp = &tables;
53524+ struct nls_table *tmp = tables;
53525
53526 if (nls->next)
53527 return -EBUSY;
53528
53529 spin_lock(&nls_lock);
53530- while (*tmp) {
53531- if (nls == *tmp) {
53532+ while (tmp) {
53533+ if (nls == tmp) {
53534 spin_unlock(&nls_lock);
53535 return -EBUSY;
53536 }
53537- tmp = &(*tmp)->next;
53538+ tmp = tmp->next;
53539 }
53540- nls->next = tables;
53541+ pax_open_kernel();
53542+ *(struct nls_table **)&nls->next = tables;
53543+ pax_close_kernel();
53544 tables = nls;
53545 spin_unlock(&nls_lock);
53546 return 0;
53547@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53548
53549 int unregister_nls(struct nls_table * nls)
53550 {
53551- struct nls_table ** tmp = &tables;
53552+ struct nls_table * const * tmp = &tables;
53553
53554 spin_lock(&nls_lock);
53555 while (*tmp) {
53556 if (nls == *tmp) {
53557- *tmp = nls->next;
53558+ pax_open_kernel();
53559+ *(struct nls_table **)tmp = nls->next;
53560+ pax_close_kernel();
53561 spin_unlock(&nls_lock);
53562 return 0;
53563 }
53564diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53565index 7424929..35f6be5 100644
53566--- a/fs/nls/nls_euc-jp.c
53567+++ b/fs/nls/nls_euc-jp.c
53568@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53569 p_nls = load_nls("cp932");
53570
53571 if (p_nls) {
53572- table.charset2upper = p_nls->charset2upper;
53573- table.charset2lower = p_nls->charset2lower;
53574+ pax_open_kernel();
53575+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53576+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53577+ pax_close_kernel();
53578 return register_nls(&table);
53579 }
53580
53581diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53582index e7bc1d7..06bd4bb 100644
53583--- a/fs/nls/nls_koi8-ru.c
53584+++ b/fs/nls/nls_koi8-ru.c
53585@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53586 p_nls = load_nls("koi8-u");
53587
53588 if (p_nls) {
53589- table.charset2upper = p_nls->charset2upper;
53590- table.charset2lower = p_nls->charset2lower;
53591+ pax_open_kernel();
53592+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53593+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53594+ pax_close_kernel();
53595 return register_nls(&table);
53596 }
53597
53598diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53599index 9ff4a5e..deb1f0f 100644
53600--- a/fs/notify/fanotify/fanotify_user.c
53601+++ b/fs/notify/fanotify/fanotify_user.c
53602@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53603
53604 fd = fanotify_event_metadata.fd;
53605 ret = -EFAULT;
53606- if (copy_to_user(buf, &fanotify_event_metadata,
53607- fanotify_event_metadata.event_len))
53608+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53609+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53610 goto out_close_fd;
53611
53612 ret = prepare_for_access_response(group, event, fd);
53613diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53614index 7b51b05..5ea5ef6 100644
53615--- a/fs/notify/notification.c
53616+++ b/fs/notify/notification.c
53617@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53618 * get set to 0 so it will never get 'freed'
53619 */
53620 static struct fsnotify_event *q_overflow_event;
53621-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53622+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53623
53624 /**
53625 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53626@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53627 */
53628 u32 fsnotify_get_cookie(void)
53629 {
53630- return atomic_inc_return(&fsnotify_sync_cookie);
53631+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53632 }
53633 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53634
53635diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53636index 99e3610..02c1068 100644
53637--- a/fs/ntfs/dir.c
53638+++ b/fs/ntfs/dir.c
53639@@ -1329,7 +1329,7 @@ find_next_index_buffer:
53640 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53641 ~(s64)(ndir->itype.index.block_size - 1)));
53642 /* Bounds checks. */
53643- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53644+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53645 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53646 "inode 0x%lx or driver bug.", vdir->i_ino);
53647 goto err_out;
53648diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53649index 5b2d4f0..c6de396 100644
53650--- a/fs/ntfs/file.c
53651+++ b/fs/ntfs/file.c
53652@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53653 #endif /* NTFS_RW */
53654 };
53655
53656-const struct file_operations ntfs_empty_file_ops = {};
53657+const struct file_operations ntfs_empty_file_ops __read_only;
53658
53659-const struct inode_operations ntfs_empty_inode_ops = {};
53660+const struct inode_operations ntfs_empty_inode_ops __read_only;
53661diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53662index a9f78c7..ed8a381 100644
53663--- a/fs/ocfs2/localalloc.c
53664+++ b/fs/ocfs2/localalloc.c
53665@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53666 goto bail;
53667 }
53668
53669- atomic_inc(&osb->alloc_stats.moves);
53670+ atomic_inc_unchecked(&osb->alloc_stats.moves);
53671
53672 bail:
53673 if (handle)
53674diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53675index d355e6e..578d905 100644
53676--- a/fs/ocfs2/ocfs2.h
53677+++ b/fs/ocfs2/ocfs2.h
53678@@ -235,11 +235,11 @@ enum ocfs2_vol_state
53679
53680 struct ocfs2_alloc_stats
53681 {
53682- atomic_t moves;
53683- atomic_t local_data;
53684- atomic_t bitmap_data;
53685- atomic_t bg_allocs;
53686- atomic_t bg_extends;
53687+ atomic_unchecked_t moves;
53688+ atomic_unchecked_t local_data;
53689+ atomic_unchecked_t bitmap_data;
53690+ atomic_unchecked_t bg_allocs;
53691+ atomic_unchecked_t bg_extends;
53692 };
53693
53694 enum ocfs2_local_alloc_state
53695diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53696index b7e74b5..19c6536 100644
53697--- a/fs/ocfs2/suballoc.c
53698+++ b/fs/ocfs2/suballoc.c
53699@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53700 mlog_errno(status);
53701 goto bail;
53702 }
53703- atomic_inc(&osb->alloc_stats.bg_extends);
53704+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53705
53706 /* You should never ask for this much metadata */
53707 BUG_ON(bits_wanted >
53708@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
53709 mlog_errno(status);
53710 goto bail;
53711 }
53712- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53713+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53714
53715 *suballoc_loc = res.sr_bg_blkno;
53716 *suballoc_bit_start = res.sr_bit_offset;
53717@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
53718 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
53719 res->sr_bits);
53720
53721- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53722+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53723
53724 BUG_ON(res->sr_bits != 1);
53725
53726@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
53727 mlog_errno(status);
53728 goto bail;
53729 }
53730- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53731+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53732
53733 BUG_ON(res.sr_bits != 1);
53734
53735@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53736 cluster_start,
53737 num_clusters);
53738 if (!status)
53739- atomic_inc(&osb->alloc_stats.local_data);
53740+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
53741 } else {
53742 if (min_clusters > (osb->bitmap_cpg - 1)) {
53743 /* The only paths asking for contiguousness
53744@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53745 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
53746 res.sr_bg_blkno,
53747 res.sr_bit_offset);
53748- atomic_inc(&osb->alloc_stats.bitmap_data);
53749+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
53750 *num_clusters = res.sr_bits;
53751 }
53752 }
53753diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
53754index 0e91ec2..f4b3fc6 100644
53755--- a/fs/ocfs2/super.c
53756+++ b/fs/ocfs2/super.c
53757@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
53758 "%10s => GlobalAllocs: %d LocalAllocs: %d "
53759 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
53760 "Stats",
53761- atomic_read(&osb->alloc_stats.bitmap_data),
53762- atomic_read(&osb->alloc_stats.local_data),
53763- atomic_read(&osb->alloc_stats.bg_allocs),
53764- atomic_read(&osb->alloc_stats.moves),
53765- atomic_read(&osb->alloc_stats.bg_extends));
53766+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
53767+ atomic_read_unchecked(&osb->alloc_stats.local_data),
53768+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
53769+ atomic_read_unchecked(&osb->alloc_stats.moves),
53770+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
53771
53772 out += snprintf(buf + out, len - out,
53773 "%10s => State: %u Descriptor: %llu Size: %u bits "
53774@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
53775 spin_lock_init(&osb->osb_xattr_lock);
53776 ocfs2_init_steal_slots(osb);
53777
53778- atomic_set(&osb->alloc_stats.moves, 0);
53779- atomic_set(&osb->alloc_stats.local_data, 0);
53780- atomic_set(&osb->alloc_stats.bitmap_data, 0);
53781- atomic_set(&osb->alloc_stats.bg_allocs, 0);
53782- atomic_set(&osb->alloc_stats.bg_extends, 0);
53783+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
53784+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
53785+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
53786+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
53787+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
53788
53789 /* Copy the blockcheck stats from the superblock probe */
53790 osb->osb_ecc_stats = *stats;
53791diff --git a/fs/open.c b/fs/open.c
53792index 9b33c0c..2ffcca2 100644
53793--- a/fs/open.c
53794+++ b/fs/open.c
53795@@ -31,6 +31,8 @@
53796 #include <linux/ima.h>
53797 #include <linux/dnotify.h>
53798
53799+#define CREATE_TRACE_POINTS
53800+#include <trace/events/fs.h>
53801 #include "internal.h"
53802
53803 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
53804@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
53805 error = locks_verify_truncate(inode, NULL, length);
53806 if (!error)
53807 error = security_path_truncate(path);
53808+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
53809+ error = -EACCES;
53810 if (!error)
53811 error = do_truncate(path->dentry, length, 0, NULL);
53812
53813@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
53814 error = locks_verify_truncate(inode, f.file, length);
53815 if (!error)
53816 error = security_path_truncate(&f.file->f_path);
53817+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
53818+ error = -EACCES;
53819 if (!error)
53820 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
53821 sb_end_write(inode->i_sb);
53822@@ -373,6 +379,9 @@ retry:
53823 if (__mnt_is_readonly(path.mnt))
53824 res = -EROFS;
53825
53826+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
53827+ res = -EACCES;
53828+
53829 out_path_release:
53830 path_put(&path);
53831 if (retry_estale(res, lookup_flags)) {
53832@@ -404,6 +413,8 @@ retry:
53833 if (error)
53834 goto dput_and_out;
53835
53836+ gr_log_chdir(path.dentry, path.mnt);
53837+
53838 set_fs_pwd(current->fs, &path);
53839
53840 dput_and_out:
53841@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
53842 goto out_putf;
53843
53844 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
53845+
53846+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
53847+ error = -EPERM;
53848+
53849+ if (!error)
53850+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
53851+
53852 if (!error)
53853 set_fs_pwd(current->fs, &f.file->f_path);
53854 out_putf:
53855@@ -462,7 +480,13 @@ retry:
53856 if (error)
53857 goto dput_and_out;
53858
53859+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
53860+ goto dput_and_out;
53861+
53862 set_fs_root(current->fs, &path);
53863+
53864+ gr_handle_chroot_chdir(&path);
53865+
53866 error = 0;
53867 dput_and_out:
53868 path_put(&path);
53869@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
53870 if (error)
53871 return error;
53872 mutex_lock(&inode->i_mutex);
53873+
53874+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
53875+ error = -EACCES;
53876+ goto out_unlock;
53877+ }
53878+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
53879+ error = -EACCES;
53880+ goto out_unlock;
53881+ }
53882+
53883 error = security_path_chmod(path, mode);
53884 if (error)
53885 goto out_unlock;
53886@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
53887 uid = make_kuid(current_user_ns(), user);
53888 gid = make_kgid(current_user_ns(), group);
53889
53890+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
53891+ return -EACCES;
53892+
53893 newattrs.ia_valid = ATTR_CTIME;
53894 if (user != (uid_t) -1) {
53895 if (!uid_valid(uid))
53896@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
53897 } else {
53898 fsnotify_open(f);
53899 fd_install(fd, f);
53900+ trace_do_sys_open(tmp->name, flags, mode);
53901 }
53902 }
53903 putname(tmp);
53904diff --git a/fs/pipe.c b/fs/pipe.c
53905index 8e2e73f..1ef1048 100644
53906--- a/fs/pipe.c
53907+++ b/fs/pipe.c
53908@@ -438,9 +438,9 @@ redo:
53909 }
53910 if (bufs) /* More to do? */
53911 continue;
53912- if (!pipe->writers)
53913+ if (!atomic_read(&pipe->writers))
53914 break;
53915- if (!pipe->waiting_writers) {
53916+ if (!atomic_read(&pipe->waiting_writers)) {
53917 /* syscall merging: Usually we must not sleep
53918 * if O_NONBLOCK is set, or if we got some data.
53919 * But if a writer sleeps in kernel space, then
53920@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
53921 mutex_lock(&inode->i_mutex);
53922 pipe = inode->i_pipe;
53923
53924- if (!pipe->readers) {
53925+ if (!atomic_read(&pipe->readers)) {
53926 send_sig(SIGPIPE, current, 0);
53927 ret = -EPIPE;
53928 goto out;
53929@@ -553,7 +553,7 @@ redo1:
53930 for (;;) {
53931 int bufs;
53932
53933- if (!pipe->readers) {
53934+ if (!atomic_read(&pipe->readers)) {
53935 send_sig(SIGPIPE, current, 0);
53936 if (!ret)
53937 ret = -EPIPE;
53938@@ -644,9 +644,9 @@ redo2:
53939 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
53940 do_wakeup = 0;
53941 }
53942- pipe->waiting_writers++;
53943+ atomic_inc(&pipe->waiting_writers);
53944 pipe_wait(pipe);
53945- pipe->waiting_writers--;
53946+ atomic_dec(&pipe->waiting_writers);
53947 }
53948 out:
53949 mutex_unlock(&inode->i_mutex);
53950@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53951 mask = 0;
53952 if (filp->f_mode & FMODE_READ) {
53953 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
53954- if (!pipe->writers && filp->f_version != pipe->w_counter)
53955+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
53956 mask |= POLLHUP;
53957 }
53958
53959@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53960 * Most Unices do not set POLLERR for FIFOs but on Linux they
53961 * behave exactly like pipes for poll().
53962 */
53963- if (!pipe->readers)
53964+ if (!atomic_read(&pipe->readers))
53965 mask |= POLLERR;
53966 }
53967
53968@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
53969
53970 mutex_lock(&inode->i_mutex);
53971 pipe = inode->i_pipe;
53972- pipe->readers -= decr;
53973- pipe->writers -= decw;
53974+ atomic_sub(decr, &pipe->readers);
53975+ atomic_sub(decw, &pipe->writers);
53976
53977- if (!pipe->readers && !pipe->writers) {
53978+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
53979 free_pipe_info(inode);
53980 } else {
53981 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
53982@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
53983
53984 if (inode->i_pipe) {
53985 ret = 0;
53986- inode->i_pipe->readers++;
53987+ atomic_inc(&inode->i_pipe->readers);
53988 }
53989
53990 mutex_unlock(&inode->i_mutex);
53991@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
53992
53993 if (inode->i_pipe) {
53994 ret = 0;
53995- inode->i_pipe->writers++;
53996+ atomic_inc(&inode->i_pipe->writers);
53997 }
53998
53999 mutex_unlock(&inode->i_mutex);
54000@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54001 if (inode->i_pipe) {
54002 ret = 0;
54003 if (filp->f_mode & FMODE_READ)
54004- inode->i_pipe->readers++;
54005+ atomic_inc(&inode->i_pipe->readers);
54006 if (filp->f_mode & FMODE_WRITE)
54007- inode->i_pipe->writers++;
54008+ atomic_inc(&inode->i_pipe->writers);
54009 }
54010
54011 mutex_unlock(&inode->i_mutex);
54012@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54013 inode->i_pipe = NULL;
54014 }
54015
54016-static struct vfsmount *pipe_mnt __read_mostly;
54017+struct vfsmount *pipe_mnt __read_mostly;
54018
54019 /*
54020 * pipefs_dname() is called from d_path().
54021@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54022 goto fail_iput;
54023 inode->i_pipe = pipe;
54024
54025- pipe->readers = pipe->writers = 1;
54026+ atomic_set(&pipe->readers, 1);
54027+ atomic_set(&pipe->writers, 1);
54028 inode->i_fop = &rdwr_pipefifo_fops;
54029
54030 /*
54031diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54032index 15af622..0e9f4467 100644
54033--- a/fs/proc/Kconfig
54034+++ b/fs/proc/Kconfig
54035@@ -30,12 +30,12 @@ config PROC_FS
54036
54037 config PROC_KCORE
54038 bool "/proc/kcore support" if !ARM
54039- depends on PROC_FS && MMU
54040+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54041
54042 config PROC_VMCORE
54043 bool "/proc/vmcore support"
54044- depends on PROC_FS && CRASH_DUMP
54045- default y
54046+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54047+ default n
54048 help
54049 Exports the dump image of crashed kernel in ELF format.
54050
54051@@ -59,8 +59,8 @@ config PROC_SYSCTL
54052 limited in memory.
54053
54054 config PROC_PAGE_MONITOR
54055- default y
54056- depends on PROC_FS && MMU
54057+ default n
54058+ depends on PROC_FS && MMU && !GRKERNSEC
54059 bool "Enable /proc page monitoring" if EXPERT
54060 help
54061 Various /proc files exist to monitor process memory utilization:
54062diff --git a/fs/proc/array.c b/fs/proc/array.c
54063index 6a91e6f..e54dbc14 100644
54064--- a/fs/proc/array.c
54065+++ b/fs/proc/array.c
54066@@ -60,6 +60,7 @@
54067 #include <linux/tty.h>
54068 #include <linux/string.h>
54069 #include <linux/mman.h>
54070+#include <linux/grsecurity.h>
54071 #include <linux/proc_fs.h>
54072 #include <linux/ioport.h>
54073 #include <linux/uaccess.h>
54074@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
54075 seq_putc(m, '\n');
54076 }
54077
54078+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54079+static inline void task_pax(struct seq_file *m, struct task_struct *p)
54080+{
54081+ if (p->mm)
54082+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
54083+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
54084+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
54085+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
54086+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
54087+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
54088+ else
54089+ seq_printf(m, "PaX:\t-----\n");
54090+}
54091+#endif
54092+
54093 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54094 struct pid *pid, struct task_struct *task)
54095 {
54096@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54097 task_cpus_allowed(m, task);
54098 cpuset_task_status_allowed(m, task);
54099 task_context_switch_counts(m, task);
54100+
54101+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54102+ task_pax(m, task);
54103+#endif
54104+
54105+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
54106+ task_grsec_rbac(m, task);
54107+#endif
54108+
54109 return 0;
54110 }
54111
54112+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54113+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54114+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54115+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54116+#endif
54117+
54118 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54119 struct pid *pid, struct task_struct *task, int whole)
54120 {
54121@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54122 char tcomm[sizeof(task->comm)];
54123 unsigned long flags;
54124
54125+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54126+ if (current->exec_id != m->exec_id) {
54127+ gr_log_badprocpid("stat");
54128+ return 0;
54129+ }
54130+#endif
54131+
54132 state = *get_task_state(task);
54133 vsize = eip = esp = 0;
54134 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54135@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54136 gtime = task->gtime;
54137 }
54138
54139+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54140+ if (PAX_RAND_FLAGS(mm)) {
54141+ eip = 0;
54142+ esp = 0;
54143+ wchan = 0;
54144+ }
54145+#endif
54146+#ifdef CONFIG_GRKERNSEC_HIDESYM
54147+ wchan = 0;
54148+ eip =0;
54149+ esp =0;
54150+#endif
54151+
54152 /* scale priority and nice values from timeslices to -20..20 */
54153 /* to make it look like a "normal" Unix priority/nice value */
54154 priority = task_prio(task);
54155@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54156 seq_put_decimal_ull(m, ' ', vsize);
54157 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
54158 seq_put_decimal_ull(m, ' ', rsslim);
54159+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54160+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
54161+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
54162+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
54163+#else
54164 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
54165 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
54166 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
54167+#endif
54168 seq_put_decimal_ull(m, ' ', esp);
54169 seq_put_decimal_ull(m, ' ', eip);
54170 /* The signal information here is obsolete.
54171@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54172 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
54173 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
54174
54175- if (mm && permitted) {
54176+ if (mm && permitted
54177+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54178+ && !PAX_RAND_FLAGS(mm)
54179+#endif
54180+ ) {
54181 seq_put_decimal_ull(m, ' ', mm->start_data);
54182 seq_put_decimal_ull(m, ' ', mm->end_data);
54183 seq_put_decimal_ull(m, ' ', mm->start_brk);
54184@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54185 struct pid *pid, struct task_struct *task)
54186 {
54187 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
54188- struct mm_struct *mm = get_task_mm(task);
54189+ struct mm_struct *mm;
54190
54191+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54192+ if (current->exec_id != m->exec_id) {
54193+ gr_log_badprocpid("statm");
54194+ return 0;
54195+ }
54196+#endif
54197+ mm = get_task_mm(task);
54198 if (mm) {
54199 size = task_statm(mm, &shared, &text, &data, &resident);
54200 mmput(mm);
54201@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54202 return 0;
54203 }
54204
54205+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54206+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
54207+{
54208+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
54209+}
54210+#endif
54211+
54212 #ifdef CONFIG_CHECKPOINT_RESTORE
54213 static struct pid *
54214 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
54215diff --git a/fs/proc/base.c b/fs/proc/base.c
54216index 9b43ff77..ba3e990 100644
54217--- a/fs/proc/base.c
54218+++ b/fs/proc/base.c
54219@@ -111,6 +111,14 @@ struct pid_entry {
54220 union proc_op op;
54221 };
54222
54223+struct getdents_callback {
54224+ struct linux_dirent __user * current_dir;
54225+ struct linux_dirent __user * previous;
54226+ struct file * file;
54227+ int count;
54228+ int error;
54229+};
54230+
54231 #define NOD(NAME, MODE, IOP, FOP, OP) { \
54232 .name = (NAME), \
54233 .len = sizeof(NAME) - 1, \
54234@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
54235 if (!mm->arg_end)
54236 goto out_mm; /* Shh! No looking before we're done */
54237
54238+ if (gr_acl_handle_procpidmem(task))
54239+ goto out_mm;
54240+
54241 len = mm->arg_end - mm->arg_start;
54242
54243 if (len > PAGE_SIZE)
54244@@ -235,12 +246,28 @@ out:
54245 return res;
54246 }
54247
54248+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54249+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54250+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54251+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54252+#endif
54253+
54254 static int proc_pid_auxv(struct task_struct *task, char *buffer)
54255 {
54256 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
54257 int res = PTR_ERR(mm);
54258 if (mm && !IS_ERR(mm)) {
54259 unsigned int nwords = 0;
54260+
54261+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54262+ /* allow if we're currently ptracing this task */
54263+ if (PAX_RAND_FLAGS(mm) &&
54264+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
54265+ mmput(mm);
54266+ return 0;
54267+ }
54268+#endif
54269+
54270 do {
54271 nwords += 2;
54272 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
54273@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
54274 }
54275
54276
54277-#ifdef CONFIG_KALLSYMS
54278+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54279 /*
54280 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
54281 * Returns the resolved symbol. If that fails, simply return the address.
54282@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
54283 mutex_unlock(&task->signal->cred_guard_mutex);
54284 }
54285
54286-#ifdef CONFIG_STACKTRACE
54287+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54288
54289 #define MAX_STACK_TRACE_DEPTH 64
54290
54291@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
54292 return count;
54293 }
54294
54295-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54296+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54297 static int proc_pid_syscall(struct task_struct *task, char *buffer)
54298 {
54299 long nr;
54300@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
54301 /************************************************************************/
54302
54303 /* permission checks */
54304-static int proc_fd_access_allowed(struct inode *inode)
54305+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
54306 {
54307 struct task_struct *task;
54308 int allowed = 0;
54309@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
54310 */
54311 task = get_proc_task(inode);
54312 if (task) {
54313- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54314+ if (log)
54315+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54316+ else
54317+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54318 put_task_struct(task);
54319 }
54320 return allowed;
54321@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
54322 struct task_struct *task,
54323 int hide_pid_min)
54324 {
54325+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54326+ return false;
54327+
54328+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54329+ rcu_read_lock();
54330+ {
54331+ const struct cred *tmpcred = current_cred();
54332+ const struct cred *cred = __task_cred(task);
54333+
54334+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
54335+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54336+ || in_group_p(grsec_proc_gid)
54337+#endif
54338+ ) {
54339+ rcu_read_unlock();
54340+ return true;
54341+ }
54342+ }
54343+ rcu_read_unlock();
54344+
54345+ if (!pid->hide_pid)
54346+ return false;
54347+#endif
54348+
54349 if (pid->hide_pid < hide_pid_min)
54350 return true;
54351 if (in_group_p(pid->pid_gid))
54352 return true;
54353+
54354 return ptrace_may_access(task, PTRACE_MODE_READ);
54355 }
54356
54357@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
54358 put_task_struct(task);
54359
54360 if (!has_perms) {
54361+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54362+ {
54363+#else
54364 if (pid->hide_pid == 2) {
54365+#endif
54366 /*
54367 * Let's make getdents(), stat(), and open()
54368 * consistent with each other. If a process
54369@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54370 if (!task)
54371 return -ESRCH;
54372
54373+ if (gr_acl_handle_procpidmem(task)) {
54374+ put_task_struct(task);
54375+ return -EPERM;
54376+ }
54377+
54378 mm = mm_access(task, mode);
54379 put_task_struct(task);
54380
54381@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54382
54383 file->private_data = mm;
54384
54385+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54386+ file->f_version = current->exec_id;
54387+#endif
54388+
54389 return 0;
54390 }
54391
54392@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54393 ssize_t copied;
54394 char *page;
54395
54396+#ifdef CONFIG_GRKERNSEC
54397+ if (write)
54398+ return -EPERM;
54399+#endif
54400+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54401+ if (file->f_version != current->exec_id) {
54402+ gr_log_badprocpid("mem");
54403+ return 0;
54404+ }
54405+#endif
54406+
54407 if (!mm)
54408 return 0;
54409
54410@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54411 if (!mm)
54412 return 0;
54413
54414+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54415+ if (file->f_version != current->exec_id) {
54416+ gr_log_badprocpid("environ");
54417+ return 0;
54418+ }
54419+#endif
54420+
54421 page = (char *)__get_free_page(GFP_TEMPORARY);
54422 if (!page)
54423 return -ENOMEM;
54424@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54425 int error = -EACCES;
54426
54427 /* Are we allowed to snoop on the tasks file descriptors? */
54428- if (!proc_fd_access_allowed(inode))
54429+ if (!proc_fd_access_allowed(inode, 0))
54430 goto out;
54431
54432 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54433@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54434 struct path path;
54435
54436 /* Are we allowed to snoop on the tasks file descriptors? */
54437- if (!proc_fd_access_allowed(inode))
54438- goto out;
54439+ /* logging this is needed for learning on chromium to work properly,
54440+ but we don't want to flood the logs from 'ps' which does a readlink
54441+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54442+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
54443+ */
54444+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54445+ if (!proc_fd_access_allowed(inode,0))
54446+ goto out;
54447+ } else {
54448+ if (!proc_fd_access_allowed(inode,1))
54449+ goto out;
54450+ }
54451
54452 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54453 if (error)
54454@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54455 rcu_read_lock();
54456 cred = __task_cred(task);
54457 inode->i_uid = cred->euid;
54458+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54459+ inode->i_gid = grsec_proc_gid;
54460+#else
54461 inode->i_gid = cred->egid;
54462+#endif
54463 rcu_read_unlock();
54464 }
54465 security_task_to_inode(task, inode);
54466@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54467 return -ENOENT;
54468 }
54469 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54470+#ifdef CONFIG_GRKERNSEC_PROC_USER
54471+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54472+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54473+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54474+#endif
54475 task_dumpable(task)) {
54476 cred = __task_cred(task);
54477 stat->uid = cred->euid;
54478+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54479+ stat->gid = grsec_proc_gid;
54480+#else
54481 stat->gid = cred->egid;
54482+#endif
54483 }
54484 }
54485 rcu_read_unlock();
54486@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54487
54488 if (task) {
54489 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54490+#ifdef CONFIG_GRKERNSEC_PROC_USER
54491+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54492+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54493+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54494+#endif
54495 task_dumpable(task)) {
54496 rcu_read_lock();
54497 cred = __task_cred(task);
54498 inode->i_uid = cred->euid;
54499+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54500+ inode->i_gid = grsec_proc_gid;
54501+#else
54502 inode->i_gid = cred->egid;
54503+#endif
54504 rcu_read_unlock();
54505 } else {
54506 inode->i_uid = GLOBAL_ROOT_UID;
54507@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54508 if (!task)
54509 goto out_no_task;
54510
54511+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54512+ goto out;
54513+
54514 /*
54515 * Yes, it does not scale. And it should not. Don't add
54516 * new entries into /proc/<tgid>/ without very good reasons.
54517@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
54518 if (!task)
54519 goto out_no_task;
54520
54521+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54522+ goto out;
54523+
54524 ret = 0;
54525 i = filp->f_pos;
54526 switch (i) {
54527@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54528 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54529 #endif
54530 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54531-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54532+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54533 INF("syscall", S_IRUGO, proc_pid_syscall),
54534 #endif
54535 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54536@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54537 #ifdef CONFIG_SECURITY
54538 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54539 #endif
54540-#ifdef CONFIG_KALLSYMS
54541+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54542 INF("wchan", S_IRUGO, proc_pid_wchan),
54543 #endif
54544-#ifdef CONFIG_STACKTRACE
54545+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54546 ONE("stack", S_IRUGO, proc_pid_stack),
54547 #endif
54548 #ifdef CONFIG_SCHEDSTATS
54549@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54550 #ifdef CONFIG_HARDWALL
54551 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54552 #endif
54553+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54554+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54555+#endif
54556 #ifdef CONFIG_USER_NS
54557 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54558 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54559@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54560 if (!inode)
54561 goto out;
54562
54563+#ifdef CONFIG_GRKERNSEC_PROC_USER
54564+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54565+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54566+ inode->i_gid = grsec_proc_gid;
54567+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54568+#else
54569 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54570+#endif
54571 inode->i_op = &proc_tgid_base_inode_operations;
54572 inode->i_fop = &proc_tgid_base_operations;
54573 inode->i_flags|=S_IMMUTABLE;
54574@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54575 if (!task)
54576 goto out;
54577
54578+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54579+ goto out_put_task;
54580+
54581 result = proc_pid_instantiate(dir, dentry, task, NULL);
54582+out_put_task:
54583 put_task_struct(task);
54584 out:
54585 return result;
54586@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54587 static int fake_filldir(void *buf, const char *name, int namelen,
54588 loff_t offset, u64 ino, unsigned d_type)
54589 {
54590+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
54591+ __buf->error = -EINVAL;
54592 return 0;
54593 }
54594
54595@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
54596 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54597 #endif
54598 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54599-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54600+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54601 INF("syscall", S_IRUGO, proc_pid_syscall),
54602 #endif
54603 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54604@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
54605 #ifdef CONFIG_SECURITY
54606 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54607 #endif
54608-#ifdef CONFIG_KALLSYMS
54609+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54610 INF("wchan", S_IRUGO, proc_pid_wchan),
54611 #endif
54612-#ifdef CONFIG_STACKTRACE
54613+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54614 ONE("stack", S_IRUGO, proc_pid_stack),
54615 #endif
54616 #ifdef CONFIG_SCHEDSTATS
54617diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54618index 82676e3..5f8518a 100644
54619--- a/fs/proc/cmdline.c
54620+++ b/fs/proc/cmdline.c
54621@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54622
54623 static int __init proc_cmdline_init(void)
54624 {
54625+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54626+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54627+#else
54628 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54629+#endif
54630 return 0;
54631 }
54632 module_init(proc_cmdline_init);
54633diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54634index b143471..bb105e5 100644
54635--- a/fs/proc/devices.c
54636+++ b/fs/proc/devices.c
54637@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54638
54639 static int __init proc_devices_init(void)
54640 {
54641+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54642+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54643+#else
54644 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54645+#endif
54646 return 0;
54647 }
54648 module_init(proc_devices_init);
54649diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54650index d7a4a28..0201742 100644
54651--- a/fs/proc/fd.c
54652+++ b/fs/proc/fd.c
54653@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54654 if (!task)
54655 return -ENOENT;
54656
54657- files = get_files_struct(task);
54658+ if (!gr_acl_handle_procpidmem(task))
54659+ files = get_files_struct(task);
54660 put_task_struct(task);
54661
54662 if (files) {
54663@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54664 */
54665 int proc_fd_permission(struct inode *inode, int mask)
54666 {
54667+ struct task_struct *task;
54668 int rv = generic_permission(inode, mask);
54669- if (rv == 0)
54670- return 0;
54671+
54672 if (task_pid(current) == proc_pid(inode))
54673 rv = 0;
54674+
54675+ task = get_proc_task(inode);
54676+ if (task == NULL)
54677+ return rv;
54678+
54679+ if (gr_acl_handle_procpidmem(task))
54680+ rv = -EACCES;
54681+
54682+ put_task_struct(task);
54683+
54684 return rv;
54685 }
54686
54687diff --git a/fs/proc/inode.c b/fs/proc/inode.c
54688index 439ae688..c21ac36 100644
54689--- a/fs/proc/inode.c
54690+++ b/fs/proc/inode.c
54691@@ -21,11 +21,17 @@
54692 #include <linux/seq_file.h>
54693 #include <linux/slab.h>
54694 #include <linux/mount.h>
54695+#include <linux/grsecurity.h>
54696
54697 #include <asm/uaccess.h>
54698
54699 #include "internal.h"
54700
54701+#ifdef CONFIG_PROC_SYSCTL
54702+extern const struct inode_operations proc_sys_inode_operations;
54703+extern const struct inode_operations proc_sys_dir_operations;
54704+#endif
54705+
54706 static void proc_evict_inode(struct inode *inode)
54707 {
54708 struct proc_dir_entry *de;
54709@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
54710 ns = PROC_I(inode)->ns;
54711 if (ns_ops && ns)
54712 ns_ops->put(ns);
54713+
54714+#ifdef CONFIG_PROC_SYSCTL
54715+ if (inode->i_op == &proc_sys_inode_operations ||
54716+ inode->i_op == &proc_sys_dir_operations)
54717+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
54718+#endif
54719+
54720 }
54721
54722 static struct kmem_cache * proc_inode_cachep;
54723@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
54724 if (de->mode) {
54725 inode->i_mode = de->mode;
54726 inode->i_uid = de->uid;
54727+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54728+ inode->i_gid = grsec_proc_gid;
54729+#else
54730 inode->i_gid = de->gid;
54731+#endif
54732 }
54733 if (de->size)
54734 inode->i_size = de->size;
54735diff --git a/fs/proc/internal.h b/fs/proc/internal.h
54736index 252544c..04395b9 100644
54737--- a/fs/proc/internal.h
54738+++ b/fs/proc/internal.h
54739@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54740 struct pid *pid, struct task_struct *task);
54741 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54742 struct pid *pid, struct task_struct *task);
54743+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54744+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
54745+#endif
54746 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
54747
54748 extern const struct file_operations proc_tid_children_operations;
54749diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
54750index e96d4f1..8b116ed 100644
54751--- a/fs/proc/kcore.c
54752+++ b/fs/proc/kcore.c
54753@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54754 * the addresses in the elf_phdr on our list.
54755 */
54756 start = kc_offset_to_vaddr(*fpos - elf_buflen);
54757- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
54758+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
54759+ if (tsz > buflen)
54760 tsz = buflen;
54761-
54762+
54763 while (buflen) {
54764 struct kcore_list *m;
54765
54766@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54767 kfree(elf_buf);
54768 } else {
54769 if (kern_addr_valid(start)) {
54770- unsigned long n;
54771+ char *elf_buf;
54772+ mm_segment_t oldfs;
54773
54774- n = copy_to_user(buffer, (char *)start, tsz);
54775- /*
54776- * We cannot distinguish between fault on source
54777- * and fault on destination. When this happens
54778- * we clear too and hope it will trigger the
54779- * EFAULT again.
54780- */
54781- if (n) {
54782- if (clear_user(buffer + tsz - n,
54783- n))
54784+ elf_buf = kmalloc(tsz, GFP_KERNEL);
54785+ if (!elf_buf)
54786+ return -ENOMEM;
54787+ oldfs = get_fs();
54788+ set_fs(KERNEL_DS);
54789+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
54790+ set_fs(oldfs);
54791+ if (copy_to_user(buffer, elf_buf, tsz)) {
54792+ kfree(elf_buf);
54793 return -EFAULT;
54794+ }
54795 }
54796+ set_fs(oldfs);
54797+ kfree(elf_buf);
54798 } else {
54799 if (clear_user(buffer, tsz))
54800 return -EFAULT;
54801@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54802
54803 static int open_kcore(struct inode *inode, struct file *filp)
54804 {
54805+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
54806+ return -EPERM;
54807+#endif
54808 if (!capable(CAP_SYS_RAWIO))
54809 return -EPERM;
54810 if (kcore_need_update)
54811diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
54812index 80e4645..53e5fcf 100644
54813--- a/fs/proc/meminfo.c
54814+++ b/fs/proc/meminfo.c
54815@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
54816 vmi.used >> 10,
54817 vmi.largest_chunk >> 10
54818 #ifdef CONFIG_MEMORY_FAILURE
54819- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
54820+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
54821 #endif
54822 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
54823 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
54824diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
54825index b1822dd..df622cb 100644
54826--- a/fs/proc/nommu.c
54827+++ b/fs/proc/nommu.c
54828@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
54829 if (len < 1)
54830 len = 1;
54831 seq_printf(m, "%*c", len, ' ');
54832- seq_path(m, &file->f_path, "");
54833+ seq_path(m, &file->f_path, "\n\\");
54834 }
54835
54836 seq_putc(m, '\n');
54837diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
54838index fe72cd0..21b52ff 100644
54839--- a/fs/proc/proc_net.c
54840+++ b/fs/proc/proc_net.c
54841@@ -23,6 +23,7 @@
54842 #include <linux/nsproxy.h>
54843 #include <net/net_namespace.h>
54844 #include <linux/seq_file.h>
54845+#include <linux/grsecurity.h>
54846
54847 #include "internal.h"
54848
54849@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
54850 struct task_struct *task;
54851 struct nsproxy *ns;
54852 struct net *net = NULL;
54853+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54854+ const struct cred *cred = current_cred();
54855+#endif
54856+
54857+#ifdef CONFIG_GRKERNSEC_PROC_USER
54858+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
54859+ return net;
54860+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54861+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
54862+ return net;
54863+#endif
54864
54865 rcu_read_lock();
54866 task = pid_task(proc_pid(dir), PIDTYPE_PID);
54867diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
54868index 1827d88..43b0279 100644
54869--- a/fs/proc/proc_sysctl.c
54870+++ b/fs/proc/proc_sysctl.c
54871@@ -12,11 +12,15 @@
54872 #include <linux/module.h>
54873 #include "internal.h"
54874
54875+extern int gr_handle_chroot_sysctl(const int op);
54876+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
54877+ const int op);
54878+
54879 static const struct dentry_operations proc_sys_dentry_operations;
54880 static const struct file_operations proc_sys_file_operations;
54881-static const struct inode_operations proc_sys_inode_operations;
54882+const struct inode_operations proc_sys_inode_operations;
54883 static const struct file_operations proc_sys_dir_file_operations;
54884-static const struct inode_operations proc_sys_dir_operations;
54885+const struct inode_operations proc_sys_dir_operations;
54886
54887 void proc_sys_poll_notify(struct ctl_table_poll *poll)
54888 {
54889@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
54890
54891 err = NULL;
54892 d_set_d_op(dentry, &proc_sys_dentry_operations);
54893+
54894+ gr_handle_proc_create(dentry, inode);
54895+
54896 d_add(dentry, inode);
54897
54898 out:
54899@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54900 struct inode *inode = filp->f_path.dentry->d_inode;
54901 struct ctl_table_header *head = grab_header(inode);
54902 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
54903+ int op = write ? MAY_WRITE : MAY_READ;
54904 ssize_t error;
54905 size_t res;
54906
54907@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54908 * and won't be until we finish.
54909 */
54910 error = -EPERM;
54911- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
54912+ if (sysctl_perm(head, table, op))
54913 goto out;
54914
54915 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
54916@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54917 if (!table->proc_handler)
54918 goto out;
54919
54920+#ifdef CONFIG_GRKERNSEC
54921+ error = -EPERM;
54922+ if (gr_handle_chroot_sysctl(op))
54923+ goto out;
54924+ dget(filp->f_path.dentry);
54925+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
54926+ dput(filp->f_path.dentry);
54927+ goto out;
54928+ }
54929+ dput(filp->f_path.dentry);
54930+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
54931+ goto out;
54932+ if (write && !capable(CAP_SYS_ADMIN))
54933+ goto out;
54934+#endif
54935+
54936 /* careful: calling conventions are nasty here */
54937 res = count;
54938 error = table->proc_handler(table, write, buf, &res, ppos);
54939@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
54940 return -ENOMEM;
54941 } else {
54942 d_set_d_op(child, &proc_sys_dentry_operations);
54943+
54944+ gr_handle_proc_create(child, inode);
54945+
54946 d_add(child, inode);
54947 }
54948 } else {
54949@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
54950 if ((*pos)++ < file->f_pos)
54951 return 0;
54952
54953+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
54954+ return 0;
54955+
54956 if (unlikely(S_ISLNK(table->mode)))
54957 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
54958 else
54959@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
54960 if (IS_ERR(head))
54961 return PTR_ERR(head);
54962
54963+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
54964+ return -ENOENT;
54965+
54966 generic_fillattr(inode, stat);
54967 if (table)
54968 stat->mode = (stat->mode & S_IFMT) | table->mode;
54969@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
54970 .llseek = generic_file_llseek,
54971 };
54972
54973-static const struct inode_operations proc_sys_inode_operations = {
54974+const struct inode_operations proc_sys_inode_operations = {
54975 .permission = proc_sys_permission,
54976 .setattr = proc_sys_setattr,
54977 .getattr = proc_sys_getattr,
54978 };
54979
54980-static const struct inode_operations proc_sys_dir_operations = {
54981+const struct inode_operations proc_sys_dir_operations = {
54982 .lookup = proc_sys_lookup,
54983 .permission = proc_sys_permission,
54984 .setattr = proc_sys_setattr,
54985@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
54986 static struct ctl_dir *new_dir(struct ctl_table_set *set,
54987 const char *name, int namelen)
54988 {
54989- struct ctl_table *table;
54990+ ctl_table_no_const *table;
54991 struct ctl_dir *new;
54992 struct ctl_node *node;
54993 char *new_name;
54994@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
54995 return NULL;
54996
54997 node = (struct ctl_node *)(new + 1);
54998- table = (struct ctl_table *)(node + 1);
54999+ table = (ctl_table_no_const *)(node + 1);
55000 new_name = (char *)(table + 2);
55001 memcpy(new_name, name, namelen);
55002 new_name[namelen] = '\0';
55003@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55004 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55005 struct ctl_table_root *link_root)
55006 {
55007- struct ctl_table *link_table, *entry, *link;
55008+ ctl_table_no_const *link_table, *link;
55009+ struct ctl_table *entry;
55010 struct ctl_table_header *links;
55011 struct ctl_node *node;
55012 char *link_name;
55013@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55014 return NULL;
55015
55016 node = (struct ctl_node *)(links + 1);
55017- link_table = (struct ctl_table *)(node + nr_entries);
55018+ link_table = (ctl_table_no_const *)(node + nr_entries);
55019 link_name = (char *)&link_table[nr_entries + 1];
55020
55021 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55022@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55023 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55024 struct ctl_table *table)
55025 {
55026- struct ctl_table *ctl_table_arg = NULL;
55027- struct ctl_table *entry, *files;
55028+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55029+ struct ctl_table *entry;
55030 int nr_files = 0;
55031 int nr_dirs = 0;
55032 int err = -ENOMEM;
55033@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55034 nr_files++;
55035 }
55036
55037- files = table;
55038 /* If there are mixed files and directories we need a new table */
55039 if (nr_dirs && nr_files) {
55040- struct ctl_table *new;
55041+ ctl_table_no_const *new;
55042 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55043 GFP_KERNEL);
55044 if (!files)
55045@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55046 /* Register everything except a directory full of subdirectories */
55047 if (nr_files || !nr_dirs) {
55048 struct ctl_table_header *header;
55049- header = __register_sysctl_table(set, path, files);
55050+ header = __register_sysctl_table(set, path, files ? files : table);
55051 if (!header) {
55052 kfree(ctl_table_arg);
55053 goto out;
55054diff --git a/fs/proc/root.c b/fs/proc/root.c
55055index c6e9fac..a740964 100644
55056--- a/fs/proc/root.c
55057+++ b/fs/proc/root.c
55058@@ -176,7 +176,15 @@ void __init proc_root_init(void)
55059 #ifdef CONFIG_PROC_DEVICETREE
55060 proc_device_tree_init();
55061 #endif
55062+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55063+#ifdef CONFIG_GRKERNSEC_PROC_USER
55064+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
55065+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55066+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
55067+#endif
55068+#else
55069 proc_mkdir("bus", NULL);
55070+#endif
55071 proc_sys_init();
55072 }
55073
55074diff --git a/fs/proc/self.c b/fs/proc/self.c
55075index aa5cc3b..c91a5d0 100644
55076--- a/fs/proc/self.c
55077+++ b/fs/proc/self.c
55078@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
55079 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
55080 void *cookie)
55081 {
55082- char *s = nd_get_link(nd);
55083+ const char *s = nd_get_link(nd);
55084 if (!IS_ERR(s))
55085 kfree(s);
55086 }
55087diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
55088index ca5ce7f..02c1cf0 100644
55089--- a/fs/proc/task_mmu.c
55090+++ b/fs/proc/task_mmu.c
55091@@ -11,12 +11,19 @@
55092 #include <linux/rmap.h>
55093 #include <linux/swap.h>
55094 #include <linux/swapops.h>
55095+#include <linux/grsecurity.h>
55096
55097 #include <asm/elf.h>
55098 #include <asm/uaccess.h>
55099 #include <asm/tlbflush.h>
55100 #include "internal.h"
55101
55102+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55103+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55104+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55105+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55106+#endif
55107+
55108 void task_mem(struct seq_file *m, struct mm_struct *mm)
55109 {
55110 unsigned long data, text, lib, swap;
55111@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55112 "VmExe:\t%8lu kB\n"
55113 "VmLib:\t%8lu kB\n"
55114 "VmPTE:\t%8lu kB\n"
55115- "VmSwap:\t%8lu kB\n",
55116- hiwater_vm << (PAGE_SHIFT-10),
55117+ "VmSwap:\t%8lu kB\n"
55118+
55119+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55120+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
55121+#endif
55122+
55123+ ,hiwater_vm << (PAGE_SHIFT-10),
55124 total_vm << (PAGE_SHIFT-10),
55125 mm->locked_vm << (PAGE_SHIFT-10),
55126 mm->pinned_vm << (PAGE_SHIFT-10),
55127@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55128 data << (PAGE_SHIFT-10),
55129 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
55130 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
55131- swap << (PAGE_SHIFT-10));
55132+ swap << (PAGE_SHIFT-10)
55133+
55134+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55135+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55136+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
55137+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
55138+#else
55139+ , mm->context.user_cs_base
55140+ , mm->context.user_cs_limit
55141+#endif
55142+#endif
55143+
55144+ );
55145 }
55146
55147 unsigned long task_vsize(struct mm_struct *mm)
55148@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55149 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
55150 }
55151
55152- /* We don't show the stack guard page in /proc/maps */
55153+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55154+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
55155+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
55156+#else
55157 start = vma->vm_start;
55158- if (stack_guard_page_start(vma, start))
55159- start += PAGE_SIZE;
55160 end = vma->vm_end;
55161- if (stack_guard_page_end(vma, end))
55162- end -= PAGE_SIZE;
55163+#endif
55164
55165 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
55166 start,
55167@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55168 flags & VM_WRITE ? 'w' : '-',
55169 flags & VM_EXEC ? 'x' : '-',
55170 flags & VM_MAYSHARE ? 's' : 'p',
55171+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55172+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
55173+#else
55174 pgoff,
55175+#endif
55176 MAJOR(dev), MINOR(dev), ino, &len);
55177
55178 /*
55179@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55180 */
55181 if (file) {
55182 pad_len_spaces(m, len);
55183- seq_path(m, &file->f_path, "\n");
55184+ seq_path(m, &file->f_path, "\n\\");
55185 goto done;
55186 }
55187
55188@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55189 * Thread stack in /proc/PID/task/TID/maps or
55190 * the main process stack.
55191 */
55192- if (!is_pid || (vma->vm_start <= mm->start_stack &&
55193- vma->vm_end >= mm->start_stack)) {
55194+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
55195+ (vma->vm_start <= mm->start_stack &&
55196+ vma->vm_end >= mm->start_stack)) {
55197 name = "[stack]";
55198 } else {
55199 /* Thread stack in /proc/PID/maps */
55200@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
55201 struct proc_maps_private *priv = m->private;
55202 struct task_struct *task = priv->task;
55203
55204+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55205+ if (current->exec_id != m->exec_id) {
55206+ gr_log_badprocpid("maps");
55207+ return 0;
55208+ }
55209+#endif
55210+
55211 show_map_vma(m, vma, is_pid);
55212
55213 if (m->count < m->size) /* vma is copied successfully */
55214@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55215 .private = &mss,
55216 };
55217
55218+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55219+ if (current->exec_id != m->exec_id) {
55220+ gr_log_badprocpid("smaps");
55221+ return 0;
55222+ }
55223+#endif
55224 memset(&mss, 0, sizeof mss);
55225- mss.vma = vma;
55226- /* mmap_sem is held in m_start */
55227- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55228- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55229-
55230+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55231+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
55232+#endif
55233+ mss.vma = vma;
55234+ /* mmap_sem is held in m_start */
55235+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55236+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55237+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55238+ }
55239+#endif
55240 show_map_vma(m, vma, is_pid);
55241
55242 seq_printf(m,
55243@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55244 "KernelPageSize: %8lu kB\n"
55245 "MMUPageSize: %8lu kB\n"
55246 "Locked: %8lu kB\n",
55247+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55248+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
55249+#else
55250 (vma->vm_end - vma->vm_start) >> 10,
55251+#endif
55252 mss.resident >> 10,
55253 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
55254 mss.shared_clean >> 10,
55255@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55256 int n;
55257 char buffer[50];
55258
55259+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55260+ if (current->exec_id != m->exec_id) {
55261+ gr_log_badprocpid("numa_maps");
55262+ return 0;
55263+ }
55264+#endif
55265+
55266 if (!mm)
55267 return 0;
55268
55269@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55270 mpol_to_str(buffer, sizeof(buffer), pol);
55271 mpol_cond_put(pol);
55272
55273+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55274+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
55275+#else
55276 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
55277+#endif
55278
55279 if (file) {
55280 seq_printf(m, " file=");
55281- seq_path(m, &file->f_path, "\n\t= ");
55282+ seq_path(m, &file->f_path, "\n\t\\= ");
55283 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
55284 seq_printf(m, " heap");
55285 } else {
55286diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
55287index 1ccfa53..0848f95 100644
55288--- a/fs/proc/task_nommu.c
55289+++ b/fs/proc/task_nommu.c
55290@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55291 else
55292 bytes += kobjsize(mm);
55293
55294- if (current->fs && current->fs->users > 1)
55295+ if (current->fs && atomic_read(&current->fs->users) > 1)
55296 sbytes += kobjsize(current->fs);
55297 else
55298 bytes += kobjsize(current->fs);
55299@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
55300
55301 if (file) {
55302 pad_len_spaces(m, len);
55303- seq_path(m, &file->f_path, "");
55304+ seq_path(m, &file->f_path, "\n\\");
55305 } else if (mm) {
55306 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
55307
55308diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
55309index b00fcc9..e0c6381 100644
55310--- a/fs/qnx6/qnx6.h
55311+++ b/fs/qnx6/qnx6.h
55312@@ -74,7 +74,7 @@ enum {
55313 BYTESEX_BE,
55314 };
55315
55316-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55317+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55318 {
55319 if (sbi->s_bytesex == BYTESEX_LE)
55320 return le64_to_cpu((__force __le64)n);
55321@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
55322 return (__force __fs64)cpu_to_be64(n);
55323 }
55324
55325-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55326+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55327 {
55328 if (sbi->s_bytesex == BYTESEX_LE)
55329 return le32_to_cpu((__force __le32)n);
55330diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
55331index 16e8abb..2dcf914 100644
55332--- a/fs/quota/netlink.c
55333+++ b/fs/quota/netlink.c
55334@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
55335 void quota_send_warning(struct kqid qid, dev_t dev,
55336 const char warntype)
55337 {
55338- static atomic_t seq;
55339+ static atomic_unchecked_t seq;
55340 struct sk_buff *skb;
55341 void *msg_head;
55342 int ret;
55343@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
55344 "VFS: Not enough memory to send quota warning.\n");
55345 return;
55346 }
55347- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
55348+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
55349 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
55350 if (!msg_head) {
55351 printk(KERN_ERR
55352diff --git a/fs/readdir.c b/fs/readdir.c
55353index 5e69ef5..e5d9099 100644
55354--- a/fs/readdir.c
55355+++ b/fs/readdir.c
55356@@ -17,6 +17,7 @@
55357 #include <linux/security.h>
55358 #include <linux/syscalls.h>
55359 #include <linux/unistd.h>
55360+#include <linux/namei.h>
55361
55362 #include <asm/uaccess.h>
55363
55364@@ -67,6 +68,7 @@ struct old_linux_dirent {
55365
55366 struct readdir_callback {
55367 struct old_linux_dirent __user * dirent;
55368+ struct file * file;
55369 int result;
55370 };
55371
55372@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
55373 buf->result = -EOVERFLOW;
55374 return -EOVERFLOW;
55375 }
55376+
55377+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55378+ return 0;
55379+
55380 buf->result++;
55381 dirent = buf->dirent;
55382 if (!access_ok(VERIFY_WRITE, dirent,
55383@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
55384
55385 buf.result = 0;
55386 buf.dirent = dirent;
55387+ buf.file = f.file;
55388
55389 error = vfs_readdir(f.file, fillonedir, &buf);
55390 if (buf.result)
55391@@ -139,6 +146,7 @@ struct linux_dirent {
55392 struct getdents_callback {
55393 struct linux_dirent __user * current_dir;
55394 struct linux_dirent __user * previous;
55395+ struct file * file;
55396 int count;
55397 int error;
55398 };
55399@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
55400 buf->error = -EOVERFLOW;
55401 return -EOVERFLOW;
55402 }
55403+
55404+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55405+ return 0;
55406+
55407 dirent = buf->previous;
55408 if (dirent) {
55409 if (__put_user(offset, &dirent->d_off))
55410@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55411 buf.previous = NULL;
55412 buf.count = count;
55413 buf.error = 0;
55414+ buf.file = f.file;
55415
55416 error = vfs_readdir(f.file, filldir, &buf);
55417 if (error >= 0)
55418@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55419 struct getdents_callback64 {
55420 struct linux_dirent64 __user * current_dir;
55421 struct linux_dirent64 __user * previous;
55422+ struct file *file;
55423 int count;
55424 int error;
55425 };
55426@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55427 buf->error = -EINVAL; /* only used if we fail.. */
55428 if (reclen > buf->count)
55429 return -EINVAL;
55430+
55431+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55432+ return 0;
55433+
55434 dirent = buf->previous;
55435 if (dirent) {
55436 if (__put_user(offset, &dirent->d_off))
55437@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55438
55439 buf.current_dir = dirent;
55440 buf.previous = NULL;
55441+ buf.file = f.file;
55442 buf.count = count;
55443 buf.error = 0;
55444
55445@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55446 error = buf.error;
55447 lastdirent = buf.previous;
55448 if (lastdirent) {
55449- typeof(lastdirent->d_off) d_off = f.file->f_pos;
55450+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55451 if (__put_user(d_off, &lastdirent->d_off))
55452 error = -EFAULT;
55453 else
55454diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55455index 2b7882b..1c5ef48 100644
55456--- a/fs/reiserfs/do_balan.c
55457+++ b/fs/reiserfs/do_balan.c
55458@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55459 return;
55460 }
55461
55462- atomic_inc(&(fs_generation(tb->tb_sb)));
55463+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55464 do_balance_starts(tb);
55465
55466 /* balance leaf returns 0 except if combining L R and S into
55467diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55468index e60e870..f40ac16 100644
55469--- a/fs/reiserfs/procfs.c
55470+++ b/fs/reiserfs/procfs.c
55471@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55472 "SMALL_TAILS " : "NO_TAILS ",
55473 replay_only(sb) ? "REPLAY_ONLY " : "",
55474 convert_reiserfs(sb) ? "CONV " : "",
55475- atomic_read(&r->s_generation_counter),
55476+ atomic_read_unchecked(&r->s_generation_counter),
55477 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55478 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55479 SF(s_good_search_by_key_reada), SF(s_bmaps),
55480diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55481index 157e474..65a6114 100644
55482--- a/fs/reiserfs/reiserfs.h
55483+++ b/fs/reiserfs/reiserfs.h
55484@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55485 /* Comment? -Hans */
55486 wait_queue_head_t s_wait;
55487 /* To be obsoleted soon by per buffer seals.. -Hans */
55488- atomic_t s_generation_counter; // increased by one every time the
55489+ atomic_unchecked_t s_generation_counter; // increased by one every time the
55490 // tree gets re-balanced
55491 unsigned long s_properties; /* File system properties. Currently holds
55492 on-disk FS format */
55493@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55494 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55495
55496 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55497-#define get_generation(s) atomic_read (&fs_generation(s))
55498+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55499 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55500 #define __fs_changed(gen,s) (gen != get_generation (s))
55501 #define fs_changed(gen,s) \
55502diff --git a/fs/select.c b/fs/select.c
55503index 2ef72d9..f213b17 100644
55504--- a/fs/select.c
55505+++ b/fs/select.c
55506@@ -20,6 +20,7 @@
55507 #include <linux/export.h>
55508 #include <linux/slab.h>
55509 #include <linux/poll.h>
55510+#include <linux/security.h>
55511 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
55512 #include <linux/file.h>
55513 #include <linux/fdtable.h>
55514@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
55515 struct poll_list *walk = head;
55516 unsigned long todo = nfds;
55517
55518+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
55519 if (nfds > rlimit(RLIMIT_NOFILE))
55520 return -EINVAL;
55521
55522diff --git a/fs/seq_file.c b/fs/seq_file.c
55523index f2bc3df..239d4f6 100644
55524--- a/fs/seq_file.c
55525+++ b/fs/seq_file.c
55526@@ -10,6 +10,7 @@
55527 #include <linux/seq_file.h>
55528 #include <linux/slab.h>
55529 #include <linux/cred.h>
55530+#include <linux/sched.h>
55531
55532 #include <asm/uaccess.h>
55533 #include <asm/page.h>
55534@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55535 #ifdef CONFIG_USER_NS
55536 p->user_ns = file->f_cred->user_ns;
55537 #endif
55538+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55539+ p->exec_id = current->exec_id;
55540+#endif
55541
55542 /*
55543 * Wrappers around seq_open(e.g. swaps_open) need to be
55544@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55545 return 0;
55546 }
55547 if (!m->buf) {
55548- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55549+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55550 if (!m->buf)
55551 return -ENOMEM;
55552 }
55553@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55554 Eoverflow:
55555 m->op->stop(m, p);
55556 kfree(m->buf);
55557- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55558+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55559 return !m->buf ? -ENOMEM : -EAGAIN;
55560 }
55561
55562@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55563
55564 /* grab buffer if we didn't have one */
55565 if (!m->buf) {
55566- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55567+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55568 if (!m->buf)
55569 goto Enomem;
55570 }
55571@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55572 goto Fill;
55573 m->op->stop(m, p);
55574 kfree(m->buf);
55575- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55576+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55577 if (!m->buf)
55578 goto Enomem;
55579 m->count = 0;
55580@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55581 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55582 void *data)
55583 {
55584- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55585+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55586 int res = -ENOMEM;
55587
55588 if (op) {
55589diff --git a/fs/splice.c b/fs/splice.c
55590index 6909d89..5b2e8f9 100644
55591--- a/fs/splice.c
55592+++ b/fs/splice.c
55593@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55594 pipe_lock(pipe);
55595
55596 for (;;) {
55597- if (!pipe->readers) {
55598+ if (!atomic_read(&pipe->readers)) {
55599 send_sig(SIGPIPE, current, 0);
55600 if (!ret)
55601 ret = -EPIPE;
55602@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55603 do_wakeup = 0;
55604 }
55605
55606- pipe->waiting_writers++;
55607+ atomic_inc(&pipe->waiting_writers);
55608 pipe_wait(pipe);
55609- pipe->waiting_writers--;
55610+ atomic_dec(&pipe->waiting_writers);
55611 }
55612
55613 pipe_unlock(pipe);
55614@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55615 old_fs = get_fs();
55616 set_fs(get_ds());
55617 /* The cast to a user pointer is valid due to the set_fs() */
55618- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55619+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55620 set_fs(old_fs);
55621
55622 return res;
55623@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55624 old_fs = get_fs();
55625 set_fs(get_ds());
55626 /* The cast to a user pointer is valid due to the set_fs() */
55627- res = vfs_write(file, (const char __user *)buf, count, &pos);
55628+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55629 set_fs(old_fs);
55630
55631 return res;
55632@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55633 goto err;
55634
55635 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55636- vec[i].iov_base = (void __user *) page_address(page);
55637+ vec[i].iov_base = (void __force_user *) page_address(page);
55638 vec[i].iov_len = this_len;
55639 spd.pages[i] = page;
55640 spd.nr_pages++;
55641@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55642 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55643 {
55644 while (!pipe->nrbufs) {
55645- if (!pipe->writers)
55646+ if (!atomic_read(&pipe->writers))
55647 return 0;
55648
55649- if (!pipe->waiting_writers && sd->num_spliced)
55650+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
55651 return 0;
55652
55653 if (sd->flags & SPLICE_F_NONBLOCK)
55654@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
55655 * out of the pipe right after the splice_to_pipe(). So set
55656 * PIPE_READERS appropriately.
55657 */
55658- pipe->readers = 1;
55659+ atomic_set(&pipe->readers, 1);
55660
55661 current->splice_pipe = pipe;
55662 }
55663@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55664 ret = -ERESTARTSYS;
55665 break;
55666 }
55667- if (!pipe->writers)
55668+ if (!atomic_read(&pipe->writers))
55669 break;
55670- if (!pipe->waiting_writers) {
55671+ if (!atomic_read(&pipe->waiting_writers)) {
55672 if (flags & SPLICE_F_NONBLOCK) {
55673 ret = -EAGAIN;
55674 break;
55675@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55676 pipe_lock(pipe);
55677
55678 while (pipe->nrbufs >= pipe->buffers) {
55679- if (!pipe->readers) {
55680+ if (!atomic_read(&pipe->readers)) {
55681 send_sig(SIGPIPE, current, 0);
55682 ret = -EPIPE;
55683 break;
55684@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55685 ret = -ERESTARTSYS;
55686 break;
55687 }
55688- pipe->waiting_writers++;
55689+ atomic_inc(&pipe->waiting_writers);
55690 pipe_wait(pipe);
55691- pipe->waiting_writers--;
55692+ atomic_dec(&pipe->waiting_writers);
55693 }
55694
55695 pipe_unlock(pipe);
55696@@ -1823,14 +1823,14 @@ retry:
55697 pipe_double_lock(ipipe, opipe);
55698
55699 do {
55700- if (!opipe->readers) {
55701+ if (!atomic_read(&opipe->readers)) {
55702 send_sig(SIGPIPE, current, 0);
55703 if (!ret)
55704 ret = -EPIPE;
55705 break;
55706 }
55707
55708- if (!ipipe->nrbufs && !ipipe->writers)
55709+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
55710 break;
55711
55712 /*
55713@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55714 pipe_double_lock(ipipe, opipe);
55715
55716 do {
55717- if (!opipe->readers) {
55718+ if (!atomic_read(&opipe->readers)) {
55719 send_sig(SIGPIPE, current, 0);
55720 if (!ret)
55721 ret = -EPIPE;
55722@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55723 * return EAGAIN if we have the potential of some data in the
55724 * future, otherwise just return 0
55725 */
55726- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
55727+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
55728 ret = -EAGAIN;
55729
55730 pipe_unlock(ipipe);
55731diff --git a/fs/stat.c b/fs/stat.c
55732index 14f4545..9b7f55b 100644
55733--- a/fs/stat.c
55734+++ b/fs/stat.c
55735@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
55736 stat->gid = inode->i_gid;
55737 stat->rdev = inode->i_rdev;
55738 stat->size = i_size_read(inode);
55739- stat->atime = inode->i_atime;
55740- stat->mtime = inode->i_mtime;
55741+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55742+ stat->atime = inode->i_ctime;
55743+ stat->mtime = inode->i_ctime;
55744+ } else {
55745+ stat->atime = inode->i_atime;
55746+ stat->mtime = inode->i_mtime;
55747+ }
55748 stat->ctime = inode->i_ctime;
55749 stat->blksize = (1 << inode->i_blkbits);
55750 stat->blocks = inode->i_blocks;
55751@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55752 if (retval)
55753 return retval;
55754
55755- if (inode->i_op->getattr)
55756- return inode->i_op->getattr(mnt, dentry, stat);
55757+ if (inode->i_op->getattr) {
55758+ retval = inode->i_op->getattr(mnt, dentry, stat);
55759+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55760+ stat->atime = stat->ctime;
55761+ stat->mtime = stat->ctime;
55762+ }
55763+ return retval;
55764+ }
55765
55766 generic_fillattr(inode, stat);
55767 return 0;
55768diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
55769index 2fbdff6..5530a61 100644
55770--- a/fs/sysfs/dir.c
55771+++ b/fs/sysfs/dir.c
55772@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
55773 struct sysfs_dirent *sd;
55774 int rc;
55775
55776+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55777+ const char *parent_name = parent_sd->s_name;
55778+
55779+ mode = S_IFDIR | S_IRWXU;
55780+
55781+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
55782+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
55783+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
55784+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
55785+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
55786+#endif
55787+
55788 /* allocate */
55789 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
55790 if (!sd)
55791diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
55792index 602f56d..6853db8 100644
55793--- a/fs/sysfs/file.c
55794+++ b/fs/sysfs/file.c
55795@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
55796
55797 struct sysfs_open_dirent {
55798 atomic_t refcnt;
55799- atomic_t event;
55800+ atomic_unchecked_t event;
55801 wait_queue_head_t poll;
55802 struct list_head buffers; /* goes through sysfs_buffer.list */
55803 };
55804@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
55805 if (!sysfs_get_active(attr_sd))
55806 return -ENODEV;
55807
55808- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
55809+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
55810 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
55811
55812 sysfs_put_active(attr_sd);
55813@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
55814 return -ENOMEM;
55815
55816 atomic_set(&new_od->refcnt, 0);
55817- atomic_set(&new_od->event, 1);
55818+ atomic_set_unchecked(&new_od->event, 1);
55819 init_waitqueue_head(&new_od->poll);
55820 INIT_LIST_HEAD(&new_od->buffers);
55821 goto retry;
55822@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
55823
55824 sysfs_put_active(attr_sd);
55825
55826- if (buffer->event != atomic_read(&od->event))
55827+ if (buffer->event != atomic_read_unchecked(&od->event))
55828 goto trigger;
55829
55830 return DEFAULT_POLLMASK;
55831@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
55832
55833 od = sd->s_attr.open;
55834 if (od) {
55835- atomic_inc(&od->event);
55836+ atomic_inc_unchecked(&od->event);
55837 wake_up_interruptible(&od->poll);
55838 }
55839
55840diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
55841index 3c9eb56..9dea5be 100644
55842--- a/fs/sysfs/symlink.c
55843+++ b/fs/sysfs/symlink.c
55844@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55845
55846 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
55847 {
55848- char *page = nd_get_link(nd);
55849+ const char *page = nd_get_link(nd);
55850 if (!IS_ERR(page))
55851 free_page((unsigned long)page);
55852 }
55853diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
55854index 69d4889..a810bd4 100644
55855--- a/fs/sysv/sysv.h
55856+++ b/fs/sysv/sysv.h
55857@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
55858 #endif
55859 }
55860
55861-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
55862+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
55863 {
55864 if (sbi->s_bytesex == BYTESEX_PDP)
55865 return PDP_swab((__force __u32)n);
55866diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
55867index e18b988..f1d4ad0f 100644
55868--- a/fs/ubifs/io.c
55869+++ b/fs/ubifs/io.c
55870@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
55871 return err;
55872 }
55873
55874-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
55875+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
55876 {
55877 int err;
55878
55879diff --git a/fs/udf/misc.c b/fs/udf/misc.c
55880index c175b4d..8f36a16 100644
55881--- a/fs/udf/misc.c
55882+++ b/fs/udf/misc.c
55883@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
55884
55885 u8 udf_tag_checksum(const struct tag *t)
55886 {
55887- u8 *data = (u8 *)t;
55888+ const u8 *data = (const u8 *)t;
55889 u8 checksum = 0;
55890 int i;
55891 for (i = 0; i < sizeof(struct tag); ++i)
55892diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
55893index 8d974c4..b82f6ec 100644
55894--- a/fs/ufs/swab.h
55895+++ b/fs/ufs/swab.h
55896@@ -22,7 +22,7 @@ enum {
55897 BYTESEX_BE
55898 };
55899
55900-static inline u64
55901+static inline u64 __intentional_overflow(-1)
55902 fs64_to_cpu(struct super_block *sbp, __fs64 n)
55903 {
55904 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
55905@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
55906 return (__force __fs64)cpu_to_be64(n);
55907 }
55908
55909-static inline u32
55910+static inline u32 __intentional_overflow(-1)
55911 fs32_to_cpu(struct super_block *sbp, __fs32 n)
55912 {
55913 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
55914diff --git a/fs/utimes.c b/fs/utimes.c
55915index f4fb7ec..3fe03c0 100644
55916--- a/fs/utimes.c
55917+++ b/fs/utimes.c
55918@@ -1,6 +1,7 @@
55919 #include <linux/compiler.h>
55920 #include <linux/file.h>
55921 #include <linux/fs.h>
55922+#include <linux/security.h>
55923 #include <linux/linkage.h>
55924 #include <linux/mount.h>
55925 #include <linux/namei.h>
55926@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
55927 goto mnt_drop_write_and_out;
55928 }
55929 }
55930+
55931+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
55932+ error = -EACCES;
55933+ goto mnt_drop_write_and_out;
55934+ }
55935+
55936 mutex_lock(&inode->i_mutex);
55937 error = notify_change(path->dentry, &newattrs);
55938 mutex_unlock(&inode->i_mutex);
55939diff --git a/fs/xattr.c b/fs/xattr.c
55940index 3377dff..4feded6 100644
55941--- a/fs/xattr.c
55942+++ b/fs/xattr.c
55943@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
55944 * Extended attribute SET operations
55945 */
55946 static long
55947-setxattr(struct dentry *d, const char __user *name, const void __user *value,
55948+setxattr(struct path *path, const char __user *name, const void __user *value,
55949 size_t size, int flags)
55950 {
55951 int error;
55952@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
55953 posix_acl_fix_xattr_from_user(kvalue, size);
55954 }
55955
55956- error = vfs_setxattr(d, kname, kvalue, size, flags);
55957+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
55958+ error = -EACCES;
55959+ goto out;
55960+ }
55961+
55962+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
55963 out:
55964 if (vvalue)
55965 vfree(vvalue);
55966@@ -377,7 +382,7 @@ retry:
55967 return error;
55968 error = mnt_want_write(path.mnt);
55969 if (!error) {
55970- error = setxattr(path.dentry, name, value, size, flags);
55971+ error = setxattr(&path, name, value, size, flags);
55972 mnt_drop_write(path.mnt);
55973 }
55974 path_put(&path);
55975@@ -401,7 +406,7 @@ retry:
55976 return error;
55977 error = mnt_want_write(path.mnt);
55978 if (!error) {
55979- error = setxattr(path.dentry, name, value, size, flags);
55980+ error = setxattr(&path, name, value, size, flags);
55981 mnt_drop_write(path.mnt);
55982 }
55983 path_put(&path);
55984@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
55985 const void __user *,value, size_t, size, int, flags)
55986 {
55987 struct fd f = fdget(fd);
55988- struct dentry *dentry;
55989 int error = -EBADF;
55990
55991 if (!f.file)
55992 return error;
55993- dentry = f.file->f_path.dentry;
55994- audit_inode(NULL, dentry, 0);
55995+ audit_inode(NULL, f.file->f_path.dentry, 0);
55996 error = mnt_want_write_file(f.file);
55997 if (!error) {
55998- error = setxattr(dentry, name, value, size, flags);
55999+ error = setxattr(&f.file->f_path, name, value, size, flags);
56000 mnt_drop_write_file(f.file);
56001 }
56002 fdput(f);
56003diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
56004index 9fbea87..6b19972 100644
56005--- a/fs/xattr_acl.c
56006+++ b/fs/xattr_acl.c
56007@@ -76,8 +76,8 @@ struct posix_acl *
56008 posix_acl_from_xattr(struct user_namespace *user_ns,
56009 const void *value, size_t size)
56010 {
56011- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
56012- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
56013+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
56014+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
56015 int count;
56016 struct posix_acl *acl;
56017 struct posix_acl_entry *acl_e;
56018diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
56019index 572a858..12a9b0d 100644
56020--- a/fs/xfs/xfs_bmap.c
56021+++ b/fs/xfs/xfs_bmap.c
56022@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
56023 int nmap,
56024 int ret_nmap);
56025 #else
56026-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
56027+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
56028 #endif /* DEBUG */
56029
56030 STATIC int
56031diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
56032index 1b9fc3e..e1bdde0 100644
56033--- a/fs/xfs/xfs_dir2_sf.c
56034+++ b/fs/xfs/xfs_dir2_sf.c
56035@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
56036 }
56037
56038 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
56039- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56040+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
56041+ char name[sfep->namelen];
56042+ memcpy(name, sfep->name, sfep->namelen);
56043+ if (filldir(dirent, name, sfep->namelen,
56044+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
56045+ *offset = off & 0x7fffffff;
56046+ return 0;
56047+ }
56048+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56049 off & 0x7fffffff, ino, DT_UNKNOWN)) {
56050 *offset = off & 0x7fffffff;
56051 return 0;
56052diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
56053index c1c3ef8..0952438 100644
56054--- a/fs/xfs/xfs_ioctl.c
56055+++ b/fs/xfs/xfs_ioctl.c
56056@@ -127,7 +127,7 @@ xfs_find_handle(
56057 }
56058
56059 error = -EFAULT;
56060- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
56061+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
56062 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
56063 goto out_put;
56064
56065diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
56066index d82efaa..0904a8e 100644
56067--- a/fs/xfs/xfs_iops.c
56068+++ b/fs/xfs/xfs_iops.c
56069@@ -395,7 +395,7 @@ xfs_vn_put_link(
56070 struct nameidata *nd,
56071 void *p)
56072 {
56073- char *s = nd_get_link(nd);
56074+ const char *s = nd_get_link(nd);
56075
56076 if (!IS_ERR(s))
56077 kfree(s);
56078diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
56079new file mode 100644
56080index 0000000..92247e4
56081--- /dev/null
56082+++ b/grsecurity/Kconfig
56083@@ -0,0 +1,1021 @@
56084+#
56085+# grecurity configuration
56086+#
56087+menu "Memory Protections"
56088+depends on GRKERNSEC
56089+
56090+config GRKERNSEC_KMEM
56091+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
56092+ default y if GRKERNSEC_CONFIG_AUTO
56093+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
56094+ help
56095+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
56096+ be written to or read from to modify or leak the contents of the running
56097+ kernel. /dev/port will also not be allowed to be opened and support
56098+ for /dev/cpu/*/msr will be removed. If you have module
56099+ support disabled, enabling this will close up five ways that are
56100+ currently used to insert malicious code into the running kernel.
56101+
56102+ Even with all these features enabled, we still highly recommend that
56103+ you use the RBAC system, as it is still possible for an attacker to
56104+ modify the running kernel through privileged I/O granted by ioperm/iopl.
56105+
56106+ If you are not using XFree86, you may be able to stop this additional
56107+ case by enabling the 'Disable privileged I/O' option. Though nothing
56108+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
56109+ but only to video memory, which is the only writing we allow in this
56110+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
56111+ not be allowed to mprotect it with PROT_WRITE later.
56112+ Enabling this feature will prevent the "cpupower" and "powertop" tools
56113+ from working.
56114+
56115+ It is highly recommended that you say Y here if you meet all the
56116+ conditions above.
56117+
56118+config GRKERNSEC_VM86
56119+ bool "Restrict VM86 mode"
56120+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56121+ depends on X86_32
56122+
56123+ help
56124+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
56125+ make use of a special execution mode on 32bit x86 processors called
56126+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
56127+ video cards and will still work with this option enabled. The purpose
56128+ of the option is to prevent exploitation of emulation errors in
56129+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
56130+ Nearly all users should be able to enable this option.
56131+
56132+config GRKERNSEC_IO
56133+ bool "Disable privileged I/O"
56134+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56135+ depends on X86
56136+ select RTC_CLASS
56137+ select RTC_INTF_DEV
56138+ select RTC_DRV_CMOS
56139+
56140+ help
56141+ If you say Y here, all ioperm and iopl calls will return an error.
56142+ Ioperm and iopl can be used to modify the running kernel.
56143+ Unfortunately, some programs need this access to operate properly,
56144+ the most notable of which are XFree86 and hwclock. hwclock can be
56145+ remedied by having RTC support in the kernel, so real-time
56146+ clock support is enabled if this option is enabled, to ensure
56147+ that hwclock operates correctly. XFree86 still will not
56148+ operate correctly with this option enabled, so DO NOT CHOOSE Y
56149+ IF YOU USE XFree86. If you use XFree86 and you still want to
56150+ protect your kernel against modification, use the RBAC system.
56151+
56152+config GRKERNSEC_JIT_HARDEN
56153+ bool "Harden BPF JIT against spray attacks"
56154+ default y if GRKERNSEC_CONFIG_AUTO
56155+ depends on BPF_JIT
56156+ help
56157+ If you say Y here, the native code generated by the kernel's Berkeley
56158+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
56159+ attacks that attempt to fit attacker-beneficial instructions in
56160+ 32bit immediate fields of JIT-generated native instructions. The
56161+ attacker will generally aim to cause an unintended instruction sequence
56162+ of JIT-generated native code to execute by jumping into the middle of
56163+ a generated instruction. This feature effectively randomizes the 32bit
56164+ immediate constants present in the generated code to thwart such attacks.
56165+
56166+ If you're using KERNEXEC, it's recommended that you enable this option
56167+ to supplement the hardening of the kernel.
56168+
56169+config GRKERNSEC_RAND_THREADSTACK
56170+ bool "Insert random gaps between thread stacks"
56171+ default y if GRKERNSEC_CONFIG_AUTO
56172+ depends on PAX_RANDMMAP && !PPC
56173+ help
56174+ If you say Y here, a random-sized gap will be enforced between allocated
56175+ thread stacks. Glibc's NPTL and other threading libraries that
56176+ pass MAP_STACK to the kernel for thread stack allocation are supported.
56177+ The implementation currently provides 8 bits of entropy for the gap.
56178+
56179+ Many distributions do not compile threaded remote services with the
56180+ -fstack-check argument to GCC, causing the variable-sized stack-based
56181+ allocator, alloca(), to not probe the stack on allocation. This
56182+ permits an unbounded alloca() to skip over any guard page and potentially
56183+ modify another thread's stack reliably. An enforced random gap
56184+ reduces the reliability of such an attack and increases the chance
56185+ that such a read/write to another thread's stack instead lands in
56186+ an unmapped area, causing a crash and triggering grsecurity's
56187+ anti-bruteforcing logic.
56188+
56189+config GRKERNSEC_PROC_MEMMAP
56190+ bool "Harden ASLR against information leaks and entropy reduction"
56191+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
56192+ depends on PAX_NOEXEC || PAX_ASLR
56193+ help
56194+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
56195+ give no information about the addresses of its mappings if
56196+ PaX features that rely on random addresses are enabled on the task.
56197+ In addition to sanitizing this information and disabling other
56198+ dangerous sources of information, this option causes reads of sensitive
56199+ /proc/<pid> entries where the file descriptor was opened in a different
56200+ task than the one performing the read. Such attempts are logged.
56201+ This option also limits argv/env strings for suid/sgid binaries
56202+ to 512KB to prevent a complete exhaustion of the stack entropy provided
56203+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
56204+ binaries to prevent alternative mmap layouts from being abused.
56205+
56206+ If you use PaX it is essential that you say Y here as it closes up
56207+ several holes that make full ASLR useless locally.
56208+
56209+config GRKERNSEC_BRUTE
56210+ bool "Deter exploit bruteforcing"
56211+ default y if GRKERNSEC_CONFIG_AUTO
56212+ help
56213+ If you say Y here, attempts to bruteforce exploits against forking
56214+ daemons such as apache or sshd, as well as against suid/sgid binaries
56215+ will be deterred. When a child of a forking daemon is killed by PaX
56216+ or crashes due to an illegal instruction or other suspicious signal,
56217+ the parent process will be delayed 30 seconds upon every subsequent
56218+ fork until the administrator is able to assess the situation and
56219+ restart the daemon.
56220+ In the suid/sgid case, the attempt is logged, the user has all their
56221+ processes terminated, and they are prevented from executing any further
56222+ processes for 15 minutes.
56223+ It is recommended that you also enable signal logging in the auditing
56224+ section so that logs are generated when a process triggers a suspicious
56225+ signal.
56226+ If the sysctl option is enabled, a sysctl option with name
56227+ "deter_bruteforce" is created.
56228+
56229+
56230+config GRKERNSEC_MODHARDEN
56231+ bool "Harden module auto-loading"
56232+ default y if GRKERNSEC_CONFIG_AUTO
56233+ depends on MODULES
56234+ help
56235+ If you say Y here, module auto-loading in response to use of some
56236+ feature implemented by an unloaded module will be restricted to
56237+ root users. Enabling this option helps defend against attacks
56238+ by unprivileged users who abuse the auto-loading behavior to
56239+ cause a vulnerable module to load that is then exploited.
56240+
56241+ If this option prevents a legitimate use of auto-loading for a
56242+ non-root user, the administrator can execute modprobe manually
56243+ with the exact name of the module mentioned in the alert log.
56244+ Alternatively, the administrator can add the module to the list
56245+ of modules loaded at boot by modifying init scripts.
56246+
56247+ Modification of init scripts will most likely be needed on
56248+ Ubuntu servers with encrypted home directory support enabled,
56249+ as the first non-root user logging in will cause the ecb(aes),
56250+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
56251+
56252+config GRKERNSEC_HIDESYM
56253+ bool "Hide kernel symbols"
56254+ default y if GRKERNSEC_CONFIG_AUTO
56255+ select PAX_USERCOPY_SLABS
56256+ help
56257+ If you say Y here, getting information on loaded modules, and
56258+ displaying all kernel symbols through a syscall will be restricted
56259+ to users with CAP_SYS_MODULE. For software compatibility reasons,
56260+ /proc/kallsyms will be restricted to the root user. The RBAC
56261+ system can hide that entry even from root.
56262+
56263+ This option also prevents leaking of kernel addresses through
56264+ several /proc entries.
56265+
56266+ Note that this option is only effective provided the following
56267+ conditions are met:
56268+ 1) The kernel using grsecurity is not precompiled by some distribution
56269+ 2) You have also enabled GRKERNSEC_DMESG
56270+ 3) You are using the RBAC system and hiding other files such as your
56271+ kernel image and System.map. Alternatively, enabling this option
56272+ causes the permissions on /boot, /lib/modules, and the kernel
56273+ source directory to change at compile time to prevent
56274+ reading by non-root users.
56275+ If the above conditions are met, this option will aid in providing a
56276+ useful protection against local kernel exploitation of overflows
56277+ and arbitrary read/write vulnerabilities.
56278+
56279+config GRKERNSEC_KERN_LOCKOUT
56280+ bool "Active kernel exploit response"
56281+ default y if GRKERNSEC_CONFIG_AUTO
56282+ depends on X86 || ARM || PPC || SPARC
56283+ help
56284+ If you say Y here, when a PaX alert is triggered due to suspicious
56285+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
56286+ or an OOPS occurs due to bad memory accesses, instead of just
56287+ terminating the offending process (and potentially allowing
56288+ a subsequent exploit from the same user), we will take one of two
56289+ actions:
56290+ If the user was root, we will panic the system
56291+ If the user was non-root, we will log the attempt, terminate
56292+ all processes owned by the user, then prevent them from creating
56293+ any new processes until the system is restarted
56294+ This deters repeated kernel exploitation/bruteforcing attempts
56295+ and is useful for later forensics.
56296+
56297+endmenu
56298+menu "Role Based Access Control Options"
56299+depends on GRKERNSEC
56300+
56301+config GRKERNSEC_RBAC_DEBUG
56302+ bool
56303+
56304+config GRKERNSEC_NO_RBAC
56305+ bool "Disable RBAC system"
56306+ help
56307+ If you say Y here, the /dev/grsec device will be removed from the kernel,
56308+ preventing the RBAC system from being enabled. You should only say Y
56309+ here if you have no intention of using the RBAC system, so as to prevent
56310+ an attacker with root access from misusing the RBAC system to hide files
56311+ and processes when loadable module support and /dev/[k]mem have been
56312+ locked down.
56313+
56314+config GRKERNSEC_ACL_HIDEKERN
56315+ bool "Hide kernel processes"
56316+ help
56317+ If you say Y here, all kernel threads will be hidden to all
56318+ processes but those whose subject has the "view hidden processes"
56319+ flag.
56320+
56321+config GRKERNSEC_ACL_MAXTRIES
56322+ int "Maximum tries before password lockout"
56323+ default 3
56324+ help
56325+ This option enforces the maximum number of times a user can attempt
56326+ to authorize themselves with the grsecurity RBAC system before being
56327+ denied the ability to attempt authorization again for a specified time.
56328+ The lower the number, the harder it will be to brute-force a password.
56329+
56330+config GRKERNSEC_ACL_TIMEOUT
56331+ int "Time to wait after max password tries, in seconds"
56332+ default 30
56333+ help
56334+ This option specifies the time the user must wait after attempting to
56335+ authorize to the RBAC system with the maximum number of invalid
56336+ passwords. The higher the number, the harder it will be to brute-force
56337+ a password.
56338+
56339+endmenu
56340+menu "Filesystem Protections"
56341+depends on GRKERNSEC
56342+
56343+config GRKERNSEC_PROC
56344+ bool "Proc restrictions"
56345+ default y if GRKERNSEC_CONFIG_AUTO
56346+ help
56347+ If you say Y here, the permissions of the /proc filesystem
56348+ will be altered to enhance system security and privacy. You MUST
56349+ choose either a user only restriction or a user and group restriction.
56350+ Depending upon the option you choose, you can either restrict users to
56351+ see only the processes they themselves run, or choose a group that can
56352+ view all processes and files normally restricted to root if you choose
56353+ the "restrict to user only" option. NOTE: If you're running identd or
56354+ ntpd as a non-root user, you will have to run it as the group you
56355+ specify here.
56356+
56357+config GRKERNSEC_PROC_USER
56358+ bool "Restrict /proc to user only"
56359+ depends on GRKERNSEC_PROC
56360+ help
56361+ If you say Y here, non-root users will only be able to view their own
56362+ processes, and restricts them from viewing network-related information,
56363+ and viewing kernel symbol and module information.
56364+
56365+config GRKERNSEC_PROC_USERGROUP
56366+ bool "Allow special group"
56367+ default y if GRKERNSEC_CONFIG_AUTO
56368+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
56369+ help
56370+ If you say Y here, you will be able to select a group that will be
56371+ able to view all processes and network-related information. If you've
56372+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
56373+ remain hidden. This option is useful if you want to run identd as
56374+ a non-root user. The group you select may also be chosen at boot time
56375+ via "grsec_proc_gid=" on the kernel commandline.
56376+
56377+config GRKERNSEC_PROC_GID
56378+ int "GID for special group"
56379+ depends on GRKERNSEC_PROC_USERGROUP
56380+ default 1001
56381+
56382+config GRKERNSEC_PROC_ADD
56383+ bool "Additional restrictions"
56384+ default y if GRKERNSEC_CONFIG_AUTO
56385+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
56386+ help
56387+ If you say Y here, additional restrictions will be placed on
56388+ /proc that keep normal users from viewing device information and
56389+ slabinfo information that could be useful for exploits.
56390+
56391+config GRKERNSEC_LINK
56392+ bool "Linking restrictions"
56393+ default y if GRKERNSEC_CONFIG_AUTO
56394+ help
56395+ If you say Y here, /tmp race exploits will be prevented, since users
56396+ will no longer be able to follow symlinks owned by other users in
56397+ world-writable +t directories (e.g. /tmp), unless the owner of the
56398+ symlink is the owner of the directory. users will also not be
56399+ able to hardlink to files they do not own. If the sysctl option is
56400+ enabled, a sysctl option with name "linking_restrictions" is created.
56401+
56402+config GRKERNSEC_SYMLINKOWN
56403+ bool "Kernel-enforced SymlinksIfOwnerMatch"
56404+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56405+ help
56406+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
56407+ that prevents it from being used as a security feature. As Apache
56408+ verifies the symlink by performing a stat() against the target of
56409+ the symlink before it is followed, an attacker can setup a symlink
56410+ to point to a same-owned file, then replace the symlink with one
56411+ that targets another user's file just after Apache "validates" the
56412+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
56413+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
56414+ will be in place for the group you specify. If the sysctl option
56415+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
56416+ created.
56417+
56418+config GRKERNSEC_SYMLINKOWN_GID
56419+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
56420+ depends on GRKERNSEC_SYMLINKOWN
56421+ default 1006
56422+ help
56423+ Setting this GID determines what group kernel-enforced
56424+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
56425+ is enabled, a sysctl option with name "symlinkown_gid" is created.
56426+
56427+config GRKERNSEC_FIFO
56428+ bool "FIFO restrictions"
56429+ default y if GRKERNSEC_CONFIG_AUTO
56430+ help
56431+ If you say Y here, users will not be able to write to FIFOs they don't
56432+ own in world-writable +t directories (e.g. /tmp), unless the owner of
56433+ the FIFO is the same owner of the directory it's held in. If the sysctl
56434+ option is enabled, a sysctl option with name "fifo_restrictions" is
56435+ created.
56436+
56437+config GRKERNSEC_SYSFS_RESTRICT
56438+ bool "Sysfs/debugfs restriction"
56439+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56440+ depends on SYSFS
56441+ help
56442+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56443+ any filesystem normally mounted under it (e.g. debugfs) will be
56444+ mostly accessible only by root. These filesystems generally provide access
56445+ to hardware and debug information that isn't appropriate for unprivileged
56446+ users of the system. Sysfs and debugfs have also become a large source
56447+ of new vulnerabilities, ranging from infoleaks to local compromise.
56448+ There has been very little oversight with an eye toward security involved
56449+ in adding new exporters of information to these filesystems, so their
56450+ use is discouraged.
56451+ For reasons of compatibility, a few directories have been whitelisted
56452+ for access by non-root users:
56453+ /sys/fs/selinux
56454+ /sys/fs/fuse
56455+ /sys/devices/system/cpu
56456+
56457+config GRKERNSEC_ROFS
56458+ bool "Runtime read-only mount protection"
56459+ help
56460+ If you say Y here, a sysctl option with name "romount_protect" will
56461+ be created. By setting this option to 1 at runtime, filesystems
56462+ will be protected in the following ways:
56463+ * No new writable mounts will be allowed
56464+ * Existing read-only mounts won't be able to be remounted read/write
56465+ * Write operations will be denied on all block devices
56466+ This option acts independently of grsec_lock: once it is set to 1,
56467+ it cannot be turned off. Therefore, please be mindful of the resulting
56468+ behavior if this option is enabled in an init script on a read-only
56469+ filesystem. This feature is mainly intended for secure embedded systems.
56470+
56471+config GRKERNSEC_DEVICE_SIDECHANNEL
56472+ bool "Eliminate stat/notify-based device sidechannels"
56473+ default y if GRKERNSEC_CONFIG_AUTO
56474+ help
56475+ If you say Y here, timing analyses on block or character
56476+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
56477+ will be thwarted for unprivileged users. If a process without
56478+ CAP_MKNOD stats such a device, the last access and last modify times
56479+ will match the device's create time. No access or modify events
56480+ will be triggered through inotify/dnotify/fanotify for such devices.
56481+ This feature will prevent attacks that may at a minimum
56482+ allow an attacker to determine the administrator's password length.
56483+
56484+config GRKERNSEC_CHROOT
56485+ bool "Chroot jail restrictions"
56486+ default y if GRKERNSEC_CONFIG_AUTO
56487+ help
56488+ If you say Y here, you will be able to choose several options that will
56489+ make breaking out of a chrooted jail much more difficult. If you
56490+ encounter no software incompatibilities with the following options, it
56491+ is recommended that you enable each one.
56492+
56493+config GRKERNSEC_CHROOT_MOUNT
56494+ bool "Deny mounts"
56495+ default y if GRKERNSEC_CONFIG_AUTO
56496+ depends on GRKERNSEC_CHROOT
56497+ help
56498+ If you say Y here, processes inside a chroot will not be able to
56499+ mount or remount filesystems. If the sysctl option is enabled, a
56500+ sysctl option with name "chroot_deny_mount" is created.
56501+
56502+config GRKERNSEC_CHROOT_DOUBLE
56503+ bool "Deny double-chroots"
56504+ default y if GRKERNSEC_CONFIG_AUTO
56505+ depends on GRKERNSEC_CHROOT
56506+ help
56507+ If you say Y here, processes inside a chroot will not be able to chroot
56508+ again outside the chroot. This is a widely used method of breaking
56509+ out of a chroot jail and should not be allowed. If the sysctl
56510+ option is enabled, a sysctl option with name
56511+ "chroot_deny_chroot" is created.
56512+
56513+config GRKERNSEC_CHROOT_PIVOT
56514+ bool "Deny pivot_root in chroot"
56515+ default y if GRKERNSEC_CONFIG_AUTO
56516+ depends on GRKERNSEC_CHROOT
56517+ help
56518+ If you say Y here, processes inside a chroot will not be able to use
56519+ a function called pivot_root() that was introduced in Linux 2.3.41. It
56520+ works similar to chroot in that it changes the root filesystem. This
56521+ function could be misused in a chrooted process to attempt to break out
56522+ of the chroot, and therefore should not be allowed. If the sysctl
56523+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
56524+ created.
56525+
56526+config GRKERNSEC_CHROOT_CHDIR
56527+ bool "Enforce chdir(\"/\") on all chroots"
56528+ default y if GRKERNSEC_CONFIG_AUTO
56529+ depends on GRKERNSEC_CHROOT
56530+ help
56531+ If you say Y here, the current working directory of all newly-chrooted
56532+ applications will be set to the the root directory of the chroot.
56533+ The man page on chroot(2) states:
56534+ Note that this call does not change the current working
56535+ directory, so that `.' can be outside the tree rooted at
56536+ `/'. In particular, the super-user can escape from a
56537+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56538+
56539+ It is recommended that you say Y here, since it's not known to break
56540+ any software. If the sysctl option is enabled, a sysctl option with
56541+ name "chroot_enforce_chdir" is created.
56542+
56543+config GRKERNSEC_CHROOT_CHMOD
56544+ bool "Deny (f)chmod +s"
56545+ default y if GRKERNSEC_CONFIG_AUTO
56546+ depends on GRKERNSEC_CHROOT
56547+ help
56548+ If you say Y here, processes inside a chroot will not be able to chmod
56549+ or fchmod files to make them have suid or sgid bits. This protects
56550+ against another published method of breaking a chroot. If the sysctl
56551+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
56552+ created.
56553+
56554+config GRKERNSEC_CHROOT_FCHDIR
56555+ bool "Deny fchdir out of chroot"
56556+ default y if GRKERNSEC_CONFIG_AUTO
56557+ depends on GRKERNSEC_CHROOT
56558+ help
56559+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
56560+ to a file descriptor of the chrooting process that points to a directory
56561+ outside the filesystem will be stopped. If the sysctl option
56562+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56563+
56564+config GRKERNSEC_CHROOT_MKNOD
56565+ bool "Deny mknod"
56566+ default y if GRKERNSEC_CONFIG_AUTO
56567+ depends on GRKERNSEC_CHROOT
56568+ help
56569+ If you say Y here, processes inside a chroot will not be allowed to
56570+ mknod. The problem with using mknod inside a chroot is that it
56571+ would allow an attacker to create a device entry that is the same
56572+ as one on the physical root of your system, which could range from
56573+ anything from the console device to a device for your harddrive (which
56574+ they could then use to wipe the drive or steal data). It is recommended
56575+ that you say Y here, unless you run into software incompatibilities.
56576+ If the sysctl option is enabled, a sysctl option with name
56577+ "chroot_deny_mknod" is created.
56578+
56579+config GRKERNSEC_CHROOT_SHMAT
56580+ bool "Deny shmat() out of chroot"
56581+ default y if GRKERNSEC_CONFIG_AUTO
56582+ depends on GRKERNSEC_CHROOT
56583+ help
56584+ If you say Y here, processes inside a chroot will not be able to attach
56585+ to shared memory segments that were created outside of the chroot jail.
56586+ It is recommended that you say Y here. If the sysctl option is enabled,
56587+ a sysctl option with name "chroot_deny_shmat" is created.
56588+
56589+config GRKERNSEC_CHROOT_UNIX
56590+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
56591+ default y if GRKERNSEC_CONFIG_AUTO
56592+ depends on GRKERNSEC_CHROOT
56593+ help
56594+ If you say Y here, processes inside a chroot will not be able to
56595+ connect to abstract (meaning not belonging to a filesystem) Unix
56596+ domain sockets that were bound outside of a chroot. It is recommended
56597+ that you say Y here. If the sysctl option is enabled, a sysctl option
56598+ with name "chroot_deny_unix" is created.
56599+
56600+config GRKERNSEC_CHROOT_FINDTASK
56601+ bool "Protect outside processes"
56602+ default y if GRKERNSEC_CONFIG_AUTO
56603+ depends on GRKERNSEC_CHROOT
56604+ help
56605+ If you say Y here, processes inside a chroot will not be able to
56606+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56607+ getsid, or view any process outside of the chroot. If the sysctl
56608+ option is enabled, a sysctl option with name "chroot_findtask" is
56609+ created.
56610+
56611+config GRKERNSEC_CHROOT_NICE
56612+ bool "Restrict priority changes"
56613+ default y if GRKERNSEC_CONFIG_AUTO
56614+ depends on GRKERNSEC_CHROOT
56615+ help
56616+ If you say Y here, processes inside a chroot will not be able to raise
56617+ the priority of processes in the chroot, or alter the priority of
56618+ processes outside the chroot. This provides more security than simply
56619+ removing CAP_SYS_NICE from the process' capability set. If the
56620+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56621+ is created.
56622+
56623+config GRKERNSEC_CHROOT_SYSCTL
56624+ bool "Deny sysctl writes"
56625+ default y if GRKERNSEC_CONFIG_AUTO
56626+ depends on GRKERNSEC_CHROOT
56627+ help
56628+ If you say Y here, an attacker in a chroot will not be able to
56629+ write to sysctl entries, either by sysctl(2) or through a /proc
56630+ interface. It is strongly recommended that you say Y here. If the
56631+ sysctl option is enabled, a sysctl option with name
56632+ "chroot_deny_sysctl" is created.
56633+
56634+config GRKERNSEC_CHROOT_CAPS
56635+ bool "Capability restrictions"
56636+ default y if GRKERNSEC_CONFIG_AUTO
56637+ depends on GRKERNSEC_CHROOT
56638+ help
56639+ If you say Y here, the capabilities on all processes within a
56640+ chroot jail will be lowered to stop module insertion, raw i/o,
56641+ system and net admin tasks, rebooting the system, modifying immutable
56642+ files, modifying IPC owned by another, and changing the system time.
56643+ This is left an option because it can break some apps. Disable this
56644+ if your chrooted apps are having problems performing those kinds of
56645+ tasks. If the sysctl option is enabled, a sysctl option with
56646+ name "chroot_caps" is created.
56647+
56648+endmenu
56649+menu "Kernel Auditing"
56650+depends on GRKERNSEC
56651+
56652+config GRKERNSEC_AUDIT_GROUP
56653+ bool "Single group for auditing"
56654+ help
56655+ If you say Y here, the exec and chdir logging features will only operate
56656+ on a group you specify. This option is recommended if you only want to
56657+ watch certain users instead of having a large amount of logs from the
56658+ entire system. If the sysctl option is enabled, a sysctl option with
56659+ name "audit_group" is created.
56660+
56661+config GRKERNSEC_AUDIT_GID
56662+ int "GID for auditing"
56663+ depends on GRKERNSEC_AUDIT_GROUP
56664+ default 1007
56665+
56666+config GRKERNSEC_EXECLOG
56667+ bool "Exec logging"
56668+ help
56669+ If you say Y here, all execve() calls will be logged (since the
56670+ other exec*() calls are frontends to execve(), all execution
56671+ will be logged). Useful for shell-servers that like to keep track
56672+ of their users. If the sysctl option is enabled, a sysctl option with
56673+ name "exec_logging" is created.
56674+ WARNING: This option when enabled will produce a LOT of logs, especially
56675+ on an active system.
56676+
56677+config GRKERNSEC_RESLOG
56678+ bool "Resource logging"
56679+ default y if GRKERNSEC_CONFIG_AUTO
56680+ help
56681+ If you say Y here, all attempts to overstep resource limits will
56682+ be logged with the resource name, the requested size, and the current
56683+ limit. It is highly recommended that you say Y here. If the sysctl
56684+ option is enabled, a sysctl option with name "resource_logging" is
56685+ created. If the RBAC system is enabled, the sysctl value is ignored.
56686+
56687+config GRKERNSEC_CHROOT_EXECLOG
56688+ bool "Log execs within chroot"
56689+ help
56690+ If you say Y here, all executions inside a chroot jail will be logged
56691+ to syslog. This can cause a large amount of logs if certain
56692+ applications (eg. djb's daemontools) are installed on the system, and
56693+ is therefore left as an option. If the sysctl option is enabled, a
56694+ sysctl option with name "chroot_execlog" is created.
56695+
56696+config GRKERNSEC_AUDIT_PTRACE
56697+ bool "Ptrace logging"
56698+ help
56699+ If you say Y here, all attempts to attach to a process via ptrace
56700+ will be logged. If the sysctl option is enabled, a sysctl option
56701+ with name "audit_ptrace" is created.
56702+
56703+config GRKERNSEC_AUDIT_CHDIR
56704+ bool "Chdir logging"
56705+ help
56706+ If you say Y here, all chdir() calls will be logged. If the sysctl
56707+ option is enabled, a sysctl option with name "audit_chdir" is created.
56708+
56709+config GRKERNSEC_AUDIT_MOUNT
56710+ bool "(Un)Mount logging"
56711+ help
56712+ If you say Y here, all mounts and unmounts will be logged. If the
56713+ sysctl option is enabled, a sysctl option with name "audit_mount" is
56714+ created.
56715+
56716+config GRKERNSEC_SIGNAL
56717+ bool "Signal logging"
56718+ default y if GRKERNSEC_CONFIG_AUTO
56719+ help
56720+ If you say Y here, certain important signals will be logged, such as
56721+ SIGSEGV, which will as a result inform you of when a error in a program
56722+ occurred, which in some cases could mean a possible exploit attempt.
56723+ If the sysctl option is enabled, a sysctl option with name
56724+ "signal_logging" is created.
56725+
56726+config GRKERNSEC_FORKFAIL
56727+ bool "Fork failure logging"
56728+ help
56729+ If you say Y here, all failed fork() attempts will be logged.
56730+ This could suggest a fork bomb, or someone attempting to overstep
56731+ their process limit. If the sysctl option is enabled, a sysctl option
56732+ with name "forkfail_logging" is created.
56733+
56734+config GRKERNSEC_TIME
56735+ bool "Time change logging"
56736+ default y if GRKERNSEC_CONFIG_AUTO
56737+ help
56738+ If you say Y here, any changes of the system clock will be logged.
56739+ If the sysctl option is enabled, a sysctl option with name
56740+ "timechange_logging" is created.
56741+
56742+config GRKERNSEC_PROC_IPADDR
56743+ bool "/proc/<pid>/ipaddr support"
56744+ default y if GRKERNSEC_CONFIG_AUTO
56745+ help
56746+ If you say Y here, a new entry will be added to each /proc/<pid>
56747+ directory that contains the IP address of the person using the task.
56748+ The IP is carried across local TCP and AF_UNIX stream sockets.
56749+ This information can be useful for IDS/IPSes to perform remote response
56750+ to a local attack. The entry is readable by only the owner of the
56751+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56752+ the RBAC system), and thus does not create privacy concerns.
56753+
56754+config GRKERNSEC_RWXMAP_LOG
56755+ bool 'Denied RWX mmap/mprotect logging'
56756+ default y if GRKERNSEC_CONFIG_AUTO
56757+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56758+ help
56759+ If you say Y here, calls to mmap() and mprotect() with explicit
56760+ usage of PROT_WRITE and PROT_EXEC together will be logged when
56761+ denied by the PAX_MPROTECT feature. If the sysctl option is
56762+ enabled, a sysctl option with name "rwxmap_logging" is created.
56763+
56764+config GRKERNSEC_AUDIT_TEXTREL
56765+ bool 'ELF text relocations logging (READ HELP)'
56766+ depends on PAX_MPROTECT
56767+ help
56768+ If you say Y here, text relocations will be logged with the filename
56769+ of the offending library or binary. The purpose of the feature is
56770+ to help Linux distribution developers get rid of libraries and
56771+ binaries that need text relocations which hinder the future progress
56772+ of PaX. Only Linux distribution developers should say Y here, and
56773+ never on a production machine, as this option creates an information
56774+ leak that could aid an attacker in defeating the randomization of
56775+ a single memory region. If the sysctl option is enabled, a sysctl
56776+ option with name "audit_textrel" is created.
56777+
56778+endmenu
56779+
56780+menu "Executable Protections"
56781+depends on GRKERNSEC
56782+
56783+config GRKERNSEC_DMESG
56784+ bool "Dmesg(8) restriction"
56785+ default y if GRKERNSEC_CONFIG_AUTO
56786+ help
56787+ If you say Y here, non-root users will not be able to use dmesg(8)
56788+ to view the contents of the kernel's circular log buffer.
56789+ The kernel's log buffer often contains kernel addresses and other
56790+ identifying information useful to an attacker in fingerprinting a
56791+ system for a targeted exploit.
56792+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
56793+ created.
56794+
56795+config GRKERNSEC_HARDEN_PTRACE
56796+ bool "Deter ptrace-based process snooping"
56797+ default y if GRKERNSEC_CONFIG_AUTO
56798+ help
56799+ If you say Y here, TTY sniffers and other malicious monitoring
56800+ programs implemented through ptrace will be defeated. If you
56801+ have been using the RBAC system, this option has already been
56802+ enabled for several years for all users, with the ability to make
56803+ fine-grained exceptions.
56804+
56805+ This option only affects the ability of non-root users to ptrace
56806+ processes that are not a descendent of the ptracing process.
56807+ This means that strace ./binary and gdb ./binary will still work,
56808+ but attaching to arbitrary processes will not. If the sysctl
56809+ option is enabled, a sysctl option with name "harden_ptrace" is
56810+ created.
56811+
56812+config GRKERNSEC_PTRACE_READEXEC
56813+ bool "Require read access to ptrace sensitive binaries"
56814+ default y if GRKERNSEC_CONFIG_AUTO
56815+ help
56816+ If you say Y here, unprivileged users will not be able to ptrace unreadable
56817+ binaries. This option is useful in environments that
56818+ remove the read bits (e.g. file mode 4711) from suid binaries to
56819+ prevent infoleaking of their contents. This option adds
56820+ consistency to the use of that file mode, as the binary could normally
56821+ be read out when run without privileges while ptracing.
56822+
56823+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
56824+ is created.
56825+
56826+config GRKERNSEC_SETXID
56827+ bool "Enforce consistent multithreaded privileges"
56828+ default y if GRKERNSEC_CONFIG_AUTO
56829+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
56830+ help
56831+ If you say Y here, a change from a root uid to a non-root uid
56832+ in a multithreaded application will cause the resulting uids,
56833+ gids, supplementary groups, and capabilities in that thread
56834+ to be propagated to the other threads of the process. In most
56835+ cases this is unnecessary, as glibc will emulate this behavior
56836+ on behalf of the application. Other libcs do not act in the
56837+ same way, allowing the other threads of the process to continue
56838+ running with root privileges. If the sysctl option is enabled,
56839+ a sysctl option with name "consistent_setxid" is created.
56840+
56841+config GRKERNSEC_TPE
56842+ bool "Trusted Path Execution (TPE)"
56843+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56844+ help
56845+ If you say Y here, you will be able to choose a gid to add to the
56846+ supplementary groups of users you want to mark as "untrusted."
56847+ These users will not be able to execute any files that are not in
56848+ root-owned directories writable only by root. If the sysctl option
56849+ is enabled, a sysctl option with name "tpe" is created.
56850+
56851+config GRKERNSEC_TPE_ALL
56852+ bool "Partially restrict all non-root users"
56853+ depends on GRKERNSEC_TPE
56854+ help
56855+ If you say Y here, all non-root users will be covered under
56856+ a weaker TPE restriction. This is separate from, and in addition to,
56857+ the main TPE options that you have selected elsewhere. Thus, if a
56858+ "trusted" GID is chosen, this restriction applies to even that GID.
56859+ Under this restriction, all non-root users will only be allowed to
56860+ execute files in directories they own that are not group or
56861+ world-writable, or in directories owned by root and writable only by
56862+ root. If the sysctl option is enabled, a sysctl option with name
56863+ "tpe_restrict_all" is created.
56864+
56865+config GRKERNSEC_TPE_INVERT
56866+ bool "Invert GID option"
56867+ depends on GRKERNSEC_TPE
56868+ help
56869+ If you say Y here, the group you specify in the TPE configuration will
56870+ decide what group TPE restrictions will be *disabled* for. This
56871+ option is useful if you want TPE restrictions to be applied to most
56872+ users on the system. If the sysctl option is enabled, a sysctl option
56873+ with name "tpe_invert" is created. Unlike other sysctl options, this
56874+ entry will default to on for backward-compatibility.
56875+
56876+config GRKERNSEC_TPE_GID
56877+ int
56878+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
56879+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
56880+
56881+config GRKERNSEC_TPE_UNTRUSTED_GID
56882+ int "GID for TPE-untrusted users"
56883+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56884+ default 1005
56885+ help
56886+ Setting this GID determines what group TPE restrictions will be
56887+ *enabled* for. If the sysctl option is enabled, a sysctl option
56888+ with name "tpe_gid" is created.
56889+
56890+config GRKERNSEC_TPE_TRUSTED_GID
56891+ int "GID for TPE-trusted users"
56892+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56893+ default 1005
56894+ help
56895+ Setting this GID determines what group TPE restrictions will be
56896+ *disabled* for. If the sysctl option is enabled, a sysctl option
56897+ with name "tpe_gid" is created.
56898+
56899+endmenu
56900+menu "Network Protections"
56901+depends on GRKERNSEC
56902+
56903+config GRKERNSEC_RANDNET
56904+ bool "Larger entropy pools"
56905+ default y if GRKERNSEC_CONFIG_AUTO
56906+ help
56907+ If you say Y here, the entropy pools used for many features of Linux
56908+ and grsecurity will be doubled in size. Since several grsecurity
56909+ features use additional randomness, it is recommended that you say Y
56910+ here. Saying Y here has a similar effect as modifying
56911+ /proc/sys/kernel/random/poolsize.
56912+
56913+config GRKERNSEC_BLACKHOLE
56914+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
56915+ default y if GRKERNSEC_CONFIG_AUTO
56916+ depends on NET
56917+ help
56918+ If you say Y here, neither TCP resets nor ICMP
56919+ destination-unreachable packets will be sent in response to packets
56920+ sent to ports for which no associated listening process exists.
56921+ This feature supports both IPV4 and IPV6 and exempts the
56922+ loopback interface from blackholing. Enabling this feature
56923+ makes a host more resilient to DoS attacks and reduces network
56924+ visibility against scanners.
56925+
56926+ The blackhole feature as-implemented is equivalent to the FreeBSD
56927+ blackhole feature, as it prevents RST responses to all packets, not
56928+ just SYNs. Under most application behavior this causes no
56929+ problems, but applications (like haproxy) may not close certain
56930+ connections in a way that cleanly terminates them on the remote
56931+ end, leaving the remote host in LAST_ACK state. Because of this
56932+ side-effect and to prevent intentional LAST_ACK DoSes, this
56933+ feature also adds automatic mitigation against such attacks.
56934+ The mitigation drastically reduces the amount of time a socket
56935+ can spend in LAST_ACK state. If you're using haproxy and not
56936+ all servers it connects to have this option enabled, consider
56937+ disabling this feature on the haproxy host.
56938+
56939+ If the sysctl option is enabled, two sysctl options with names
56940+ "ip_blackhole" and "lastack_retries" will be created.
56941+ While "ip_blackhole" takes the standard zero/non-zero on/off
56942+ toggle, "lastack_retries" uses the same kinds of values as
56943+ "tcp_retries1" and "tcp_retries2". The default value of 4
56944+ prevents a socket from lasting more than 45 seconds in LAST_ACK
56945+ state.
56946+
56947+config GRKERNSEC_NO_SIMULT_CONNECT
56948+ bool "Disable TCP Simultaneous Connect"
56949+ default y if GRKERNSEC_CONFIG_AUTO
56950+ depends on NET
56951+ help
56952+ If you say Y here, a feature by Willy Tarreau will be enabled that
56953+ removes a weakness in Linux's strict implementation of TCP that
56954+ allows two clients to connect to each other without either entering
56955+ a listening state. The weakness allows an attacker to easily prevent
56956+ a client from connecting to a known server provided the source port
56957+ for the connection is guessed correctly.
56958+
56959+ As the weakness could be used to prevent an antivirus or IPS from
56960+ fetching updates, or prevent an SSL gateway from fetching a CRL,
56961+ it should be eliminated by enabling this option. Though Linux is
56962+ one of few operating systems supporting simultaneous connect, it
56963+ has no legitimate use in practice and is rarely supported by firewalls.
56964+
56965+config GRKERNSEC_SOCKET
56966+ bool "Socket restrictions"
56967+ depends on NET
56968+ help
56969+ If you say Y here, you will be able to choose from several options.
56970+ If you assign a GID on your system and add it to the supplementary
56971+ groups of users you want to restrict socket access to, this patch
56972+ will perform up to three things, based on the option(s) you choose.
56973+
56974+config GRKERNSEC_SOCKET_ALL
56975+ bool "Deny any sockets to group"
56976+ depends on GRKERNSEC_SOCKET
56977+ help
56978+ If you say Y here, you will be able to choose a GID of whose users will
56979+ be unable to connect to other hosts from your machine or run server
56980+ applications from your machine. If the sysctl option is enabled, a
56981+ sysctl option with name "socket_all" is created.
56982+
56983+config GRKERNSEC_SOCKET_ALL_GID
56984+ int "GID to deny all sockets for"
56985+ depends on GRKERNSEC_SOCKET_ALL
56986+ default 1004
56987+ help
56988+ Here you can choose the GID to disable socket access for. Remember to
56989+ add the users you want socket access disabled for to the GID
56990+ specified here. If the sysctl option is enabled, a sysctl option
56991+ with name "socket_all_gid" is created.
56992+
56993+config GRKERNSEC_SOCKET_CLIENT
56994+ bool "Deny client sockets to group"
56995+ depends on GRKERNSEC_SOCKET
56996+ help
56997+ If you say Y here, you will be able to choose a GID of whose users will
56998+ be unable to connect to other hosts from your machine, but will be
56999+ able to run servers. If this option is enabled, all users in the group
57000+ you specify will have to use passive mode when initiating ftp transfers
57001+ from the shell on your machine. If the sysctl option is enabled, a
57002+ sysctl option with name "socket_client" is created.
57003+
57004+config GRKERNSEC_SOCKET_CLIENT_GID
57005+ int "GID to deny client sockets for"
57006+ depends on GRKERNSEC_SOCKET_CLIENT
57007+ default 1003
57008+ help
57009+ Here you can choose the GID to disable client socket access for.
57010+ Remember to add the users you want client socket access disabled for to
57011+ the GID specified here. If the sysctl option is enabled, a sysctl
57012+ option with name "socket_client_gid" is created.
57013+
57014+config GRKERNSEC_SOCKET_SERVER
57015+ bool "Deny server sockets to group"
57016+ depends on GRKERNSEC_SOCKET
57017+ help
57018+ If you say Y here, you will be able to choose a GID of whose users will
57019+ be unable to run server applications from your machine. If the sysctl
57020+ option is enabled, a sysctl option with name "socket_server" is created.
57021+
57022+config GRKERNSEC_SOCKET_SERVER_GID
57023+ int "GID to deny server sockets for"
57024+ depends on GRKERNSEC_SOCKET_SERVER
57025+ default 1002
57026+ help
57027+ Here you can choose the GID to disable server socket access for.
57028+ Remember to add the users you want server socket access disabled for to
57029+ the GID specified here. If the sysctl option is enabled, a sysctl
57030+ option with name "socket_server_gid" is created.
57031+
57032+endmenu
57033+menu "Sysctl Support"
57034+depends on GRKERNSEC && SYSCTL
57035+
57036+config GRKERNSEC_SYSCTL
57037+ bool "Sysctl support"
57038+ default y if GRKERNSEC_CONFIG_AUTO
57039+ help
57040+ If you say Y here, you will be able to change the options that
57041+ grsecurity runs with at bootup, without having to recompile your
57042+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
57043+ to enable (1) or disable (0) various features. All the sysctl entries
57044+ are mutable until the "grsec_lock" entry is set to a non-zero value.
57045+ All features enabled in the kernel configuration are disabled at boot
57046+ if you do not say Y to the "Turn on features by default" option.
57047+ All options should be set at startup, and the grsec_lock entry should
57048+ be set to a non-zero value after all the options are set.
57049+ *THIS IS EXTREMELY IMPORTANT*
57050+
57051+config GRKERNSEC_SYSCTL_DISTRO
57052+ bool "Extra sysctl support for distro makers (READ HELP)"
57053+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
57054+ help
57055+ If you say Y here, additional sysctl options will be created
57056+ for features that affect processes running as root. Therefore,
57057+ it is critical when using this option that the grsec_lock entry be
57058+ enabled after boot. Only distros with prebuilt kernel packages
57059+ with this option enabled that can ensure grsec_lock is enabled
57060+ after boot should use this option.
57061+ *Failure to set grsec_lock after boot makes all grsec features
57062+ this option covers useless*
57063+
57064+ Currently this option creates the following sysctl entries:
57065+ "Disable Privileged I/O": "disable_priv_io"
57066+
57067+config GRKERNSEC_SYSCTL_ON
57068+ bool "Turn on features by default"
57069+ default y if GRKERNSEC_CONFIG_AUTO
57070+ depends on GRKERNSEC_SYSCTL
57071+ help
57072+ If you say Y here, instead of having all features enabled in the
57073+ kernel configuration disabled at boot time, the features will be
57074+ enabled at boot time. It is recommended you say Y here unless
57075+ there is some reason you would want all sysctl-tunable features to
57076+ be disabled by default. As mentioned elsewhere, it is important
57077+ to enable the grsec_lock entry once you have finished modifying
57078+ the sysctl entries.
57079+
57080+endmenu
57081+menu "Logging Options"
57082+depends on GRKERNSEC
57083+
57084+config GRKERNSEC_FLOODTIME
57085+ int "Seconds in between log messages (minimum)"
57086+ default 10
57087+ help
57088+ This option allows you to enforce the number of seconds between
57089+ grsecurity log messages. The default should be suitable for most
57090+ people, however, if you choose to change it, choose a value small enough
57091+ to allow informative logs to be produced, but large enough to
57092+ prevent flooding.
57093+
57094+config GRKERNSEC_FLOODBURST
57095+ int "Number of messages in a burst (maximum)"
57096+ default 6
57097+ help
57098+ This option allows you to choose the maximum number of messages allowed
57099+ within the flood time interval you chose in a separate option. The
57100+ default should be suitable for most people, however if you find that
57101+ many of your logs are being interpreted as flooding, you may want to
57102+ raise this value.
57103+
57104+endmenu
57105diff --git a/grsecurity/Makefile b/grsecurity/Makefile
57106new file mode 100644
57107index 0000000..1b9afa9
57108--- /dev/null
57109+++ b/grsecurity/Makefile
57110@@ -0,0 +1,38 @@
57111+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
57112+# during 2001-2009 it has been completely redesigned by Brad Spengler
57113+# into an RBAC system
57114+#
57115+# All code in this directory and various hooks inserted throughout the kernel
57116+# are copyright Brad Spengler - Open Source Security, Inc., and released
57117+# under the GPL v2 or higher
57118+
57119+KBUILD_CFLAGS += -Werror
57120+
57121+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
57122+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
57123+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
57124+
57125+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
57126+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
57127+ gracl_learn.o grsec_log.o
57128+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
57129+
57130+ifdef CONFIG_NET
57131+obj-y += grsec_sock.o
57132+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
57133+endif
57134+
57135+ifndef CONFIG_GRKERNSEC
57136+obj-y += grsec_disabled.o
57137+endif
57138+
57139+ifdef CONFIG_GRKERNSEC_HIDESYM
57140+extra-y := grsec_hidesym.o
57141+$(obj)/grsec_hidesym.o:
57142+ @-chmod -f 500 /boot
57143+ @-chmod -f 500 /lib/modules
57144+ @-chmod -f 500 /lib64/modules
57145+ @-chmod -f 500 /lib32/modules
57146+ @-chmod -f 700 .
57147+ @echo ' grsec: protected kernel image paths'
57148+endif
57149diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
57150new file mode 100644
57151index 0000000..ab45812
57152--- /dev/null
57153+++ b/grsecurity/gracl.c
57154@@ -0,0 +1,4071 @@
57155+#include <linux/kernel.h>
57156+#include <linux/module.h>
57157+#include <linux/sched.h>
57158+#include <linux/mm.h>
57159+#include <linux/file.h>
57160+#include <linux/fs.h>
57161+#include <linux/namei.h>
57162+#include <linux/mount.h>
57163+#include <linux/tty.h>
57164+#include <linux/proc_fs.h>
57165+#include <linux/lglock.h>
57166+#include <linux/slab.h>
57167+#include <linux/vmalloc.h>
57168+#include <linux/types.h>
57169+#include <linux/sysctl.h>
57170+#include <linux/netdevice.h>
57171+#include <linux/ptrace.h>
57172+#include <linux/gracl.h>
57173+#include <linux/gralloc.h>
57174+#include <linux/security.h>
57175+#include <linux/grinternal.h>
57176+#include <linux/pid_namespace.h>
57177+#include <linux/stop_machine.h>
57178+#include <linux/fdtable.h>
57179+#include <linux/percpu.h>
57180+#include <linux/lglock.h>
57181+#include <linux/hugetlb.h>
57182+#include <linux/posix-timers.h>
57183+#include "../fs/mount.h"
57184+
57185+#include <asm/uaccess.h>
57186+#include <asm/errno.h>
57187+#include <asm/mman.h>
57188+
57189+extern struct lglock vfsmount_lock;
57190+
57191+static struct acl_role_db acl_role_set;
57192+static struct name_db name_set;
57193+static struct inodev_db inodev_set;
57194+
57195+/* for keeping track of userspace pointers used for subjects, so we
57196+ can share references in the kernel as well
57197+*/
57198+
57199+static struct path real_root;
57200+
57201+static struct acl_subj_map_db subj_map_set;
57202+
57203+static struct acl_role_label *default_role;
57204+
57205+static struct acl_role_label *role_list;
57206+
57207+static u16 acl_sp_role_value;
57208+
57209+extern char *gr_shared_page[4];
57210+static DEFINE_MUTEX(gr_dev_mutex);
57211+DEFINE_RWLOCK(gr_inode_lock);
57212+
57213+struct gr_arg *gr_usermode;
57214+
57215+static unsigned int gr_status __read_only = GR_STATUS_INIT;
57216+
57217+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
57218+extern void gr_clear_learn_entries(void);
57219+
57220+unsigned char *gr_system_salt;
57221+unsigned char *gr_system_sum;
57222+
57223+static struct sprole_pw **acl_special_roles = NULL;
57224+static __u16 num_sprole_pws = 0;
57225+
57226+static struct acl_role_label *kernel_role = NULL;
57227+
57228+static unsigned int gr_auth_attempts = 0;
57229+static unsigned long gr_auth_expires = 0UL;
57230+
57231+#ifdef CONFIG_NET
57232+extern struct vfsmount *sock_mnt;
57233+#endif
57234+
57235+extern struct vfsmount *pipe_mnt;
57236+extern struct vfsmount *shm_mnt;
57237+
57238+#ifdef CONFIG_HUGETLBFS
57239+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57240+#endif
57241+
57242+static struct acl_object_label *fakefs_obj_rw;
57243+static struct acl_object_label *fakefs_obj_rwx;
57244+
57245+extern int gr_init_uidset(void);
57246+extern void gr_free_uidset(void);
57247+extern void gr_remove_uid(uid_t uid);
57248+extern int gr_find_uid(uid_t uid);
57249+
57250+__inline__ int
57251+gr_acl_is_enabled(void)
57252+{
57253+ return (gr_status & GR_READY);
57254+}
57255+
57256+#ifdef CONFIG_BTRFS_FS
57257+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57258+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57259+#endif
57260+
57261+static inline dev_t __get_dev(const struct dentry *dentry)
57262+{
57263+#ifdef CONFIG_BTRFS_FS
57264+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57265+ return get_btrfs_dev_from_inode(dentry->d_inode);
57266+ else
57267+#endif
57268+ return dentry->d_inode->i_sb->s_dev;
57269+}
57270+
57271+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57272+{
57273+ return __get_dev(dentry);
57274+}
57275+
57276+static char gr_task_roletype_to_char(struct task_struct *task)
57277+{
57278+ switch (task->role->roletype &
57279+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
57280+ GR_ROLE_SPECIAL)) {
57281+ case GR_ROLE_DEFAULT:
57282+ return 'D';
57283+ case GR_ROLE_USER:
57284+ return 'U';
57285+ case GR_ROLE_GROUP:
57286+ return 'G';
57287+ case GR_ROLE_SPECIAL:
57288+ return 'S';
57289+ }
57290+
57291+ return 'X';
57292+}
57293+
57294+char gr_roletype_to_char(void)
57295+{
57296+ return gr_task_roletype_to_char(current);
57297+}
57298+
57299+__inline__ int
57300+gr_acl_tpe_check(void)
57301+{
57302+ if (unlikely(!(gr_status & GR_READY)))
57303+ return 0;
57304+ if (current->role->roletype & GR_ROLE_TPE)
57305+ return 1;
57306+ else
57307+ return 0;
57308+}
57309+
57310+int
57311+gr_handle_rawio(const struct inode *inode)
57312+{
57313+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57314+ if (inode && S_ISBLK(inode->i_mode) &&
57315+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57316+ !capable(CAP_SYS_RAWIO))
57317+ return 1;
57318+#endif
57319+ return 0;
57320+}
57321+
57322+static int
57323+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
57324+{
57325+ if (likely(lena != lenb))
57326+ return 0;
57327+
57328+ return !memcmp(a, b, lena);
57329+}
57330+
57331+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
57332+{
57333+ *buflen -= namelen;
57334+ if (*buflen < 0)
57335+ return -ENAMETOOLONG;
57336+ *buffer -= namelen;
57337+ memcpy(*buffer, str, namelen);
57338+ return 0;
57339+}
57340+
57341+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
57342+{
57343+ return prepend(buffer, buflen, name->name, name->len);
57344+}
57345+
57346+static int prepend_path(const struct path *path, struct path *root,
57347+ char **buffer, int *buflen)
57348+{
57349+ struct dentry *dentry = path->dentry;
57350+ struct vfsmount *vfsmnt = path->mnt;
57351+ struct mount *mnt = real_mount(vfsmnt);
57352+ bool slash = false;
57353+ int error = 0;
57354+
57355+ while (dentry != root->dentry || vfsmnt != root->mnt) {
57356+ struct dentry * parent;
57357+
57358+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
57359+ /* Global root? */
57360+ if (!mnt_has_parent(mnt)) {
57361+ goto out;
57362+ }
57363+ dentry = mnt->mnt_mountpoint;
57364+ mnt = mnt->mnt_parent;
57365+ vfsmnt = &mnt->mnt;
57366+ continue;
57367+ }
57368+ parent = dentry->d_parent;
57369+ prefetch(parent);
57370+ spin_lock(&dentry->d_lock);
57371+ error = prepend_name(buffer, buflen, &dentry->d_name);
57372+ spin_unlock(&dentry->d_lock);
57373+ if (!error)
57374+ error = prepend(buffer, buflen, "/", 1);
57375+ if (error)
57376+ break;
57377+
57378+ slash = true;
57379+ dentry = parent;
57380+ }
57381+
57382+out:
57383+ if (!error && !slash)
57384+ error = prepend(buffer, buflen, "/", 1);
57385+
57386+ return error;
57387+}
57388+
57389+/* this must be called with vfsmount_lock and rename_lock held */
57390+
57391+static char *__our_d_path(const struct path *path, struct path *root,
57392+ char *buf, int buflen)
57393+{
57394+ char *res = buf + buflen;
57395+ int error;
57396+
57397+ prepend(&res, &buflen, "\0", 1);
57398+ error = prepend_path(path, root, &res, &buflen);
57399+ if (error)
57400+ return ERR_PTR(error);
57401+
57402+ return res;
57403+}
57404+
57405+static char *
57406+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
57407+{
57408+ char *retval;
57409+
57410+ retval = __our_d_path(path, root, buf, buflen);
57411+ if (unlikely(IS_ERR(retval)))
57412+ retval = strcpy(buf, "<path too long>");
57413+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
57414+ retval[1] = '\0';
57415+
57416+ return retval;
57417+}
57418+
57419+static char *
57420+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57421+ char *buf, int buflen)
57422+{
57423+ struct path path;
57424+ char *res;
57425+
57426+ path.dentry = (struct dentry *)dentry;
57427+ path.mnt = (struct vfsmount *)vfsmnt;
57428+
57429+ /* we can use real_root.dentry, real_root.mnt, because this is only called
57430+ by the RBAC system */
57431+ res = gen_full_path(&path, &real_root, buf, buflen);
57432+
57433+ return res;
57434+}
57435+
57436+static char *
57437+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57438+ char *buf, int buflen)
57439+{
57440+ char *res;
57441+ struct path path;
57442+ struct path root;
57443+ struct task_struct *reaper = init_pid_ns.child_reaper;
57444+
57445+ path.dentry = (struct dentry *)dentry;
57446+ path.mnt = (struct vfsmount *)vfsmnt;
57447+
57448+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
57449+ get_fs_root(reaper->fs, &root);
57450+
57451+ write_seqlock(&rename_lock);
57452+ br_read_lock(&vfsmount_lock);
57453+ res = gen_full_path(&path, &root, buf, buflen);
57454+ br_read_unlock(&vfsmount_lock);
57455+ write_sequnlock(&rename_lock);
57456+
57457+ path_put(&root);
57458+ return res;
57459+}
57460+
57461+static char *
57462+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57463+{
57464+ char *ret;
57465+ write_seqlock(&rename_lock);
57466+ br_read_lock(&vfsmount_lock);
57467+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57468+ PAGE_SIZE);
57469+ br_read_unlock(&vfsmount_lock);
57470+ write_sequnlock(&rename_lock);
57471+ return ret;
57472+}
57473+
57474+static char *
57475+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57476+{
57477+ char *ret;
57478+ char *buf;
57479+ int buflen;
57480+
57481+ write_seqlock(&rename_lock);
57482+ br_read_lock(&vfsmount_lock);
57483+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
57484+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
57485+ buflen = (int)(ret - buf);
57486+ if (buflen >= 5)
57487+ prepend(&ret, &buflen, "/proc", 5);
57488+ else
57489+ ret = strcpy(buf, "<path too long>");
57490+ br_read_unlock(&vfsmount_lock);
57491+ write_sequnlock(&rename_lock);
57492+ return ret;
57493+}
57494+
57495+char *
57496+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
57497+{
57498+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57499+ PAGE_SIZE);
57500+}
57501+
57502+char *
57503+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
57504+{
57505+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57506+ PAGE_SIZE);
57507+}
57508+
57509+char *
57510+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
57511+{
57512+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
57513+ PAGE_SIZE);
57514+}
57515+
57516+char *
57517+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
57518+{
57519+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
57520+ PAGE_SIZE);
57521+}
57522+
57523+char *
57524+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
57525+{
57526+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
57527+ PAGE_SIZE);
57528+}
57529+
57530+__inline__ __u32
57531+to_gr_audit(const __u32 reqmode)
57532+{
57533+ /* masks off auditable permission flags, then shifts them to create
57534+ auditing flags, and adds the special case of append auditing if
57535+ we're requesting write */
57536+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
57537+}
57538+
57539+struct acl_subject_label *
57540+lookup_subject_map(const struct acl_subject_label *userp)
57541+{
57542+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
57543+ struct subject_map *match;
57544+
57545+ match = subj_map_set.s_hash[index];
57546+
57547+ while (match && match->user != userp)
57548+ match = match->next;
57549+
57550+ if (match != NULL)
57551+ return match->kernel;
57552+ else
57553+ return NULL;
57554+}
57555+
57556+static void
57557+insert_subj_map_entry(struct subject_map *subjmap)
57558+{
57559+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
57560+ struct subject_map **curr;
57561+
57562+ subjmap->prev = NULL;
57563+
57564+ curr = &subj_map_set.s_hash[index];
57565+ if (*curr != NULL)
57566+ (*curr)->prev = subjmap;
57567+
57568+ subjmap->next = *curr;
57569+ *curr = subjmap;
57570+
57571+ return;
57572+}
57573+
57574+static struct acl_role_label *
57575+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
57576+ const gid_t gid)
57577+{
57578+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
57579+ struct acl_role_label *match;
57580+ struct role_allowed_ip *ipp;
57581+ unsigned int x;
57582+ u32 curr_ip = task->signal->curr_ip;
57583+
57584+ task->signal->saved_ip = curr_ip;
57585+
57586+ match = acl_role_set.r_hash[index];
57587+
57588+ while (match) {
57589+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
57590+ for (x = 0; x < match->domain_child_num; x++) {
57591+ if (match->domain_children[x] == uid)
57592+ goto found;
57593+ }
57594+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
57595+ break;
57596+ match = match->next;
57597+ }
57598+found:
57599+ if (match == NULL) {
57600+ try_group:
57601+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
57602+ match = acl_role_set.r_hash[index];
57603+
57604+ while (match) {
57605+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
57606+ for (x = 0; x < match->domain_child_num; x++) {
57607+ if (match->domain_children[x] == gid)
57608+ goto found2;
57609+ }
57610+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
57611+ break;
57612+ match = match->next;
57613+ }
57614+found2:
57615+ if (match == NULL)
57616+ match = default_role;
57617+ if (match->allowed_ips == NULL)
57618+ return match;
57619+ else {
57620+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57621+ if (likely
57622+ ((ntohl(curr_ip) & ipp->netmask) ==
57623+ (ntohl(ipp->addr) & ipp->netmask)))
57624+ return match;
57625+ }
57626+ match = default_role;
57627+ }
57628+ } else if (match->allowed_ips == NULL) {
57629+ return match;
57630+ } else {
57631+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57632+ if (likely
57633+ ((ntohl(curr_ip) & ipp->netmask) ==
57634+ (ntohl(ipp->addr) & ipp->netmask)))
57635+ return match;
57636+ }
57637+ goto try_group;
57638+ }
57639+
57640+ return match;
57641+}
57642+
57643+struct acl_subject_label *
57644+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
57645+ const struct acl_role_label *role)
57646+{
57647+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57648+ struct acl_subject_label *match;
57649+
57650+ match = role->subj_hash[index];
57651+
57652+ while (match && (match->inode != ino || match->device != dev ||
57653+ (match->mode & GR_DELETED))) {
57654+ match = match->next;
57655+ }
57656+
57657+ if (match && !(match->mode & GR_DELETED))
57658+ return match;
57659+ else
57660+ return NULL;
57661+}
57662+
57663+struct acl_subject_label *
57664+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
57665+ const struct acl_role_label *role)
57666+{
57667+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57668+ struct acl_subject_label *match;
57669+
57670+ match = role->subj_hash[index];
57671+
57672+ while (match && (match->inode != ino || match->device != dev ||
57673+ !(match->mode & GR_DELETED))) {
57674+ match = match->next;
57675+ }
57676+
57677+ if (match && (match->mode & GR_DELETED))
57678+ return match;
57679+ else
57680+ return NULL;
57681+}
57682+
57683+static struct acl_object_label *
57684+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
57685+ const struct acl_subject_label *subj)
57686+{
57687+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57688+ struct acl_object_label *match;
57689+
57690+ match = subj->obj_hash[index];
57691+
57692+ while (match && (match->inode != ino || match->device != dev ||
57693+ (match->mode & GR_DELETED))) {
57694+ match = match->next;
57695+ }
57696+
57697+ if (match && !(match->mode & GR_DELETED))
57698+ return match;
57699+ else
57700+ return NULL;
57701+}
57702+
57703+static struct acl_object_label *
57704+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
57705+ const struct acl_subject_label *subj)
57706+{
57707+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57708+ struct acl_object_label *match;
57709+
57710+ match = subj->obj_hash[index];
57711+
57712+ while (match && (match->inode != ino || match->device != dev ||
57713+ !(match->mode & GR_DELETED))) {
57714+ match = match->next;
57715+ }
57716+
57717+ if (match && (match->mode & GR_DELETED))
57718+ return match;
57719+
57720+ match = subj->obj_hash[index];
57721+
57722+ while (match && (match->inode != ino || match->device != dev ||
57723+ (match->mode & GR_DELETED))) {
57724+ match = match->next;
57725+ }
57726+
57727+ if (match && !(match->mode & GR_DELETED))
57728+ return match;
57729+ else
57730+ return NULL;
57731+}
57732+
57733+static struct name_entry *
57734+lookup_name_entry(const char *name)
57735+{
57736+ unsigned int len = strlen(name);
57737+ unsigned int key = full_name_hash(name, len);
57738+ unsigned int index = key % name_set.n_size;
57739+ struct name_entry *match;
57740+
57741+ match = name_set.n_hash[index];
57742+
57743+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
57744+ match = match->next;
57745+
57746+ return match;
57747+}
57748+
57749+static struct name_entry *
57750+lookup_name_entry_create(const char *name)
57751+{
57752+ unsigned int len = strlen(name);
57753+ unsigned int key = full_name_hash(name, len);
57754+ unsigned int index = key % name_set.n_size;
57755+ struct name_entry *match;
57756+
57757+ match = name_set.n_hash[index];
57758+
57759+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57760+ !match->deleted))
57761+ match = match->next;
57762+
57763+ if (match && match->deleted)
57764+ return match;
57765+
57766+ match = name_set.n_hash[index];
57767+
57768+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57769+ match->deleted))
57770+ match = match->next;
57771+
57772+ if (match && !match->deleted)
57773+ return match;
57774+ else
57775+ return NULL;
57776+}
57777+
57778+static struct inodev_entry *
57779+lookup_inodev_entry(const ino_t ino, const dev_t dev)
57780+{
57781+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
57782+ struct inodev_entry *match;
57783+
57784+ match = inodev_set.i_hash[index];
57785+
57786+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
57787+ match = match->next;
57788+
57789+ return match;
57790+}
57791+
57792+static void
57793+insert_inodev_entry(struct inodev_entry *entry)
57794+{
57795+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
57796+ inodev_set.i_size);
57797+ struct inodev_entry **curr;
57798+
57799+ entry->prev = NULL;
57800+
57801+ curr = &inodev_set.i_hash[index];
57802+ if (*curr != NULL)
57803+ (*curr)->prev = entry;
57804+
57805+ entry->next = *curr;
57806+ *curr = entry;
57807+
57808+ return;
57809+}
57810+
57811+static void
57812+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
57813+{
57814+ unsigned int index =
57815+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
57816+ struct acl_role_label **curr;
57817+ struct acl_role_label *tmp, *tmp2;
57818+
57819+ curr = &acl_role_set.r_hash[index];
57820+
57821+ /* simple case, slot is empty, just set it to our role */
57822+ if (*curr == NULL) {
57823+ *curr = role;
57824+ } else {
57825+ /* example:
57826+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
57827+ 2 -> 3
57828+ */
57829+ /* first check to see if we can already be reached via this slot */
57830+ tmp = *curr;
57831+ while (tmp && tmp != role)
57832+ tmp = tmp->next;
57833+ if (tmp == role) {
57834+ /* we don't need to add ourselves to this slot's chain */
57835+ return;
57836+ }
57837+ /* we need to add ourselves to this chain, two cases */
57838+ if (role->next == NULL) {
57839+ /* simple case, append the current chain to our role */
57840+ role->next = *curr;
57841+ *curr = role;
57842+ } else {
57843+ /* 1 -> 2 -> 3 -> 4
57844+ 2 -> 3 -> 4
57845+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
57846+ */
57847+ /* trickier case: walk our role's chain until we find
57848+ the role for the start of the current slot's chain */
57849+ tmp = role;
57850+ tmp2 = *curr;
57851+ while (tmp->next && tmp->next != tmp2)
57852+ tmp = tmp->next;
57853+ if (tmp->next == tmp2) {
57854+ /* from example above, we found 3, so just
57855+ replace this slot's chain with ours */
57856+ *curr = role;
57857+ } else {
57858+ /* we didn't find a subset of our role's chain
57859+ in the current slot's chain, so append their
57860+ chain to ours, and set us as the first role in
57861+ the slot's chain
57862+
57863+ we could fold this case with the case above,
57864+ but making it explicit for clarity
57865+ */
57866+ tmp->next = tmp2;
57867+ *curr = role;
57868+ }
57869+ }
57870+ }
57871+
57872+ return;
57873+}
57874+
57875+static void
57876+insert_acl_role_label(struct acl_role_label *role)
57877+{
57878+ int i;
57879+
57880+ if (role_list == NULL) {
57881+ role_list = role;
57882+ role->prev = NULL;
57883+ } else {
57884+ role->prev = role_list;
57885+ role_list = role;
57886+ }
57887+
57888+ /* used for hash chains */
57889+ role->next = NULL;
57890+
57891+ if (role->roletype & GR_ROLE_DOMAIN) {
57892+ for (i = 0; i < role->domain_child_num; i++)
57893+ __insert_acl_role_label(role, role->domain_children[i]);
57894+ } else
57895+ __insert_acl_role_label(role, role->uidgid);
57896+}
57897+
57898+static int
57899+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
57900+{
57901+ struct name_entry **curr, *nentry;
57902+ struct inodev_entry *ientry;
57903+ unsigned int len = strlen(name);
57904+ unsigned int key = full_name_hash(name, len);
57905+ unsigned int index = key % name_set.n_size;
57906+
57907+ curr = &name_set.n_hash[index];
57908+
57909+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
57910+ curr = &((*curr)->next);
57911+
57912+ if (*curr != NULL)
57913+ return 1;
57914+
57915+ nentry = acl_alloc(sizeof (struct name_entry));
57916+ if (nentry == NULL)
57917+ return 0;
57918+ ientry = acl_alloc(sizeof (struct inodev_entry));
57919+ if (ientry == NULL)
57920+ return 0;
57921+ ientry->nentry = nentry;
57922+
57923+ nentry->key = key;
57924+ nentry->name = name;
57925+ nentry->inode = inode;
57926+ nentry->device = device;
57927+ nentry->len = len;
57928+ nentry->deleted = deleted;
57929+
57930+ nentry->prev = NULL;
57931+ curr = &name_set.n_hash[index];
57932+ if (*curr != NULL)
57933+ (*curr)->prev = nentry;
57934+ nentry->next = *curr;
57935+ *curr = nentry;
57936+
57937+ /* insert us into the table searchable by inode/dev */
57938+ insert_inodev_entry(ientry);
57939+
57940+ return 1;
57941+}
57942+
57943+static void
57944+insert_acl_obj_label(struct acl_object_label *obj,
57945+ struct acl_subject_label *subj)
57946+{
57947+ unsigned int index =
57948+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
57949+ struct acl_object_label **curr;
57950+
57951+
57952+ obj->prev = NULL;
57953+
57954+ curr = &subj->obj_hash[index];
57955+ if (*curr != NULL)
57956+ (*curr)->prev = obj;
57957+
57958+ obj->next = *curr;
57959+ *curr = obj;
57960+
57961+ return;
57962+}
57963+
57964+static void
57965+insert_acl_subj_label(struct acl_subject_label *obj,
57966+ struct acl_role_label *role)
57967+{
57968+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
57969+ struct acl_subject_label **curr;
57970+
57971+ obj->prev = NULL;
57972+
57973+ curr = &role->subj_hash[index];
57974+ if (*curr != NULL)
57975+ (*curr)->prev = obj;
57976+
57977+ obj->next = *curr;
57978+ *curr = obj;
57979+
57980+ return;
57981+}
57982+
57983+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
57984+
57985+static void *
57986+create_table(__u32 * len, int elementsize)
57987+{
57988+ unsigned int table_sizes[] = {
57989+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
57990+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
57991+ 4194301, 8388593, 16777213, 33554393, 67108859
57992+ };
57993+ void *newtable = NULL;
57994+ unsigned int pwr = 0;
57995+
57996+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
57997+ table_sizes[pwr] <= *len)
57998+ pwr++;
57999+
58000+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
58001+ return newtable;
58002+
58003+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
58004+ newtable =
58005+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
58006+ else
58007+ newtable = vmalloc(table_sizes[pwr] * elementsize);
58008+
58009+ *len = table_sizes[pwr];
58010+
58011+ return newtable;
58012+}
58013+
58014+static int
58015+init_variables(const struct gr_arg *arg)
58016+{
58017+ struct task_struct *reaper = init_pid_ns.child_reaper;
58018+ unsigned int stacksize;
58019+
58020+ subj_map_set.s_size = arg->role_db.num_subjects;
58021+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
58022+ name_set.n_size = arg->role_db.num_objects;
58023+ inodev_set.i_size = arg->role_db.num_objects;
58024+
58025+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
58026+ !name_set.n_size || !inodev_set.i_size)
58027+ return 1;
58028+
58029+ if (!gr_init_uidset())
58030+ return 1;
58031+
58032+ /* set up the stack that holds allocation info */
58033+
58034+ stacksize = arg->role_db.num_pointers + 5;
58035+
58036+ if (!acl_alloc_stack_init(stacksize))
58037+ return 1;
58038+
58039+ /* grab reference for the real root dentry and vfsmount */
58040+ get_fs_root(reaper->fs, &real_root);
58041+
58042+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58043+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
58044+#endif
58045+
58046+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
58047+ if (fakefs_obj_rw == NULL)
58048+ return 1;
58049+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
58050+
58051+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
58052+ if (fakefs_obj_rwx == NULL)
58053+ return 1;
58054+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
58055+
58056+ subj_map_set.s_hash =
58057+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
58058+ acl_role_set.r_hash =
58059+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
58060+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
58061+ inodev_set.i_hash =
58062+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
58063+
58064+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
58065+ !name_set.n_hash || !inodev_set.i_hash)
58066+ return 1;
58067+
58068+ memset(subj_map_set.s_hash, 0,
58069+ sizeof(struct subject_map *) * subj_map_set.s_size);
58070+ memset(acl_role_set.r_hash, 0,
58071+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
58072+ memset(name_set.n_hash, 0,
58073+ sizeof (struct name_entry *) * name_set.n_size);
58074+ memset(inodev_set.i_hash, 0,
58075+ sizeof (struct inodev_entry *) * inodev_set.i_size);
58076+
58077+ return 0;
58078+}
58079+
58080+/* free information not needed after startup
58081+ currently contains user->kernel pointer mappings for subjects
58082+*/
58083+
58084+static void
58085+free_init_variables(void)
58086+{
58087+ __u32 i;
58088+
58089+ if (subj_map_set.s_hash) {
58090+ for (i = 0; i < subj_map_set.s_size; i++) {
58091+ if (subj_map_set.s_hash[i]) {
58092+ kfree(subj_map_set.s_hash[i]);
58093+ subj_map_set.s_hash[i] = NULL;
58094+ }
58095+ }
58096+
58097+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
58098+ PAGE_SIZE)
58099+ kfree(subj_map_set.s_hash);
58100+ else
58101+ vfree(subj_map_set.s_hash);
58102+ }
58103+
58104+ return;
58105+}
58106+
58107+static void
58108+free_variables(void)
58109+{
58110+ struct acl_subject_label *s;
58111+ struct acl_role_label *r;
58112+ struct task_struct *task, *task2;
58113+ unsigned int x;
58114+
58115+ gr_clear_learn_entries();
58116+
58117+ read_lock(&tasklist_lock);
58118+ do_each_thread(task2, task) {
58119+ task->acl_sp_role = 0;
58120+ task->acl_role_id = 0;
58121+ task->acl = NULL;
58122+ task->role = NULL;
58123+ } while_each_thread(task2, task);
58124+ read_unlock(&tasklist_lock);
58125+
58126+ /* release the reference to the real root dentry and vfsmount */
58127+ path_put(&real_root);
58128+ memset(&real_root, 0, sizeof(real_root));
58129+
58130+ /* free all object hash tables */
58131+
58132+ FOR_EACH_ROLE_START(r)
58133+ if (r->subj_hash == NULL)
58134+ goto next_role;
58135+ FOR_EACH_SUBJECT_START(r, s, x)
58136+ if (s->obj_hash == NULL)
58137+ break;
58138+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58139+ kfree(s->obj_hash);
58140+ else
58141+ vfree(s->obj_hash);
58142+ FOR_EACH_SUBJECT_END(s, x)
58143+ FOR_EACH_NESTED_SUBJECT_START(r, s)
58144+ if (s->obj_hash == NULL)
58145+ break;
58146+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58147+ kfree(s->obj_hash);
58148+ else
58149+ vfree(s->obj_hash);
58150+ FOR_EACH_NESTED_SUBJECT_END(s)
58151+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
58152+ kfree(r->subj_hash);
58153+ else
58154+ vfree(r->subj_hash);
58155+ r->subj_hash = NULL;
58156+next_role:
58157+ FOR_EACH_ROLE_END(r)
58158+
58159+ acl_free_all();
58160+
58161+ if (acl_role_set.r_hash) {
58162+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
58163+ PAGE_SIZE)
58164+ kfree(acl_role_set.r_hash);
58165+ else
58166+ vfree(acl_role_set.r_hash);
58167+ }
58168+ if (name_set.n_hash) {
58169+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
58170+ PAGE_SIZE)
58171+ kfree(name_set.n_hash);
58172+ else
58173+ vfree(name_set.n_hash);
58174+ }
58175+
58176+ if (inodev_set.i_hash) {
58177+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
58178+ PAGE_SIZE)
58179+ kfree(inodev_set.i_hash);
58180+ else
58181+ vfree(inodev_set.i_hash);
58182+ }
58183+
58184+ gr_free_uidset();
58185+
58186+ memset(&name_set, 0, sizeof (struct name_db));
58187+ memset(&inodev_set, 0, sizeof (struct inodev_db));
58188+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
58189+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
58190+
58191+ default_role = NULL;
58192+ kernel_role = NULL;
58193+ role_list = NULL;
58194+
58195+ return;
58196+}
58197+
58198+static __u32
58199+count_user_objs(struct acl_object_label *userp)
58200+{
58201+ struct acl_object_label o_tmp;
58202+ __u32 num = 0;
58203+
58204+ while (userp) {
58205+ if (copy_from_user(&o_tmp, userp,
58206+ sizeof (struct acl_object_label)))
58207+ break;
58208+
58209+ userp = o_tmp.prev;
58210+ num++;
58211+ }
58212+
58213+ return num;
58214+}
58215+
58216+static struct acl_subject_label *
58217+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
58218+
58219+static int
58220+copy_user_glob(struct acl_object_label *obj)
58221+{
58222+ struct acl_object_label *g_tmp, **guser;
58223+ unsigned int len;
58224+ char *tmp;
58225+
58226+ if (obj->globbed == NULL)
58227+ return 0;
58228+
58229+ guser = &obj->globbed;
58230+ while (*guser) {
58231+ g_tmp = (struct acl_object_label *)
58232+ acl_alloc(sizeof (struct acl_object_label));
58233+ if (g_tmp == NULL)
58234+ return -ENOMEM;
58235+
58236+ if (copy_from_user(g_tmp, *guser,
58237+ sizeof (struct acl_object_label)))
58238+ return -EFAULT;
58239+
58240+ len = strnlen_user(g_tmp->filename, PATH_MAX);
58241+
58242+ if (!len || len >= PATH_MAX)
58243+ return -EINVAL;
58244+
58245+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58246+ return -ENOMEM;
58247+
58248+ if (copy_from_user(tmp, g_tmp->filename, len))
58249+ return -EFAULT;
58250+ tmp[len-1] = '\0';
58251+ g_tmp->filename = tmp;
58252+
58253+ *guser = g_tmp;
58254+ guser = &(g_tmp->next);
58255+ }
58256+
58257+ return 0;
58258+}
58259+
58260+static int
58261+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
58262+ struct acl_role_label *role)
58263+{
58264+ struct acl_object_label *o_tmp;
58265+ unsigned int len;
58266+ int ret;
58267+ char *tmp;
58268+
58269+ while (userp) {
58270+ if ((o_tmp = (struct acl_object_label *)
58271+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
58272+ return -ENOMEM;
58273+
58274+ if (copy_from_user(o_tmp, userp,
58275+ sizeof (struct acl_object_label)))
58276+ return -EFAULT;
58277+
58278+ userp = o_tmp->prev;
58279+
58280+ len = strnlen_user(o_tmp->filename, PATH_MAX);
58281+
58282+ if (!len || len >= PATH_MAX)
58283+ return -EINVAL;
58284+
58285+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58286+ return -ENOMEM;
58287+
58288+ if (copy_from_user(tmp, o_tmp->filename, len))
58289+ return -EFAULT;
58290+ tmp[len-1] = '\0';
58291+ o_tmp->filename = tmp;
58292+
58293+ insert_acl_obj_label(o_tmp, subj);
58294+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
58295+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
58296+ return -ENOMEM;
58297+
58298+ ret = copy_user_glob(o_tmp);
58299+ if (ret)
58300+ return ret;
58301+
58302+ if (o_tmp->nested) {
58303+ int already_copied;
58304+
58305+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
58306+ if (IS_ERR(o_tmp->nested))
58307+ return PTR_ERR(o_tmp->nested);
58308+
58309+ /* insert into nested subject list if we haven't copied this one yet
58310+ to prevent duplicate entries */
58311+ if (!already_copied) {
58312+ o_tmp->nested->next = role->hash->first;
58313+ role->hash->first = o_tmp->nested;
58314+ }
58315+ }
58316+ }
58317+
58318+ return 0;
58319+}
58320+
58321+static __u32
58322+count_user_subjs(struct acl_subject_label *userp)
58323+{
58324+ struct acl_subject_label s_tmp;
58325+ __u32 num = 0;
58326+
58327+ while (userp) {
58328+ if (copy_from_user(&s_tmp, userp,
58329+ sizeof (struct acl_subject_label)))
58330+ break;
58331+
58332+ userp = s_tmp.prev;
58333+ }
58334+
58335+ return num;
58336+}
58337+
58338+static int
58339+copy_user_allowedips(struct acl_role_label *rolep)
58340+{
58341+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
58342+
58343+ ruserip = rolep->allowed_ips;
58344+
58345+ while (ruserip) {
58346+ rlast = rtmp;
58347+
58348+ if ((rtmp = (struct role_allowed_ip *)
58349+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
58350+ return -ENOMEM;
58351+
58352+ if (copy_from_user(rtmp, ruserip,
58353+ sizeof (struct role_allowed_ip)))
58354+ return -EFAULT;
58355+
58356+ ruserip = rtmp->prev;
58357+
58358+ if (!rlast) {
58359+ rtmp->prev = NULL;
58360+ rolep->allowed_ips = rtmp;
58361+ } else {
58362+ rlast->next = rtmp;
58363+ rtmp->prev = rlast;
58364+ }
58365+
58366+ if (!ruserip)
58367+ rtmp->next = NULL;
58368+ }
58369+
58370+ return 0;
58371+}
58372+
58373+static int
58374+copy_user_transitions(struct acl_role_label *rolep)
58375+{
58376+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
58377+
58378+ unsigned int len;
58379+ char *tmp;
58380+
58381+ rusertp = rolep->transitions;
58382+
58383+ while (rusertp) {
58384+ rlast = rtmp;
58385+
58386+ if ((rtmp = (struct role_transition *)
58387+ acl_alloc(sizeof (struct role_transition))) == NULL)
58388+ return -ENOMEM;
58389+
58390+ if (copy_from_user(rtmp, rusertp,
58391+ sizeof (struct role_transition)))
58392+ return -EFAULT;
58393+
58394+ rusertp = rtmp->prev;
58395+
58396+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
58397+
58398+ if (!len || len >= GR_SPROLE_LEN)
58399+ return -EINVAL;
58400+
58401+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58402+ return -ENOMEM;
58403+
58404+ if (copy_from_user(tmp, rtmp->rolename, len))
58405+ return -EFAULT;
58406+ tmp[len-1] = '\0';
58407+ rtmp->rolename = tmp;
58408+
58409+ if (!rlast) {
58410+ rtmp->prev = NULL;
58411+ rolep->transitions = rtmp;
58412+ } else {
58413+ rlast->next = rtmp;
58414+ rtmp->prev = rlast;
58415+ }
58416+
58417+ if (!rusertp)
58418+ rtmp->next = NULL;
58419+ }
58420+
58421+ return 0;
58422+}
58423+
58424+static struct acl_subject_label *
58425+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
58426+{
58427+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
58428+ unsigned int len;
58429+ char *tmp;
58430+ __u32 num_objs;
58431+ struct acl_ip_label **i_tmp, *i_utmp2;
58432+ struct gr_hash_struct ghash;
58433+ struct subject_map *subjmap;
58434+ unsigned int i_num;
58435+ int err;
58436+
58437+ if (already_copied != NULL)
58438+ *already_copied = 0;
58439+
58440+ s_tmp = lookup_subject_map(userp);
58441+
58442+ /* we've already copied this subject into the kernel, just return
58443+ the reference to it, and don't copy it over again
58444+ */
58445+ if (s_tmp) {
58446+ if (already_copied != NULL)
58447+ *already_copied = 1;
58448+ return(s_tmp);
58449+ }
58450+
58451+ if ((s_tmp = (struct acl_subject_label *)
58452+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
58453+ return ERR_PTR(-ENOMEM);
58454+
58455+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
58456+ if (subjmap == NULL)
58457+ return ERR_PTR(-ENOMEM);
58458+
58459+ subjmap->user = userp;
58460+ subjmap->kernel = s_tmp;
58461+ insert_subj_map_entry(subjmap);
58462+
58463+ if (copy_from_user(s_tmp, userp,
58464+ sizeof (struct acl_subject_label)))
58465+ return ERR_PTR(-EFAULT);
58466+
58467+ len = strnlen_user(s_tmp->filename, PATH_MAX);
58468+
58469+ if (!len || len >= PATH_MAX)
58470+ return ERR_PTR(-EINVAL);
58471+
58472+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58473+ return ERR_PTR(-ENOMEM);
58474+
58475+ if (copy_from_user(tmp, s_tmp->filename, len))
58476+ return ERR_PTR(-EFAULT);
58477+ tmp[len-1] = '\0';
58478+ s_tmp->filename = tmp;
58479+
58480+ if (!strcmp(s_tmp->filename, "/"))
58481+ role->root_label = s_tmp;
58482+
58483+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
58484+ return ERR_PTR(-EFAULT);
58485+
58486+ /* copy user and group transition tables */
58487+
58488+ if (s_tmp->user_trans_num) {
58489+ uid_t *uidlist;
58490+
58491+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
58492+ if (uidlist == NULL)
58493+ return ERR_PTR(-ENOMEM);
58494+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
58495+ return ERR_PTR(-EFAULT);
58496+
58497+ s_tmp->user_transitions = uidlist;
58498+ }
58499+
58500+ if (s_tmp->group_trans_num) {
58501+ gid_t *gidlist;
58502+
58503+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
58504+ if (gidlist == NULL)
58505+ return ERR_PTR(-ENOMEM);
58506+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
58507+ return ERR_PTR(-EFAULT);
58508+
58509+ s_tmp->group_transitions = gidlist;
58510+ }
58511+
58512+ /* set up object hash table */
58513+ num_objs = count_user_objs(ghash.first);
58514+
58515+ s_tmp->obj_hash_size = num_objs;
58516+ s_tmp->obj_hash =
58517+ (struct acl_object_label **)
58518+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
58519+
58520+ if (!s_tmp->obj_hash)
58521+ return ERR_PTR(-ENOMEM);
58522+
58523+ memset(s_tmp->obj_hash, 0,
58524+ s_tmp->obj_hash_size *
58525+ sizeof (struct acl_object_label *));
58526+
58527+ /* add in objects */
58528+ err = copy_user_objs(ghash.first, s_tmp, role);
58529+
58530+ if (err)
58531+ return ERR_PTR(err);
58532+
58533+ /* set pointer for parent subject */
58534+ if (s_tmp->parent_subject) {
58535+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
58536+
58537+ if (IS_ERR(s_tmp2))
58538+ return s_tmp2;
58539+
58540+ s_tmp->parent_subject = s_tmp2;
58541+ }
58542+
58543+ /* add in ip acls */
58544+
58545+ if (!s_tmp->ip_num) {
58546+ s_tmp->ips = NULL;
58547+ goto insert;
58548+ }
58549+
58550+ i_tmp =
58551+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
58552+ sizeof (struct acl_ip_label *));
58553+
58554+ if (!i_tmp)
58555+ return ERR_PTR(-ENOMEM);
58556+
58557+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
58558+ *(i_tmp + i_num) =
58559+ (struct acl_ip_label *)
58560+ acl_alloc(sizeof (struct acl_ip_label));
58561+ if (!*(i_tmp + i_num))
58562+ return ERR_PTR(-ENOMEM);
58563+
58564+ if (copy_from_user
58565+ (&i_utmp2, s_tmp->ips + i_num,
58566+ sizeof (struct acl_ip_label *)))
58567+ return ERR_PTR(-EFAULT);
58568+
58569+ if (copy_from_user
58570+ (*(i_tmp + i_num), i_utmp2,
58571+ sizeof (struct acl_ip_label)))
58572+ return ERR_PTR(-EFAULT);
58573+
58574+ if ((*(i_tmp + i_num))->iface == NULL)
58575+ continue;
58576+
58577+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
58578+ if (!len || len >= IFNAMSIZ)
58579+ return ERR_PTR(-EINVAL);
58580+ tmp = acl_alloc(len);
58581+ if (tmp == NULL)
58582+ return ERR_PTR(-ENOMEM);
58583+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
58584+ return ERR_PTR(-EFAULT);
58585+ (*(i_tmp + i_num))->iface = tmp;
58586+ }
58587+
58588+ s_tmp->ips = i_tmp;
58589+
58590+insert:
58591+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
58592+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
58593+ return ERR_PTR(-ENOMEM);
58594+
58595+ return s_tmp;
58596+}
58597+
58598+static int
58599+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
58600+{
58601+ struct acl_subject_label s_pre;
58602+ struct acl_subject_label * ret;
58603+ int err;
58604+
58605+ while (userp) {
58606+ if (copy_from_user(&s_pre, userp,
58607+ sizeof (struct acl_subject_label)))
58608+ return -EFAULT;
58609+
58610+ ret = do_copy_user_subj(userp, role, NULL);
58611+
58612+ err = PTR_ERR(ret);
58613+ if (IS_ERR(ret))
58614+ return err;
58615+
58616+ insert_acl_subj_label(ret, role);
58617+
58618+ userp = s_pre.prev;
58619+ }
58620+
58621+ return 0;
58622+}
58623+
58624+static int
58625+copy_user_acl(struct gr_arg *arg)
58626+{
58627+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
58628+ struct acl_subject_label *subj_list;
58629+ struct sprole_pw *sptmp;
58630+ struct gr_hash_struct *ghash;
58631+ uid_t *domainlist;
58632+ unsigned int r_num;
58633+ unsigned int len;
58634+ char *tmp;
58635+ int err = 0;
58636+ __u16 i;
58637+ __u32 num_subjs;
58638+
58639+ /* we need a default and kernel role */
58640+ if (arg->role_db.num_roles < 2)
58641+ return -EINVAL;
58642+
58643+ /* copy special role authentication info from userspace */
58644+
58645+ num_sprole_pws = arg->num_sprole_pws;
58646+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
58647+
58648+ if (!acl_special_roles && num_sprole_pws)
58649+ return -ENOMEM;
58650+
58651+ for (i = 0; i < num_sprole_pws; i++) {
58652+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
58653+ if (!sptmp)
58654+ return -ENOMEM;
58655+ if (copy_from_user(sptmp, arg->sprole_pws + i,
58656+ sizeof (struct sprole_pw)))
58657+ return -EFAULT;
58658+
58659+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
58660+
58661+ if (!len || len >= GR_SPROLE_LEN)
58662+ return -EINVAL;
58663+
58664+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58665+ return -ENOMEM;
58666+
58667+ if (copy_from_user(tmp, sptmp->rolename, len))
58668+ return -EFAULT;
58669+
58670+ tmp[len-1] = '\0';
58671+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58672+ printk(KERN_ALERT "Copying special role %s\n", tmp);
58673+#endif
58674+ sptmp->rolename = tmp;
58675+ acl_special_roles[i] = sptmp;
58676+ }
58677+
58678+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
58679+
58680+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
58681+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
58682+
58683+ if (!r_tmp)
58684+ return -ENOMEM;
58685+
58686+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
58687+ sizeof (struct acl_role_label *)))
58688+ return -EFAULT;
58689+
58690+ if (copy_from_user(r_tmp, r_utmp2,
58691+ sizeof (struct acl_role_label)))
58692+ return -EFAULT;
58693+
58694+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
58695+
58696+ if (!len || len >= PATH_MAX)
58697+ return -EINVAL;
58698+
58699+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58700+ return -ENOMEM;
58701+
58702+ if (copy_from_user(tmp, r_tmp->rolename, len))
58703+ return -EFAULT;
58704+
58705+ tmp[len-1] = '\0';
58706+ r_tmp->rolename = tmp;
58707+
58708+ if (!strcmp(r_tmp->rolename, "default")
58709+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
58710+ default_role = r_tmp;
58711+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
58712+ kernel_role = r_tmp;
58713+ }
58714+
58715+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
58716+ return -ENOMEM;
58717+
58718+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
58719+ return -EFAULT;
58720+
58721+ r_tmp->hash = ghash;
58722+
58723+ num_subjs = count_user_subjs(r_tmp->hash->first);
58724+
58725+ r_tmp->subj_hash_size = num_subjs;
58726+ r_tmp->subj_hash =
58727+ (struct acl_subject_label **)
58728+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
58729+
58730+ if (!r_tmp->subj_hash)
58731+ return -ENOMEM;
58732+
58733+ err = copy_user_allowedips(r_tmp);
58734+ if (err)
58735+ return err;
58736+
58737+ /* copy domain info */
58738+ if (r_tmp->domain_children != NULL) {
58739+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
58740+ if (domainlist == NULL)
58741+ return -ENOMEM;
58742+
58743+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
58744+ return -EFAULT;
58745+
58746+ r_tmp->domain_children = domainlist;
58747+ }
58748+
58749+ err = copy_user_transitions(r_tmp);
58750+ if (err)
58751+ return err;
58752+
58753+ memset(r_tmp->subj_hash, 0,
58754+ r_tmp->subj_hash_size *
58755+ sizeof (struct acl_subject_label *));
58756+
58757+ /* acquire the list of subjects, then NULL out
58758+ the list prior to parsing the subjects for this role,
58759+ as during this parsing the list is replaced with a list
58760+ of *nested* subjects for the role
58761+ */
58762+ subj_list = r_tmp->hash->first;
58763+
58764+ /* set nested subject list to null */
58765+ r_tmp->hash->first = NULL;
58766+
58767+ err = copy_user_subjs(subj_list, r_tmp);
58768+
58769+ if (err)
58770+ return err;
58771+
58772+ insert_acl_role_label(r_tmp);
58773+ }
58774+
58775+ if (default_role == NULL || kernel_role == NULL)
58776+ return -EINVAL;
58777+
58778+ return err;
58779+}
58780+
58781+static int
58782+gracl_init(struct gr_arg *args)
58783+{
58784+ int error = 0;
58785+
58786+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
58787+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
58788+
58789+ if (init_variables(args)) {
58790+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
58791+ error = -ENOMEM;
58792+ free_variables();
58793+ goto out;
58794+ }
58795+
58796+ error = copy_user_acl(args);
58797+ free_init_variables();
58798+ if (error) {
58799+ free_variables();
58800+ goto out;
58801+ }
58802+
58803+ if ((error = gr_set_acls(0))) {
58804+ free_variables();
58805+ goto out;
58806+ }
58807+
58808+ pax_open_kernel();
58809+ gr_status |= GR_READY;
58810+ pax_close_kernel();
58811+
58812+ out:
58813+ return error;
58814+}
58815+
58816+/* derived from glibc fnmatch() 0: match, 1: no match*/
58817+
58818+static int
58819+glob_match(const char *p, const char *n)
58820+{
58821+ char c;
58822+
58823+ while ((c = *p++) != '\0') {
58824+ switch (c) {
58825+ case '?':
58826+ if (*n == '\0')
58827+ return 1;
58828+ else if (*n == '/')
58829+ return 1;
58830+ break;
58831+ case '\\':
58832+ if (*n != c)
58833+ return 1;
58834+ break;
58835+ case '*':
58836+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
58837+ if (*n == '/')
58838+ return 1;
58839+ else if (c == '?') {
58840+ if (*n == '\0')
58841+ return 1;
58842+ else
58843+ ++n;
58844+ }
58845+ }
58846+ if (c == '\0') {
58847+ return 0;
58848+ } else {
58849+ const char *endp;
58850+
58851+ if ((endp = strchr(n, '/')) == NULL)
58852+ endp = n + strlen(n);
58853+
58854+ if (c == '[') {
58855+ for (--p; n < endp; ++n)
58856+ if (!glob_match(p, n))
58857+ return 0;
58858+ } else if (c == '/') {
58859+ while (*n != '\0' && *n != '/')
58860+ ++n;
58861+ if (*n == '/' && !glob_match(p, n + 1))
58862+ return 0;
58863+ } else {
58864+ for (--p; n < endp; ++n)
58865+ if (*n == c && !glob_match(p, n))
58866+ return 0;
58867+ }
58868+
58869+ return 1;
58870+ }
58871+ case '[':
58872+ {
58873+ int not;
58874+ char cold;
58875+
58876+ if (*n == '\0' || *n == '/')
58877+ return 1;
58878+
58879+ not = (*p == '!' || *p == '^');
58880+ if (not)
58881+ ++p;
58882+
58883+ c = *p++;
58884+ for (;;) {
58885+ unsigned char fn = (unsigned char)*n;
58886+
58887+ if (c == '\0')
58888+ return 1;
58889+ else {
58890+ if (c == fn)
58891+ goto matched;
58892+ cold = c;
58893+ c = *p++;
58894+
58895+ if (c == '-' && *p != ']') {
58896+ unsigned char cend = *p++;
58897+
58898+ if (cend == '\0')
58899+ return 1;
58900+
58901+ if (cold <= fn && fn <= cend)
58902+ goto matched;
58903+
58904+ c = *p++;
58905+ }
58906+ }
58907+
58908+ if (c == ']')
58909+ break;
58910+ }
58911+ if (!not)
58912+ return 1;
58913+ break;
58914+ matched:
58915+ while (c != ']') {
58916+ if (c == '\0')
58917+ return 1;
58918+
58919+ c = *p++;
58920+ }
58921+ if (not)
58922+ return 1;
58923+ }
58924+ break;
58925+ default:
58926+ if (c != *n)
58927+ return 1;
58928+ }
58929+
58930+ ++n;
58931+ }
58932+
58933+ if (*n == '\0')
58934+ return 0;
58935+
58936+ if (*n == '/')
58937+ return 0;
58938+
58939+ return 1;
58940+}
58941+
58942+static struct acl_object_label *
58943+chk_glob_label(struct acl_object_label *globbed,
58944+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
58945+{
58946+ struct acl_object_label *tmp;
58947+
58948+ if (*path == NULL)
58949+ *path = gr_to_filename_nolock(dentry, mnt);
58950+
58951+ tmp = globbed;
58952+
58953+ while (tmp) {
58954+ if (!glob_match(tmp->filename, *path))
58955+ return tmp;
58956+ tmp = tmp->next;
58957+ }
58958+
58959+ return NULL;
58960+}
58961+
58962+static struct acl_object_label *
58963+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58964+ const ino_t curr_ino, const dev_t curr_dev,
58965+ const struct acl_subject_label *subj, char **path, const int checkglob)
58966+{
58967+ struct acl_subject_label *tmpsubj;
58968+ struct acl_object_label *retval;
58969+ struct acl_object_label *retval2;
58970+
58971+ tmpsubj = (struct acl_subject_label *) subj;
58972+ read_lock(&gr_inode_lock);
58973+ do {
58974+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
58975+ if (retval) {
58976+ if (checkglob && retval->globbed) {
58977+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
58978+ if (retval2)
58979+ retval = retval2;
58980+ }
58981+ break;
58982+ }
58983+ } while ((tmpsubj = tmpsubj->parent_subject));
58984+ read_unlock(&gr_inode_lock);
58985+
58986+ return retval;
58987+}
58988+
58989+static __inline__ struct acl_object_label *
58990+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58991+ struct dentry *curr_dentry,
58992+ const struct acl_subject_label *subj, char **path, const int checkglob)
58993+{
58994+ int newglob = checkglob;
58995+ ino_t inode;
58996+ dev_t device;
58997+
58998+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
58999+ as we don't want a / * rule to match instead of the / object
59000+ don't do this for create lookups that call this function though, since they're looking up
59001+ on the parent and thus need globbing checks on all paths
59002+ */
59003+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
59004+ newglob = GR_NO_GLOB;
59005+
59006+ spin_lock(&curr_dentry->d_lock);
59007+ inode = curr_dentry->d_inode->i_ino;
59008+ device = __get_dev(curr_dentry);
59009+ spin_unlock(&curr_dentry->d_lock);
59010+
59011+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
59012+}
59013+
59014+#ifdef CONFIG_HUGETLBFS
59015+static inline bool
59016+is_hugetlbfs_mnt(const struct vfsmount *mnt)
59017+{
59018+ int i;
59019+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
59020+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
59021+ return true;
59022+ }
59023+
59024+ return false;
59025+}
59026+#endif
59027+
59028+static struct acl_object_label *
59029+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59030+ const struct acl_subject_label *subj, char *path, const int checkglob)
59031+{
59032+ struct dentry *dentry = (struct dentry *) l_dentry;
59033+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59034+ struct mount *real_mnt = real_mount(mnt);
59035+ struct acl_object_label *retval;
59036+ struct dentry *parent;
59037+
59038+ write_seqlock(&rename_lock);
59039+ br_read_lock(&vfsmount_lock);
59040+
59041+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
59042+#ifdef CONFIG_NET
59043+ mnt == sock_mnt ||
59044+#endif
59045+#ifdef CONFIG_HUGETLBFS
59046+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
59047+#endif
59048+ /* ignore Eric Biederman */
59049+ IS_PRIVATE(l_dentry->d_inode))) {
59050+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
59051+ goto out;
59052+ }
59053+
59054+ for (;;) {
59055+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59056+ break;
59057+
59058+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59059+ if (!mnt_has_parent(real_mnt))
59060+ break;
59061+
59062+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59063+ if (retval != NULL)
59064+ goto out;
59065+
59066+ dentry = real_mnt->mnt_mountpoint;
59067+ real_mnt = real_mnt->mnt_parent;
59068+ mnt = &real_mnt->mnt;
59069+ continue;
59070+ }
59071+
59072+ parent = dentry->d_parent;
59073+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59074+ if (retval != NULL)
59075+ goto out;
59076+
59077+ dentry = parent;
59078+ }
59079+
59080+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59081+
59082+ /* real_root is pinned so we don't have to hold a reference */
59083+ if (retval == NULL)
59084+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
59085+out:
59086+ br_read_unlock(&vfsmount_lock);
59087+ write_sequnlock(&rename_lock);
59088+
59089+ BUG_ON(retval == NULL);
59090+
59091+ return retval;
59092+}
59093+
59094+static __inline__ struct acl_object_label *
59095+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59096+ const struct acl_subject_label *subj)
59097+{
59098+ char *path = NULL;
59099+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
59100+}
59101+
59102+static __inline__ struct acl_object_label *
59103+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59104+ const struct acl_subject_label *subj)
59105+{
59106+ char *path = NULL;
59107+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
59108+}
59109+
59110+static __inline__ struct acl_object_label *
59111+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59112+ const struct acl_subject_label *subj, char *path)
59113+{
59114+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
59115+}
59116+
59117+static struct acl_subject_label *
59118+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59119+ const struct acl_role_label *role)
59120+{
59121+ struct dentry *dentry = (struct dentry *) l_dentry;
59122+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59123+ struct mount *real_mnt = real_mount(mnt);
59124+ struct acl_subject_label *retval;
59125+ struct dentry *parent;
59126+
59127+ write_seqlock(&rename_lock);
59128+ br_read_lock(&vfsmount_lock);
59129+
59130+ for (;;) {
59131+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59132+ break;
59133+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59134+ if (!mnt_has_parent(real_mnt))
59135+ break;
59136+
59137+ spin_lock(&dentry->d_lock);
59138+ read_lock(&gr_inode_lock);
59139+ retval =
59140+ lookup_acl_subj_label(dentry->d_inode->i_ino,
59141+ __get_dev(dentry), role);
59142+ read_unlock(&gr_inode_lock);
59143+ spin_unlock(&dentry->d_lock);
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+ spin_lock(&dentry->d_lock);
59154+ read_lock(&gr_inode_lock);
59155+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59156+ __get_dev(dentry), role);
59157+ read_unlock(&gr_inode_lock);
59158+ parent = dentry->d_parent;
59159+ spin_unlock(&dentry->d_lock);
59160+
59161+ if (retval != NULL)
59162+ goto out;
59163+
59164+ dentry = parent;
59165+ }
59166+
59167+ spin_lock(&dentry->d_lock);
59168+ read_lock(&gr_inode_lock);
59169+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59170+ __get_dev(dentry), role);
59171+ read_unlock(&gr_inode_lock);
59172+ spin_unlock(&dentry->d_lock);
59173+
59174+ if (unlikely(retval == NULL)) {
59175+ /* real_root is pinned, we don't need to hold a reference */
59176+ read_lock(&gr_inode_lock);
59177+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
59178+ __get_dev(real_root.dentry), role);
59179+ read_unlock(&gr_inode_lock);
59180+ }
59181+out:
59182+ br_read_unlock(&vfsmount_lock);
59183+ write_sequnlock(&rename_lock);
59184+
59185+ BUG_ON(retval == NULL);
59186+
59187+ return retval;
59188+}
59189+
59190+static void
59191+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
59192+{
59193+ struct task_struct *task = current;
59194+ const struct cred *cred = current_cred();
59195+
59196+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
59197+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59198+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59199+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
59200+
59201+ return;
59202+}
59203+
59204+static void
59205+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
59206+{
59207+ struct task_struct *task = current;
59208+ const struct cred *cred = current_cred();
59209+
59210+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59211+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59212+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59213+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
59214+
59215+ return;
59216+}
59217+
59218+static void
59219+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
59220+{
59221+ struct task_struct *task = current;
59222+ const struct cred *cred = current_cred();
59223+
59224+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59225+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59226+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59227+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
59228+
59229+ return;
59230+}
59231+
59232+__u32
59233+gr_search_file(const struct dentry * dentry, const __u32 mode,
59234+ const struct vfsmount * mnt)
59235+{
59236+ __u32 retval = mode;
59237+ struct acl_subject_label *curracl;
59238+ struct acl_object_label *currobj;
59239+
59240+ if (unlikely(!(gr_status & GR_READY)))
59241+ return (mode & ~GR_AUDITS);
59242+
59243+ curracl = current->acl;
59244+
59245+ currobj = chk_obj_label(dentry, mnt, curracl);
59246+ retval = currobj->mode & mode;
59247+
59248+ /* if we're opening a specified transfer file for writing
59249+ (e.g. /dev/initctl), then transfer our role to init
59250+ */
59251+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
59252+ current->role->roletype & GR_ROLE_PERSIST)) {
59253+ struct task_struct *task = init_pid_ns.child_reaper;
59254+
59255+ if (task->role != current->role) {
59256+ task->acl_sp_role = 0;
59257+ task->acl_role_id = current->acl_role_id;
59258+ task->role = current->role;
59259+ rcu_read_lock();
59260+ read_lock(&grsec_exec_file_lock);
59261+ gr_apply_subject_to_task(task);
59262+ read_unlock(&grsec_exec_file_lock);
59263+ rcu_read_unlock();
59264+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
59265+ }
59266+ }
59267+
59268+ if (unlikely
59269+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
59270+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
59271+ __u32 new_mode = mode;
59272+
59273+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59274+
59275+ retval = new_mode;
59276+
59277+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
59278+ new_mode |= GR_INHERIT;
59279+
59280+ if (!(mode & GR_NOLEARN))
59281+ gr_log_learn(dentry, mnt, new_mode);
59282+ }
59283+
59284+ return retval;
59285+}
59286+
59287+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
59288+ const struct dentry *parent,
59289+ const struct vfsmount *mnt)
59290+{
59291+ struct name_entry *match;
59292+ struct acl_object_label *matchpo;
59293+ struct acl_subject_label *curracl;
59294+ char *path;
59295+
59296+ if (unlikely(!(gr_status & GR_READY)))
59297+ return NULL;
59298+
59299+ preempt_disable();
59300+ path = gr_to_filename_rbac(new_dentry, mnt);
59301+ match = lookup_name_entry_create(path);
59302+
59303+ curracl = current->acl;
59304+
59305+ if (match) {
59306+ read_lock(&gr_inode_lock);
59307+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
59308+ read_unlock(&gr_inode_lock);
59309+
59310+ if (matchpo) {
59311+ preempt_enable();
59312+ return matchpo;
59313+ }
59314+ }
59315+
59316+ // lookup parent
59317+
59318+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
59319+
59320+ preempt_enable();
59321+ return matchpo;
59322+}
59323+
59324+__u32
59325+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
59326+ const struct vfsmount * mnt, const __u32 mode)
59327+{
59328+ struct acl_object_label *matchpo;
59329+ __u32 retval;
59330+
59331+ if (unlikely(!(gr_status & GR_READY)))
59332+ return (mode & ~GR_AUDITS);
59333+
59334+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
59335+
59336+ retval = matchpo->mode & mode;
59337+
59338+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
59339+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59340+ __u32 new_mode = mode;
59341+
59342+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59343+
59344+ gr_log_learn(new_dentry, mnt, new_mode);
59345+ return new_mode;
59346+ }
59347+
59348+ return retval;
59349+}
59350+
59351+__u32
59352+gr_check_link(const struct dentry * new_dentry,
59353+ const struct dentry * parent_dentry,
59354+ const struct vfsmount * parent_mnt,
59355+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
59356+{
59357+ struct acl_object_label *obj;
59358+ __u32 oldmode, newmode;
59359+ __u32 needmode;
59360+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
59361+ GR_DELETE | GR_INHERIT;
59362+
59363+ if (unlikely(!(gr_status & GR_READY)))
59364+ return (GR_CREATE | GR_LINK);
59365+
59366+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
59367+ oldmode = obj->mode;
59368+
59369+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
59370+ newmode = obj->mode;
59371+
59372+ needmode = newmode & checkmodes;
59373+
59374+ // old name for hardlink must have at least the permissions of the new name
59375+ if ((oldmode & needmode) != needmode)
59376+ goto bad;
59377+
59378+ // if old name had restrictions/auditing, make sure the new name does as well
59379+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
59380+
59381+ // don't allow hardlinking of suid/sgid/fcapped files without permission
59382+ if (is_privileged_binary(old_dentry))
59383+ needmode |= GR_SETID;
59384+
59385+ if ((newmode & needmode) != needmode)
59386+ goto bad;
59387+
59388+ // enforce minimum permissions
59389+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
59390+ return newmode;
59391+bad:
59392+ needmode = oldmode;
59393+ if (is_privileged_binary(old_dentry))
59394+ needmode |= GR_SETID;
59395+
59396+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
59397+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
59398+ return (GR_CREATE | GR_LINK);
59399+ } else if (newmode & GR_SUPPRESS)
59400+ return GR_SUPPRESS;
59401+ else
59402+ return 0;
59403+}
59404+
59405+int
59406+gr_check_hidden_task(const struct task_struct *task)
59407+{
59408+ if (unlikely(!(gr_status & GR_READY)))
59409+ return 0;
59410+
59411+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
59412+ return 1;
59413+
59414+ return 0;
59415+}
59416+
59417+int
59418+gr_check_protected_task(const struct task_struct *task)
59419+{
59420+ if (unlikely(!(gr_status & GR_READY) || !task))
59421+ return 0;
59422+
59423+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59424+ task->acl != current->acl)
59425+ return 1;
59426+
59427+ return 0;
59428+}
59429+
59430+int
59431+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59432+{
59433+ struct task_struct *p;
59434+ int ret = 0;
59435+
59436+ if (unlikely(!(gr_status & GR_READY) || !pid))
59437+ return ret;
59438+
59439+ read_lock(&tasklist_lock);
59440+ do_each_pid_task(pid, type, p) {
59441+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59442+ p->acl != current->acl) {
59443+ ret = 1;
59444+ goto out;
59445+ }
59446+ } while_each_pid_task(pid, type, p);
59447+out:
59448+ read_unlock(&tasklist_lock);
59449+
59450+ return ret;
59451+}
59452+
59453+void
59454+gr_copy_label(struct task_struct *tsk)
59455+{
59456+ tsk->signal->used_accept = 0;
59457+ tsk->acl_sp_role = 0;
59458+ tsk->acl_role_id = current->acl_role_id;
59459+ tsk->acl = current->acl;
59460+ tsk->role = current->role;
59461+ tsk->signal->curr_ip = current->signal->curr_ip;
59462+ tsk->signal->saved_ip = current->signal->saved_ip;
59463+ if (current->exec_file)
59464+ get_file(current->exec_file);
59465+ tsk->exec_file = current->exec_file;
59466+ tsk->is_writable = current->is_writable;
59467+ if (unlikely(current->signal->used_accept)) {
59468+ current->signal->curr_ip = 0;
59469+ current->signal->saved_ip = 0;
59470+ }
59471+
59472+ return;
59473+}
59474+
59475+static void
59476+gr_set_proc_res(struct task_struct *task)
59477+{
59478+ struct acl_subject_label *proc;
59479+ unsigned short i;
59480+
59481+ proc = task->acl;
59482+
59483+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
59484+ return;
59485+
59486+ for (i = 0; i < RLIM_NLIMITS; i++) {
59487+ if (!(proc->resmask & (1 << i)))
59488+ continue;
59489+
59490+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
59491+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
59492+
59493+ if (i == RLIMIT_CPU)
59494+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
59495+ }
59496+
59497+ return;
59498+}
59499+
59500+extern int __gr_process_user_ban(struct user_struct *user);
59501+
59502+int
59503+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
59504+{
59505+ unsigned int i;
59506+ __u16 num;
59507+ uid_t *uidlist;
59508+ uid_t curuid;
59509+ int realok = 0;
59510+ int effectiveok = 0;
59511+ int fsok = 0;
59512+ uid_t globalreal, globaleffective, globalfs;
59513+
59514+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59515+ struct user_struct *user;
59516+
59517+ if (!uid_valid(real))
59518+ goto skipit;
59519+
59520+ /* find user based on global namespace */
59521+
59522+ globalreal = GR_GLOBAL_UID(real);
59523+
59524+ user = find_user(make_kuid(&init_user_ns, globalreal));
59525+ if (user == NULL)
59526+ goto skipit;
59527+
59528+ if (__gr_process_user_ban(user)) {
59529+ /* for find_user */
59530+ free_uid(user);
59531+ return 1;
59532+ }
59533+
59534+ /* for find_user */
59535+ free_uid(user);
59536+
59537+skipit:
59538+#endif
59539+
59540+ if (unlikely(!(gr_status & GR_READY)))
59541+ return 0;
59542+
59543+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59544+ gr_log_learn_uid_change(real, effective, fs);
59545+
59546+ num = current->acl->user_trans_num;
59547+ uidlist = current->acl->user_transitions;
59548+
59549+ if (uidlist == NULL)
59550+ return 0;
59551+
59552+ if (!uid_valid(real)) {
59553+ realok = 1;
59554+ globalreal = (uid_t)-1;
59555+ } else {
59556+ globalreal = GR_GLOBAL_UID(real);
59557+ }
59558+ if (!uid_valid(effective)) {
59559+ effectiveok = 1;
59560+ globaleffective = (uid_t)-1;
59561+ } else {
59562+ globaleffective = GR_GLOBAL_UID(effective);
59563+ }
59564+ if (!uid_valid(fs)) {
59565+ fsok = 1;
59566+ globalfs = (uid_t)-1;
59567+ } else {
59568+ globalfs = GR_GLOBAL_UID(fs);
59569+ }
59570+
59571+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
59572+ for (i = 0; i < num; i++) {
59573+ curuid = uidlist[i];
59574+ if (globalreal == curuid)
59575+ realok = 1;
59576+ if (globaleffective == curuid)
59577+ effectiveok = 1;
59578+ if (globalfs == curuid)
59579+ fsok = 1;
59580+ }
59581+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
59582+ for (i = 0; i < num; i++) {
59583+ curuid = uidlist[i];
59584+ if (globalreal == curuid)
59585+ break;
59586+ if (globaleffective == curuid)
59587+ break;
59588+ if (globalfs == curuid)
59589+ break;
59590+ }
59591+ /* not in deny list */
59592+ if (i == num) {
59593+ realok = 1;
59594+ effectiveok = 1;
59595+ fsok = 1;
59596+ }
59597+ }
59598+
59599+ if (realok && effectiveok && fsok)
59600+ return 0;
59601+ else {
59602+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59603+ return 1;
59604+ }
59605+}
59606+
59607+int
59608+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
59609+{
59610+ unsigned int i;
59611+ __u16 num;
59612+ gid_t *gidlist;
59613+ gid_t curgid;
59614+ int realok = 0;
59615+ int effectiveok = 0;
59616+ int fsok = 0;
59617+ gid_t globalreal, globaleffective, globalfs;
59618+
59619+ if (unlikely(!(gr_status & GR_READY)))
59620+ return 0;
59621+
59622+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59623+ gr_log_learn_gid_change(real, effective, fs);
59624+
59625+ num = current->acl->group_trans_num;
59626+ gidlist = current->acl->group_transitions;
59627+
59628+ if (gidlist == NULL)
59629+ return 0;
59630+
59631+ if (!gid_valid(real)) {
59632+ realok = 1;
59633+ globalreal = (gid_t)-1;
59634+ } else {
59635+ globalreal = GR_GLOBAL_GID(real);
59636+ }
59637+ if (!gid_valid(effective)) {
59638+ effectiveok = 1;
59639+ globaleffective = (gid_t)-1;
59640+ } else {
59641+ globaleffective = GR_GLOBAL_GID(effective);
59642+ }
59643+ if (!gid_valid(fs)) {
59644+ fsok = 1;
59645+ globalfs = (gid_t)-1;
59646+ } else {
59647+ globalfs = GR_GLOBAL_GID(fs);
59648+ }
59649+
59650+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
59651+ for (i = 0; i < num; i++) {
59652+ curgid = gidlist[i];
59653+ if (globalreal == curgid)
59654+ realok = 1;
59655+ if (globaleffective == curgid)
59656+ effectiveok = 1;
59657+ if (globalfs == curgid)
59658+ fsok = 1;
59659+ }
59660+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
59661+ for (i = 0; i < num; i++) {
59662+ curgid = gidlist[i];
59663+ if (globalreal == curgid)
59664+ break;
59665+ if (globaleffective == curgid)
59666+ break;
59667+ if (globalfs == curgid)
59668+ break;
59669+ }
59670+ /* not in deny list */
59671+ if (i == num) {
59672+ realok = 1;
59673+ effectiveok = 1;
59674+ fsok = 1;
59675+ }
59676+ }
59677+
59678+ if (realok && effectiveok && fsok)
59679+ return 0;
59680+ else {
59681+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59682+ return 1;
59683+ }
59684+}
59685+
59686+extern int gr_acl_is_capable(const int cap);
59687+
59688+void
59689+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
59690+{
59691+ struct acl_role_label *role = task->role;
59692+ struct acl_subject_label *subj = NULL;
59693+ struct acl_object_label *obj;
59694+ struct file *filp;
59695+ uid_t uid;
59696+ gid_t gid;
59697+
59698+ if (unlikely(!(gr_status & GR_READY)))
59699+ return;
59700+
59701+ uid = GR_GLOBAL_UID(kuid);
59702+ gid = GR_GLOBAL_GID(kgid);
59703+
59704+ filp = task->exec_file;
59705+
59706+ /* kernel process, we'll give them the kernel role */
59707+ if (unlikely(!filp)) {
59708+ task->role = kernel_role;
59709+ task->acl = kernel_role->root_label;
59710+ return;
59711+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
59712+ role = lookup_acl_role_label(task, uid, gid);
59713+
59714+ /* don't change the role if we're not a privileged process */
59715+ if (role && task->role != role &&
59716+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
59717+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
59718+ return;
59719+
59720+ /* perform subject lookup in possibly new role
59721+ we can use this result below in the case where role == task->role
59722+ */
59723+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
59724+
59725+ /* if we changed uid/gid, but result in the same role
59726+ and are using inheritance, don't lose the inherited subject
59727+ if current subject is other than what normal lookup
59728+ would result in, we arrived via inheritance, don't
59729+ lose subject
59730+ */
59731+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
59732+ (subj == task->acl)))
59733+ task->acl = subj;
59734+
59735+ task->role = role;
59736+
59737+ task->is_writable = 0;
59738+
59739+ /* ignore additional mmap checks for processes that are writable
59740+ by the default ACL */
59741+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59742+ if (unlikely(obj->mode & GR_WRITE))
59743+ task->is_writable = 1;
59744+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59745+ if (unlikely(obj->mode & GR_WRITE))
59746+ task->is_writable = 1;
59747+
59748+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59749+ 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);
59750+#endif
59751+
59752+ gr_set_proc_res(task);
59753+
59754+ return;
59755+}
59756+
59757+int
59758+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59759+ const int unsafe_flags)
59760+{
59761+ struct task_struct *task = current;
59762+ struct acl_subject_label *newacl;
59763+ struct acl_object_label *obj;
59764+ __u32 retmode;
59765+
59766+ if (unlikely(!(gr_status & GR_READY)))
59767+ return 0;
59768+
59769+ newacl = chk_subj_label(dentry, mnt, task->role);
59770+
59771+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
59772+ did an exec
59773+ */
59774+ rcu_read_lock();
59775+ read_lock(&tasklist_lock);
59776+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
59777+ (task->parent->acl->mode & GR_POVERRIDE))) {
59778+ read_unlock(&tasklist_lock);
59779+ rcu_read_unlock();
59780+ goto skip_check;
59781+ }
59782+ read_unlock(&tasklist_lock);
59783+ rcu_read_unlock();
59784+
59785+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
59786+ !(task->role->roletype & GR_ROLE_GOD) &&
59787+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
59788+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59789+ if (unsafe_flags & LSM_UNSAFE_SHARE)
59790+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
59791+ else
59792+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
59793+ return -EACCES;
59794+ }
59795+
59796+skip_check:
59797+
59798+ obj = chk_obj_label(dentry, mnt, task->acl);
59799+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
59800+
59801+ if (!(task->acl->mode & GR_INHERITLEARN) &&
59802+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
59803+ if (obj->nested)
59804+ task->acl = obj->nested;
59805+ else
59806+ task->acl = newacl;
59807+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
59808+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
59809+
59810+ task->is_writable = 0;
59811+
59812+ /* ignore additional mmap checks for processes that are writable
59813+ by the default ACL */
59814+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
59815+ if (unlikely(obj->mode & GR_WRITE))
59816+ task->is_writable = 1;
59817+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
59818+ if (unlikely(obj->mode & GR_WRITE))
59819+ task->is_writable = 1;
59820+
59821+ gr_set_proc_res(task);
59822+
59823+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59824+ 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);
59825+#endif
59826+ return 0;
59827+}
59828+
59829+/* always called with valid inodev ptr */
59830+static void
59831+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
59832+{
59833+ struct acl_object_label *matchpo;
59834+ struct acl_subject_label *matchps;
59835+ struct acl_subject_label *subj;
59836+ struct acl_role_label *role;
59837+ unsigned int x;
59838+
59839+ FOR_EACH_ROLE_START(role)
59840+ FOR_EACH_SUBJECT_START(role, subj, x)
59841+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59842+ matchpo->mode |= GR_DELETED;
59843+ FOR_EACH_SUBJECT_END(subj,x)
59844+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
59845+ /* nested subjects aren't in the role's subj_hash table */
59846+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59847+ matchpo->mode |= GR_DELETED;
59848+ FOR_EACH_NESTED_SUBJECT_END(subj)
59849+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
59850+ matchps->mode |= GR_DELETED;
59851+ FOR_EACH_ROLE_END(role)
59852+
59853+ inodev->nentry->deleted = 1;
59854+
59855+ return;
59856+}
59857+
59858+void
59859+gr_handle_delete(const ino_t ino, const dev_t dev)
59860+{
59861+ struct inodev_entry *inodev;
59862+
59863+ if (unlikely(!(gr_status & GR_READY)))
59864+ return;
59865+
59866+ write_lock(&gr_inode_lock);
59867+ inodev = lookup_inodev_entry(ino, dev);
59868+ if (inodev != NULL)
59869+ do_handle_delete(inodev, ino, dev);
59870+ write_unlock(&gr_inode_lock);
59871+
59872+ return;
59873+}
59874+
59875+static void
59876+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
59877+ const ino_t newinode, const dev_t newdevice,
59878+ struct acl_subject_label *subj)
59879+{
59880+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
59881+ struct acl_object_label *match;
59882+
59883+ match = subj->obj_hash[index];
59884+
59885+ while (match && (match->inode != oldinode ||
59886+ match->device != olddevice ||
59887+ !(match->mode & GR_DELETED)))
59888+ match = match->next;
59889+
59890+ if (match && (match->inode == oldinode)
59891+ && (match->device == olddevice)
59892+ && (match->mode & GR_DELETED)) {
59893+ if (match->prev == NULL) {
59894+ subj->obj_hash[index] = match->next;
59895+ if (match->next != NULL)
59896+ match->next->prev = NULL;
59897+ } else {
59898+ match->prev->next = match->next;
59899+ if (match->next != NULL)
59900+ match->next->prev = match->prev;
59901+ }
59902+ match->prev = NULL;
59903+ match->next = NULL;
59904+ match->inode = newinode;
59905+ match->device = newdevice;
59906+ match->mode &= ~GR_DELETED;
59907+
59908+ insert_acl_obj_label(match, subj);
59909+ }
59910+
59911+ return;
59912+}
59913+
59914+static void
59915+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
59916+ const ino_t newinode, const dev_t newdevice,
59917+ struct acl_role_label *role)
59918+{
59919+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
59920+ struct acl_subject_label *match;
59921+
59922+ match = role->subj_hash[index];
59923+
59924+ while (match && (match->inode != oldinode ||
59925+ match->device != olddevice ||
59926+ !(match->mode & GR_DELETED)))
59927+ match = match->next;
59928+
59929+ if (match && (match->inode == oldinode)
59930+ && (match->device == olddevice)
59931+ && (match->mode & GR_DELETED)) {
59932+ if (match->prev == NULL) {
59933+ role->subj_hash[index] = match->next;
59934+ if (match->next != NULL)
59935+ match->next->prev = NULL;
59936+ } else {
59937+ match->prev->next = match->next;
59938+ if (match->next != NULL)
59939+ match->next->prev = match->prev;
59940+ }
59941+ match->prev = NULL;
59942+ match->next = NULL;
59943+ match->inode = newinode;
59944+ match->device = newdevice;
59945+ match->mode &= ~GR_DELETED;
59946+
59947+ insert_acl_subj_label(match, role);
59948+ }
59949+
59950+ return;
59951+}
59952+
59953+static void
59954+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
59955+ const ino_t newinode, const dev_t newdevice)
59956+{
59957+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
59958+ struct inodev_entry *match;
59959+
59960+ match = inodev_set.i_hash[index];
59961+
59962+ while (match && (match->nentry->inode != oldinode ||
59963+ match->nentry->device != olddevice || !match->nentry->deleted))
59964+ match = match->next;
59965+
59966+ if (match && (match->nentry->inode == oldinode)
59967+ && (match->nentry->device == olddevice) &&
59968+ match->nentry->deleted) {
59969+ if (match->prev == NULL) {
59970+ inodev_set.i_hash[index] = match->next;
59971+ if (match->next != NULL)
59972+ match->next->prev = NULL;
59973+ } else {
59974+ match->prev->next = match->next;
59975+ if (match->next != NULL)
59976+ match->next->prev = match->prev;
59977+ }
59978+ match->prev = NULL;
59979+ match->next = NULL;
59980+ match->nentry->inode = newinode;
59981+ match->nentry->device = newdevice;
59982+ match->nentry->deleted = 0;
59983+
59984+ insert_inodev_entry(match);
59985+ }
59986+
59987+ return;
59988+}
59989+
59990+static void
59991+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
59992+{
59993+ struct acl_subject_label *subj;
59994+ struct acl_role_label *role;
59995+ unsigned int x;
59996+
59997+ FOR_EACH_ROLE_START(role)
59998+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
59999+
60000+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60001+ if ((subj->inode == ino) && (subj->device == dev)) {
60002+ subj->inode = ino;
60003+ subj->device = dev;
60004+ }
60005+ /* nested subjects aren't in the role's subj_hash table */
60006+ update_acl_obj_label(matchn->inode, matchn->device,
60007+ ino, dev, subj);
60008+ FOR_EACH_NESTED_SUBJECT_END(subj)
60009+ FOR_EACH_SUBJECT_START(role, subj, x)
60010+ update_acl_obj_label(matchn->inode, matchn->device,
60011+ ino, dev, subj);
60012+ FOR_EACH_SUBJECT_END(subj,x)
60013+ FOR_EACH_ROLE_END(role)
60014+
60015+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
60016+
60017+ return;
60018+}
60019+
60020+static void
60021+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
60022+ const struct vfsmount *mnt)
60023+{
60024+ ino_t ino = dentry->d_inode->i_ino;
60025+ dev_t dev = __get_dev(dentry);
60026+
60027+ __do_handle_create(matchn, ino, dev);
60028+
60029+ return;
60030+}
60031+
60032+void
60033+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60034+{
60035+ struct name_entry *matchn;
60036+
60037+ if (unlikely(!(gr_status & GR_READY)))
60038+ return;
60039+
60040+ preempt_disable();
60041+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
60042+
60043+ if (unlikely((unsigned long)matchn)) {
60044+ write_lock(&gr_inode_lock);
60045+ do_handle_create(matchn, dentry, mnt);
60046+ write_unlock(&gr_inode_lock);
60047+ }
60048+ preempt_enable();
60049+
60050+ return;
60051+}
60052+
60053+void
60054+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60055+{
60056+ struct name_entry *matchn;
60057+
60058+ if (unlikely(!(gr_status & GR_READY)))
60059+ return;
60060+
60061+ preempt_disable();
60062+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
60063+
60064+ if (unlikely((unsigned long)matchn)) {
60065+ write_lock(&gr_inode_lock);
60066+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
60067+ write_unlock(&gr_inode_lock);
60068+ }
60069+ preempt_enable();
60070+
60071+ return;
60072+}
60073+
60074+void
60075+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60076+ struct dentry *old_dentry,
60077+ struct dentry *new_dentry,
60078+ struct vfsmount *mnt, const __u8 replace)
60079+{
60080+ struct name_entry *matchn;
60081+ struct inodev_entry *inodev;
60082+ struct inode *inode = new_dentry->d_inode;
60083+ ino_t old_ino = old_dentry->d_inode->i_ino;
60084+ dev_t old_dev = __get_dev(old_dentry);
60085+
60086+ /* vfs_rename swaps the name and parent link for old_dentry and
60087+ new_dentry
60088+ at this point, old_dentry has the new name, parent link, and inode
60089+ for the renamed file
60090+ if a file is being replaced by a rename, new_dentry has the inode
60091+ and name for the replaced file
60092+ */
60093+
60094+ if (unlikely(!(gr_status & GR_READY)))
60095+ return;
60096+
60097+ preempt_disable();
60098+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
60099+
60100+ /* we wouldn't have to check d_inode if it weren't for
60101+ NFS silly-renaming
60102+ */
60103+
60104+ write_lock(&gr_inode_lock);
60105+ if (unlikely(replace && inode)) {
60106+ ino_t new_ino = inode->i_ino;
60107+ dev_t new_dev = __get_dev(new_dentry);
60108+
60109+ inodev = lookup_inodev_entry(new_ino, new_dev);
60110+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
60111+ do_handle_delete(inodev, new_ino, new_dev);
60112+ }
60113+
60114+ inodev = lookup_inodev_entry(old_ino, old_dev);
60115+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
60116+ do_handle_delete(inodev, old_ino, old_dev);
60117+
60118+ if (unlikely((unsigned long)matchn))
60119+ do_handle_create(matchn, old_dentry, mnt);
60120+
60121+ write_unlock(&gr_inode_lock);
60122+ preempt_enable();
60123+
60124+ return;
60125+}
60126+
60127+static int
60128+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
60129+ unsigned char **sum)
60130+{
60131+ struct acl_role_label *r;
60132+ struct role_allowed_ip *ipp;
60133+ struct role_transition *trans;
60134+ unsigned int i;
60135+ int found = 0;
60136+ u32 curr_ip = current->signal->curr_ip;
60137+
60138+ current->signal->saved_ip = curr_ip;
60139+
60140+ /* check transition table */
60141+
60142+ for (trans = current->role->transitions; trans; trans = trans->next) {
60143+ if (!strcmp(rolename, trans->rolename)) {
60144+ found = 1;
60145+ break;
60146+ }
60147+ }
60148+
60149+ if (!found)
60150+ return 0;
60151+
60152+ /* handle special roles that do not require authentication
60153+ and check ip */
60154+
60155+ FOR_EACH_ROLE_START(r)
60156+ if (!strcmp(rolename, r->rolename) &&
60157+ (r->roletype & GR_ROLE_SPECIAL)) {
60158+ found = 0;
60159+ if (r->allowed_ips != NULL) {
60160+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
60161+ if ((ntohl(curr_ip) & ipp->netmask) ==
60162+ (ntohl(ipp->addr) & ipp->netmask))
60163+ found = 1;
60164+ }
60165+ } else
60166+ found = 2;
60167+ if (!found)
60168+ return 0;
60169+
60170+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
60171+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
60172+ *salt = NULL;
60173+ *sum = NULL;
60174+ return 1;
60175+ }
60176+ }
60177+ FOR_EACH_ROLE_END(r)
60178+
60179+ for (i = 0; i < num_sprole_pws; i++) {
60180+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
60181+ *salt = acl_special_roles[i]->salt;
60182+ *sum = acl_special_roles[i]->sum;
60183+ return 1;
60184+ }
60185+ }
60186+
60187+ return 0;
60188+}
60189+
60190+static void
60191+assign_special_role(char *rolename)
60192+{
60193+ struct acl_object_label *obj;
60194+ struct acl_role_label *r;
60195+ struct acl_role_label *assigned = NULL;
60196+ struct task_struct *tsk;
60197+ struct file *filp;
60198+
60199+ FOR_EACH_ROLE_START(r)
60200+ if (!strcmp(rolename, r->rolename) &&
60201+ (r->roletype & GR_ROLE_SPECIAL)) {
60202+ assigned = r;
60203+ break;
60204+ }
60205+ FOR_EACH_ROLE_END(r)
60206+
60207+ if (!assigned)
60208+ return;
60209+
60210+ read_lock(&tasklist_lock);
60211+ read_lock(&grsec_exec_file_lock);
60212+
60213+ tsk = current->real_parent;
60214+ if (tsk == NULL)
60215+ goto out_unlock;
60216+
60217+ filp = tsk->exec_file;
60218+ if (filp == NULL)
60219+ goto out_unlock;
60220+
60221+ tsk->is_writable = 0;
60222+
60223+ tsk->acl_sp_role = 1;
60224+ tsk->acl_role_id = ++acl_sp_role_value;
60225+ tsk->role = assigned;
60226+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
60227+
60228+ /* ignore additional mmap checks for processes that are writable
60229+ by the default ACL */
60230+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60231+ if (unlikely(obj->mode & GR_WRITE))
60232+ tsk->is_writable = 1;
60233+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
60234+ if (unlikely(obj->mode & GR_WRITE))
60235+ tsk->is_writable = 1;
60236+
60237+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60238+ 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));
60239+#endif
60240+
60241+out_unlock:
60242+ read_unlock(&grsec_exec_file_lock);
60243+ read_unlock(&tasklist_lock);
60244+ return;
60245+}
60246+
60247+int gr_check_secure_terminal(struct task_struct *task)
60248+{
60249+ struct task_struct *p, *p2, *p3;
60250+ struct files_struct *files;
60251+ struct fdtable *fdt;
60252+ struct file *our_file = NULL, *file;
60253+ int i;
60254+
60255+ if (task->signal->tty == NULL)
60256+ return 1;
60257+
60258+ files = get_files_struct(task);
60259+ if (files != NULL) {
60260+ rcu_read_lock();
60261+ fdt = files_fdtable(files);
60262+ for (i=0; i < fdt->max_fds; i++) {
60263+ file = fcheck_files(files, i);
60264+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
60265+ get_file(file);
60266+ our_file = file;
60267+ }
60268+ }
60269+ rcu_read_unlock();
60270+ put_files_struct(files);
60271+ }
60272+
60273+ if (our_file == NULL)
60274+ return 1;
60275+
60276+ read_lock(&tasklist_lock);
60277+ do_each_thread(p2, p) {
60278+ files = get_files_struct(p);
60279+ if (files == NULL ||
60280+ (p->signal && p->signal->tty == task->signal->tty)) {
60281+ if (files != NULL)
60282+ put_files_struct(files);
60283+ continue;
60284+ }
60285+ rcu_read_lock();
60286+ fdt = files_fdtable(files);
60287+ for (i=0; i < fdt->max_fds; i++) {
60288+ file = fcheck_files(files, i);
60289+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
60290+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
60291+ p3 = task;
60292+ while (task_pid_nr(p3) > 0) {
60293+ if (p3 == p)
60294+ break;
60295+ p3 = p3->real_parent;
60296+ }
60297+ if (p3 == p)
60298+ break;
60299+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
60300+ gr_handle_alertkill(p);
60301+ rcu_read_unlock();
60302+ put_files_struct(files);
60303+ read_unlock(&tasklist_lock);
60304+ fput(our_file);
60305+ return 0;
60306+ }
60307+ }
60308+ rcu_read_unlock();
60309+ put_files_struct(files);
60310+ } while_each_thread(p2, p);
60311+ read_unlock(&tasklist_lock);
60312+
60313+ fput(our_file);
60314+ return 1;
60315+}
60316+
60317+static int gr_rbac_disable(void *unused)
60318+{
60319+ pax_open_kernel();
60320+ gr_status &= ~GR_READY;
60321+ pax_close_kernel();
60322+
60323+ return 0;
60324+}
60325+
60326+ssize_t
60327+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
60328+{
60329+ struct gr_arg_wrapper uwrap;
60330+ unsigned char *sprole_salt = NULL;
60331+ unsigned char *sprole_sum = NULL;
60332+ int error = sizeof (struct gr_arg_wrapper);
60333+ int error2 = 0;
60334+
60335+ mutex_lock(&gr_dev_mutex);
60336+
60337+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
60338+ error = -EPERM;
60339+ goto out;
60340+ }
60341+
60342+ if (count != sizeof (struct gr_arg_wrapper)) {
60343+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
60344+ error = -EINVAL;
60345+ goto out;
60346+ }
60347+
60348+
60349+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
60350+ gr_auth_expires = 0;
60351+ gr_auth_attempts = 0;
60352+ }
60353+
60354+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
60355+ error = -EFAULT;
60356+ goto out;
60357+ }
60358+
60359+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
60360+ error = -EINVAL;
60361+ goto out;
60362+ }
60363+
60364+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
60365+ error = -EFAULT;
60366+ goto out;
60367+ }
60368+
60369+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60370+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60371+ time_after(gr_auth_expires, get_seconds())) {
60372+ error = -EBUSY;
60373+ goto out;
60374+ }
60375+
60376+ /* if non-root trying to do anything other than use a special role,
60377+ do not attempt authentication, do not count towards authentication
60378+ locking
60379+ */
60380+
60381+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
60382+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60383+ gr_is_global_nonroot(current_uid())) {
60384+ error = -EPERM;
60385+ goto out;
60386+ }
60387+
60388+ /* ensure pw and special role name are null terminated */
60389+
60390+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
60391+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
60392+
60393+ /* Okay.
60394+ * We have our enough of the argument structure..(we have yet
60395+ * to copy_from_user the tables themselves) . Copy the tables
60396+ * only if we need them, i.e. for loading operations. */
60397+
60398+ switch (gr_usermode->mode) {
60399+ case GR_STATUS:
60400+ if (gr_status & GR_READY) {
60401+ error = 1;
60402+ if (!gr_check_secure_terminal(current))
60403+ error = 3;
60404+ } else
60405+ error = 2;
60406+ goto out;
60407+ case GR_SHUTDOWN:
60408+ if ((gr_status & GR_READY)
60409+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60410+ stop_machine(gr_rbac_disable, NULL, NULL);
60411+ free_variables();
60412+ memset(gr_usermode, 0, sizeof (struct gr_arg));
60413+ memset(gr_system_salt, 0, GR_SALT_LEN);
60414+ memset(gr_system_sum, 0, GR_SHA_LEN);
60415+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
60416+ } else if (gr_status & GR_READY) {
60417+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
60418+ error = -EPERM;
60419+ } else {
60420+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
60421+ error = -EAGAIN;
60422+ }
60423+ break;
60424+ case GR_ENABLE:
60425+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
60426+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
60427+ else {
60428+ if (gr_status & GR_READY)
60429+ error = -EAGAIN;
60430+ else
60431+ error = error2;
60432+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
60433+ }
60434+ break;
60435+ case GR_RELOAD:
60436+ if (!(gr_status & GR_READY)) {
60437+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
60438+ error = -EAGAIN;
60439+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60440+ stop_machine(gr_rbac_disable, NULL, NULL);
60441+ free_variables();
60442+ error2 = gracl_init(gr_usermode);
60443+ if (!error2)
60444+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
60445+ else {
60446+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60447+ error = error2;
60448+ }
60449+ } else {
60450+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60451+ error = -EPERM;
60452+ }
60453+ break;
60454+ case GR_SEGVMOD:
60455+ if (unlikely(!(gr_status & GR_READY))) {
60456+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
60457+ error = -EAGAIN;
60458+ break;
60459+ }
60460+
60461+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60462+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
60463+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
60464+ struct acl_subject_label *segvacl;
60465+ segvacl =
60466+ lookup_acl_subj_label(gr_usermode->segv_inode,
60467+ gr_usermode->segv_device,
60468+ current->role);
60469+ if (segvacl) {
60470+ segvacl->crashes = 0;
60471+ segvacl->expires = 0;
60472+ }
60473+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
60474+ gr_remove_uid(gr_usermode->segv_uid);
60475+ }
60476+ } else {
60477+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
60478+ error = -EPERM;
60479+ }
60480+ break;
60481+ case GR_SPROLE:
60482+ case GR_SPROLEPAM:
60483+ if (unlikely(!(gr_status & GR_READY))) {
60484+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
60485+ error = -EAGAIN;
60486+ break;
60487+ }
60488+
60489+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
60490+ current->role->expires = 0;
60491+ current->role->auth_attempts = 0;
60492+ }
60493+
60494+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60495+ time_after(current->role->expires, get_seconds())) {
60496+ error = -EBUSY;
60497+ goto out;
60498+ }
60499+
60500+ if (lookup_special_role_auth
60501+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
60502+ && ((!sprole_salt && !sprole_sum)
60503+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
60504+ char *p = "";
60505+ assign_special_role(gr_usermode->sp_role);
60506+ read_lock(&tasklist_lock);
60507+ if (current->real_parent)
60508+ p = current->real_parent->role->rolename;
60509+ read_unlock(&tasklist_lock);
60510+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
60511+ p, acl_sp_role_value);
60512+ } else {
60513+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
60514+ error = -EPERM;
60515+ if(!(current->role->auth_attempts++))
60516+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60517+
60518+ goto out;
60519+ }
60520+ break;
60521+ case GR_UNSPROLE:
60522+ if (unlikely(!(gr_status & GR_READY))) {
60523+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
60524+ error = -EAGAIN;
60525+ break;
60526+ }
60527+
60528+ if (current->role->roletype & GR_ROLE_SPECIAL) {
60529+ char *p = "";
60530+ int i = 0;
60531+
60532+ read_lock(&tasklist_lock);
60533+ if (current->real_parent) {
60534+ p = current->real_parent->role->rolename;
60535+ i = current->real_parent->acl_role_id;
60536+ }
60537+ read_unlock(&tasklist_lock);
60538+
60539+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
60540+ gr_set_acls(1);
60541+ } else {
60542+ error = -EPERM;
60543+ goto out;
60544+ }
60545+ break;
60546+ default:
60547+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
60548+ error = -EINVAL;
60549+ break;
60550+ }
60551+
60552+ if (error != -EPERM)
60553+ goto out;
60554+
60555+ if(!(gr_auth_attempts++))
60556+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60557+
60558+ out:
60559+ mutex_unlock(&gr_dev_mutex);
60560+ return error;
60561+}
60562+
60563+/* must be called with
60564+ rcu_read_lock();
60565+ read_lock(&tasklist_lock);
60566+ read_lock(&grsec_exec_file_lock);
60567+*/
60568+int gr_apply_subject_to_task(struct task_struct *task)
60569+{
60570+ struct acl_object_label *obj;
60571+ char *tmpname;
60572+ struct acl_subject_label *tmpsubj;
60573+ struct file *filp;
60574+ struct name_entry *nmatch;
60575+
60576+ filp = task->exec_file;
60577+ if (filp == NULL)
60578+ return 0;
60579+
60580+ /* the following is to apply the correct subject
60581+ on binaries running when the RBAC system
60582+ is enabled, when the binaries have been
60583+ replaced or deleted since their execution
60584+ -----
60585+ when the RBAC system starts, the inode/dev
60586+ from exec_file will be one the RBAC system
60587+ is unaware of. It only knows the inode/dev
60588+ of the present file on disk, or the absence
60589+ of it.
60590+ */
60591+ preempt_disable();
60592+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
60593+
60594+ nmatch = lookup_name_entry(tmpname);
60595+ preempt_enable();
60596+ tmpsubj = NULL;
60597+ if (nmatch) {
60598+ if (nmatch->deleted)
60599+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
60600+ else
60601+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
60602+ if (tmpsubj != NULL)
60603+ task->acl = tmpsubj;
60604+ }
60605+ if (tmpsubj == NULL)
60606+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
60607+ task->role);
60608+ if (task->acl) {
60609+ task->is_writable = 0;
60610+ /* ignore additional mmap checks for processes that are writable
60611+ by the default ACL */
60612+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60613+ if (unlikely(obj->mode & GR_WRITE))
60614+ task->is_writable = 1;
60615+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60616+ if (unlikely(obj->mode & GR_WRITE))
60617+ task->is_writable = 1;
60618+
60619+ gr_set_proc_res(task);
60620+
60621+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60622+ 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);
60623+#endif
60624+ } else {
60625+ return 1;
60626+ }
60627+
60628+ return 0;
60629+}
60630+
60631+int
60632+gr_set_acls(const int type)
60633+{
60634+ struct task_struct *task, *task2;
60635+ struct acl_role_label *role = current->role;
60636+ __u16 acl_role_id = current->acl_role_id;
60637+ const struct cred *cred;
60638+ int ret;
60639+
60640+ rcu_read_lock();
60641+ read_lock(&tasklist_lock);
60642+ read_lock(&grsec_exec_file_lock);
60643+ do_each_thread(task2, task) {
60644+ /* check to see if we're called from the exit handler,
60645+ if so, only replace ACLs that have inherited the admin
60646+ ACL */
60647+
60648+ if (type && (task->role != role ||
60649+ task->acl_role_id != acl_role_id))
60650+ continue;
60651+
60652+ task->acl_role_id = 0;
60653+ task->acl_sp_role = 0;
60654+
60655+ if (task->exec_file) {
60656+ cred = __task_cred(task);
60657+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
60658+ ret = gr_apply_subject_to_task(task);
60659+ if (ret) {
60660+ read_unlock(&grsec_exec_file_lock);
60661+ read_unlock(&tasklist_lock);
60662+ rcu_read_unlock();
60663+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
60664+ return ret;
60665+ }
60666+ } else {
60667+ // it's a kernel process
60668+ task->role = kernel_role;
60669+ task->acl = kernel_role->root_label;
60670+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
60671+ task->acl->mode &= ~GR_PROCFIND;
60672+#endif
60673+ }
60674+ } while_each_thread(task2, task);
60675+ read_unlock(&grsec_exec_file_lock);
60676+ read_unlock(&tasklist_lock);
60677+ rcu_read_unlock();
60678+
60679+ return 0;
60680+}
60681+
60682+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
60683+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
60684+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
60685+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
60686+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
60687+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
60688+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
60689+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
60690+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
60691+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
60692+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
60693+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
60694+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
60695+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
60696+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
60697+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
60698+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
60699+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
60700+};
60701+
60702+void
60703+gr_learn_resource(const struct task_struct *task,
60704+ const int res, const unsigned long wanted, const int gt)
60705+{
60706+ struct acl_subject_label *acl;
60707+ const struct cred *cred;
60708+
60709+ if (unlikely((gr_status & GR_READY) &&
60710+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
60711+ goto skip_reslog;
60712+
60713+ gr_log_resource(task, res, wanted, gt);
60714+skip_reslog:
60715+
60716+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
60717+ return;
60718+
60719+ acl = task->acl;
60720+
60721+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
60722+ !(acl->resmask & (1 << (unsigned short) res))))
60723+ return;
60724+
60725+ if (wanted >= acl->res[res].rlim_cur) {
60726+ unsigned long res_add;
60727+
60728+ res_add = wanted + res_learn_bumps[res];
60729+
60730+ acl->res[res].rlim_cur = res_add;
60731+
60732+ if (wanted > acl->res[res].rlim_max)
60733+ acl->res[res].rlim_max = res_add;
60734+
60735+ /* only log the subject filename, since resource logging is supported for
60736+ single-subject learning only */
60737+ rcu_read_lock();
60738+ cred = __task_cred(task);
60739+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60740+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
60741+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
60742+ "", (unsigned long) res, &task->signal->saved_ip);
60743+ rcu_read_unlock();
60744+ }
60745+
60746+ return;
60747+}
60748+EXPORT_SYMBOL(gr_learn_resource);
60749+#endif
60750+
60751+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
60752+void
60753+pax_set_initial_flags(struct linux_binprm *bprm)
60754+{
60755+ struct task_struct *task = current;
60756+ struct acl_subject_label *proc;
60757+ unsigned long flags;
60758+
60759+ if (unlikely(!(gr_status & GR_READY)))
60760+ return;
60761+
60762+ flags = pax_get_flags(task);
60763+
60764+ proc = task->acl;
60765+
60766+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
60767+ flags &= ~MF_PAX_PAGEEXEC;
60768+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
60769+ flags &= ~MF_PAX_SEGMEXEC;
60770+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
60771+ flags &= ~MF_PAX_RANDMMAP;
60772+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
60773+ flags &= ~MF_PAX_EMUTRAMP;
60774+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
60775+ flags &= ~MF_PAX_MPROTECT;
60776+
60777+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
60778+ flags |= MF_PAX_PAGEEXEC;
60779+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
60780+ flags |= MF_PAX_SEGMEXEC;
60781+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
60782+ flags |= MF_PAX_RANDMMAP;
60783+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
60784+ flags |= MF_PAX_EMUTRAMP;
60785+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
60786+ flags |= MF_PAX_MPROTECT;
60787+
60788+ pax_set_flags(task, flags);
60789+
60790+ return;
60791+}
60792+#endif
60793+
60794+int
60795+gr_handle_proc_ptrace(struct task_struct *task)
60796+{
60797+ struct file *filp;
60798+ struct task_struct *tmp = task;
60799+ struct task_struct *curtemp = current;
60800+ __u32 retmode;
60801+
60802+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60803+ if (unlikely(!(gr_status & GR_READY)))
60804+ return 0;
60805+#endif
60806+
60807+ read_lock(&tasklist_lock);
60808+ read_lock(&grsec_exec_file_lock);
60809+ filp = task->exec_file;
60810+
60811+ while (task_pid_nr(tmp) > 0) {
60812+ if (tmp == curtemp)
60813+ break;
60814+ tmp = tmp->real_parent;
60815+ }
60816+
60817+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60818+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
60819+ read_unlock(&grsec_exec_file_lock);
60820+ read_unlock(&tasklist_lock);
60821+ return 1;
60822+ }
60823+
60824+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60825+ if (!(gr_status & GR_READY)) {
60826+ read_unlock(&grsec_exec_file_lock);
60827+ read_unlock(&tasklist_lock);
60828+ return 0;
60829+ }
60830+#endif
60831+
60832+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
60833+ read_unlock(&grsec_exec_file_lock);
60834+ read_unlock(&tasklist_lock);
60835+
60836+ if (retmode & GR_NOPTRACE)
60837+ return 1;
60838+
60839+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
60840+ && (current->acl != task->acl || (current->acl != current->role->root_label
60841+ && task_pid_nr(current) != task_pid_nr(task))))
60842+ return 1;
60843+
60844+ return 0;
60845+}
60846+
60847+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
60848+{
60849+ if (unlikely(!(gr_status & GR_READY)))
60850+ return;
60851+
60852+ if (!(current->role->roletype & GR_ROLE_GOD))
60853+ return;
60854+
60855+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
60856+ p->role->rolename, gr_task_roletype_to_char(p),
60857+ p->acl->filename);
60858+}
60859+
60860+int
60861+gr_handle_ptrace(struct task_struct *task, const long request)
60862+{
60863+ struct task_struct *tmp = task;
60864+ struct task_struct *curtemp = current;
60865+ __u32 retmode;
60866+
60867+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60868+ if (unlikely(!(gr_status & GR_READY)))
60869+ return 0;
60870+#endif
60871+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
60872+ read_lock(&tasklist_lock);
60873+ while (task_pid_nr(tmp) > 0) {
60874+ if (tmp == curtemp)
60875+ break;
60876+ tmp = tmp->real_parent;
60877+ }
60878+
60879+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60880+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
60881+ read_unlock(&tasklist_lock);
60882+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60883+ return 1;
60884+ }
60885+ read_unlock(&tasklist_lock);
60886+ }
60887+
60888+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60889+ if (!(gr_status & GR_READY))
60890+ return 0;
60891+#endif
60892+
60893+ read_lock(&grsec_exec_file_lock);
60894+ if (unlikely(!task->exec_file)) {
60895+ read_unlock(&grsec_exec_file_lock);
60896+ return 0;
60897+ }
60898+
60899+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
60900+ read_unlock(&grsec_exec_file_lock);
60901+
60902+ if (retmode & GR_NOPTRACE) {
60903+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60904+ return 1;
60905+ }
60906+
60907+ if (retmode & GR_PTRACERD) {
60908+ switch (request) {
60909+ case PTRACE_SEIZE:
60910+ case PTRACE_POKETEXT:
60911+ case PTRACE_POKEDATA:
60912+ case PTRACE_POKEUSR:
60913+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
60914+ case PTRACE_SETREGS:
60915+ case PTRACE_SETFPREGS:
60916+#endif
60917+#ifdef CONFIG_X86
60918+ case PTRACE_SETFPXREGS:
60919+#endif
60920+#ifdef CONFIG_ALTIVEC
60921+ case PTRACE_SETVRREGS:
60922+#endif
60923+ return 1;
60924+ default:
60925+ return 0;
60926+ }
60927+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
60928+ !(current->role->roletype & GR_ROLE_GOD) &&
60929+ (current->acl != task->acl)) {
60930+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60931+ return 1;
60932+ }
60933+
60934+ return 0;
60935+}
60936+
60937+static int is_writable_mmap(const struct file *filp)
60938+{
60939+ struct task_struct *task = current;
60940+ struct acl_object_label *obj, *obj2;
60941+
60942+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
60943+ !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))) {
60944+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60945+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
60946+ task->role->root_label);
60947+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
60948+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
60949+ return 1;
60950+ }
60951+ }
60952+ return 0;
60953+}
60954+
60955+int
60956+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
60957+{
60958+ __u32 mode;
60959+
60960+ if (unlikely(!file || !(prot & PROT_EXEC)))
60961+ return 1;
60962+
60963+ if (is_writable_mmap(file))
60964+ return 0;
60965+
60966+ mode =
60967+ gr_search_file(file->f_path.dentry,
60968+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60969+ file->f_path.mnt);
60970+
60971+ if (!gr_tpe_allow(file))
60972+ return 0;
60973+
60974+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60975+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60976+ return 0;
60977+ } else if (unlikely(!(mode & GR_EXEC))) {
60978+ return 0;
60979+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60980+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60981+ return 1;
60982+ }
60983+
60984+ return 1;
60985+}
60986+
60987+int
60988+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60989+{
60990+ __u32 mode;
60991+
60992+ if (unlikely(!file || !(prot & PROT_EXEC)))
60993+ return 1;
60994+
60995+ if (is_writable_mmap(file))
60996+ return 0;
60997+
60998+ mode =
60999+ gr_search_file(file->f_path.dentry,
61000+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61001+ file->f_path.mnt);
61002+
61003+ if (!gr_tpe_allow(file))
61004+ return 0;
61005+
61006+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61007+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61008+ return 0;
61009+ } else if (unlikely(!(mode & GR_EXEC))) {
61010+ return 0;
61011+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61012+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61013+ return 1;
61014+ }
61015+
61016+ return 1;
61017+}
61018+
61019+void
61020+gr_acl_handle_psacct(struct task_struct *task, const long code)
61021+{
61022+ unsigned long runtime;
61023+ unsigned long cputime;
61024+ unsigned int wday, cday;
61025+ __u8 whr, chr;
61026+ __u8 wmin, cmin;
61027+ __u8 wsec, csec;
61028+ struct timespec timeval;
61029+
61030+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
61031+ !(task->acl->mode & GR_PROCACCT)))
61032+ return;
61033+
61034+ do_posix_clock_monotonic_gettime(&timeval);
61035+ runtime = timeval.tv_sec - task->start_time.tv_sec;
61036+ wday = runtime / (3600 * 24);
61037+ runtime -= wday * (3600 * 24);
61038+ whr = runtime / 3600;
61039+ runtime -= whr * 3600;
61040+ wmin = runtime / 60;
61041+ runtime -= wmin * 60;
61042+ wsec = runtime;
61043+
61044+ cputime = (task->utime + task->stime) / HZ;
61045+ cday = cputime / (3600 * 24);
61046+ cputime -= cday * (3600 * 24);
61047+ chr = cputime / 3600;
61048+ cputime -= chr * 3600;
61049+ cmin = cputime / 60;
61050+ cputime -= cmin * 60;
61051+ csec = cputime;
61052+
61053+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
61054+
61055+ return;
61056+}
61057+
61058+void gr_set_kernel_label(struct task_struct *task)
61059+{
61060+ if (gr_status & GR_READY) {
61061+ task->role = kernel_role;
61062+ task->acl = kernel_role->root_label;
61063+ }
61064+ return;
61065+}
61066+
61067+#ifdef CONFIG_TASKSTATS
61068+int gr_is_taskstats_denied(int pid)
61069+{
61070+ struct task_struct *task;
61071+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61072+ const struct cred *cred;
61073+#endif
61074+ int ret = 0;
61075+
61076+ /* restrict taskstats viewing to un-chrooted root users
61077+ who have the 'view' subject flag if the RBAC system is enabled
61078+ */
61079+
61080+ rcu_read_lock();
61081+ read_lock(&tasklist_lock);
61082+ task = find_task_by_vpid(pid);
61083+ if (task) {
61084+#ifdef CONFIG_GRKERNSEC_CHROOT
61085+ if (proc_is_chrooted(task))
61086+ ret = -EACCES;
61087+#endif
61088+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61089+ cred = __task_cred(task);
61090+#ifdef CONFIG_GRKERNSEC_PROC_USER
61091+ if (gr_is_global_nonroot(cred->uid))
61092+ ret = -EACCES;
61093+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61094+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
61095+ ret = -EACCES;
61096+#endif
61097+#endif
61098+ if (gr_status & GR_READY) {
61099+ if (!(task->acl->mode & GR_VIEW))
61100+ ret = -EACCES;
61101+ }
61102+ } else
61103+ ret = -ENOENT;
61104+
61105+ read_unlock(&tasklist_lock);
61106+ rcu_read_unlock();
61107+
61108+ return ret;
61109+}
61110+#endif
61111+
61112+/* AUXV entries are filled via a descendant of search_binary_handler
61113+ after we've already applied the subject for the target
61114+*/
61115+int gr_acl_enable_at_secure(void)
61116+{
61117+ if (unlikely(!(gr_status & GR_READY)))
61118+ return 0;
61119+
61120+ if (current->acl->mode & GR_ATSECURE)
61121+ return 1;
61122+
61123+ return 0;
61124+}
61125+
61126+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
61127+{
61128+ struct task_struct *task = current;
61129+ struct dentry *dentry = file->f_path.dentry;
61130+ struct vfsmount *mnt = file->f_path.mnt;
61131+ struct acl_object_label *obj, *tmp;
61132+ struct acl_subject_label *subj;
61133+ unsigned int bufsize;
61134+ int is_not_root;
61135+ char *path;
61136+ dev_t dev = __get_dev(dentry);
61137+
61138+ if (unlikely(!(gr_status & GR_READY)))
61139+ return 1;
61140+
61141+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
61142+ return 1;
61143+
61144+ /* ignore Eric Biederman */
61145+ if (IS_PRIVATE(dentry->d_inode))
61146+ return 1;
61147+
61148+ subj = task->acl;
61149+ read_lock(&gr_inode_lock);
61150+ do {
61151+ obj = lookup_acl_obj_label(ino, dev, subj);
61152+ if (obj != NULL) {
61153+ read_unlock(&gr_inode_lock);
61154+ return (obj->mode & GR_FIND) ? 1 : 0;
61155+ }
61156+ } while ((subj = subj->parent_subject));
61157+ read_unlock(&gr_inode_lock);
61158+
61159+ /* this is purely an optimization since we're looking for an object
61160+ for the directory we're doing a readdir on
61161+ if it's possible for any globbed object to match the entry we're
61162+ filling into the directory, then the object we find here will be
61163+ an anchor point with attached globbed objects
61164+ */
61165+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
61166+ if (obj->globbed == NULL)
61167+ return (obj->mode & GR_FIND) ? 1 : 0;
61168+
61169+ is_not_root = ((obj->filename[0] == '/') &&
61170+ (obj->filename[1] == '\0')) ? 0 : 1;
61171+ bufsize = PAGE_SIZE - namelen - is_not_root;
61172+
61173+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
61174+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
61175+ return 1;
61176+
61177+ preempt_disable();
61178+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
61179+ bufsize);
61180+
61181+ bufsize = strlen(path);
61182+
61183+ /* if base is "/", don't append an additional slash */
61184+ if (is_not_root)
61185+ *(path + bufsize) = '/';
61186+ memcpy(path + bufsize + is_not_root, name, namelen);
61187+ *(path + bufsize + namelen + is_not_root) = '\0';
61188+
61189+ tmp = obj->globbed;
61190+ while (tmp) {
61191+ if (!glob_match(tmp->filename, path)) {
61192+ preempt_enable();
61193+ return (tmp->mode & GR_FIND) ? 1 : 0;
61194+ }
61195+ tmp = tmp->next;
61196+ }
61197+ preempt_enable();
61198+ return (obj->mode & GR_FIND) ? 1 : 0;
61199+}
61200+
61201+void gr_put_exec_file(struct task_struct *task)
61202+{
61203+ struct file *filp;
61204+
61205+ write_lock(&grsec_exec_file_lock);
61206+ filp = task->exec_file;
61207+ task->exec_file = NULL;
61208+ write_unlock(&grsec_exec_file_lock);
61209+
61210+ if (filp)
61211+ fput(filp);
61212+
61213+ return;
61214+}
61215+
61216+
61217+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
61218+EXPORT_SYMBOL(gr_acl_is_enabled);
61219+#endif
61220+EXPORT_SYMBOL(gr_set_kernel_label);
61221+#ifdef CONFIG_SECURITY
61222+EXPORT_SYMBOL(gr_check_user_change);
61223+EXPORT_SYMBOL(gr_check_group_change);
61224+#endif
61225+
61226diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
61227new file mode 100644
61228index 0000000..34fefda
61229--- /dev/null
61230+++ b/grsecurity/gracl_alloc.c
61231@@ -0,0 +1,105 @@
61232+#include <linux/kernel.h>
61233+#include <linux/mm.h>
61234+#include <linux/slab.h>
61235+#include <linux/vmalloc.h>
61236+#include <linux/gracl.h>
61237+#include <linux/grsecurity.h>
61238+
61239+static unsigned long alloc_stack_next = 1;
61240+static unsigned long alloc_stack_size = 1;
61241+static void **alloc_stack;
61242+
61243+static __inline__ int
61244+alloc_pop(void)
61245+{
61246+ if (alloc_stack_next == 1)
61247+ return 0;
61248+
61249+ kfree(alloc_stack[alloc_stack_next - 2]);
61250+
61251+ alloc_stack_next--;
61252+
61253+ return 1;
61254+}
61255+
61256+static __inline__ int
61257+alloc_push(void *buf)
61258+{
61259+ if (alloc_stack_next >= alloc_stack_size)
61260+ return 1;
61261+
61262+ alloc_stack[alloc_stack_next - 1] = buf;
61263+
61264+ alloc_stack_next++;
61265+
61266+ return 0;
61267+}
61268+
61269+void *
61270+acl_alloc(unsigned long len)
61271+{
61272+ void *ret = NULL;
61273+
61274+ if (!len || len > PAGE_SIZE)
61275+ goto out;
61276+
61277+ ret = kmalloc(len, GFP_KERNEL);
61278+
61279+ if (ret) {
61280+ if (alloc_push(ret)) {
61281+ kfree(ret);
61282+ ret = NULL;
61283+ }
61284+ }
61285+
61286+out:
61287+ return ret;
61288+}
61289+
61290+void *
61291+acl_alloc_num(unsigned long num, unsigned long len)
61292+{
61293+ if (!len || (num > (PAGE_SIZE / len)))
61294+ return NULL;
61295+
61296+ return acl_alloc(num * len);
61297+}
61298+
61299+void
61300+acl_free_all(void)
61301+{
61302+ if (gr_acl_is_enabled() || !alloc_stack)
61303+ return;
61304+
61305+ while (alloc_pop()) ;
61306+
61307+ if (alloc_stack) {
61308+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
61309+ kfree(alloc_stack);
61310+ else
61311+ vfree(alloc_stack);
61312+ }
61313+
61314+ alloc_stack = NULL;
61315+ alloc_stack_size = 1;
61316+ alloc_stack_next = 1;
61317+
61318+ return;
61319+}
61320+
61321+int
61322+acl_alloc_stack_init(unsigned long size)
61323+{
61324+ if ((size * sizeof (void *)) <= PAGE_SIZE)
61325+ alloc_stack =
61326+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
61327+ else
61328+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
61329+
61330+ alloc_stack_size = size;
61331+
61332+ if (!alloc_stack)
61333+ return 0;
61334+ else
61335+ return 1;
61336+}
61337diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
61338new file mode 100644
61339index 0000000..bdd51ea
61340--- /dev/null
61341+++ b/grsecurity/gracl_cap.c
61342@@ -0,0 +1,110 @@
61343+#include <linux/kernel.h>
61344+#include <linux/module.h>
61345+#include <linux/sched.h>
61346+#include <linux/gracl.h>
61347+#include <linux/grsecurity.h>
61348+#include <linux/grinternal.h>
61349+
61350+extern const char *captab_log[];
61351+extern int captab_log_entries;
61352+
61353+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61354+{
61355+ struct acl_subject_label *curracl;
61356+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61357+ kernel_cap_t cap_audit = __cap_empty_set;
61358+
61359+ if (!gr_acl_is_enabled())
61360+ return 1;
61361+
61362+ curracl = task->acl;
61363+
61364+ cap_drop = curracl->cap_lower;
61365+ cap_mask = curracl->cap_mask;
61366+ cap_audit = curracl->cap_invert_audit;
61367+
61368+ while ((curracl = curracl->parent_subject)) {
61369+ /* if the cap isn't specified in the current computed mask but is specified in the
61370+ current level subject, and is lowered in the current level subject, then add
61371+ it to the set of dropped capabilities
61372+ otherwise, add the current level subject's mask to the current computed mask
61373+ */
61374+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61375+ cap_raise(cap_mask, cap);
61376+ if (cap_raised(curracl->cap_lower, cap))
61377+ cap_raise(cap_drop, cap);
61378+ if (cap_raised(curracl->cap_invert_audit, cap))
61379+ cap_raise(cap_audit, cap);
61380+ }
61381+ }
61382+
61383+ if (!cap_raised(cap_drop, cap)) {
61384+ if (cap_raised(cap_audit, cap))
61385+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
61386+ return 1;
61387+ }
61388+
61389+ curracl = task->acl;
61390+
61391+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
61392+ && cap_raised(cred->cap_effective, cap)) {
61393+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61394+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
61395+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
61396+ gr_to_filename(task->exec_file->f_path.dentry,
61397+ task->exec_file->f_path.mnt) : curracl->filename,
61398+ curracl->filename, 0UL,
61399+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
61400+ return 1;
61401+ }
61402+
61403+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
61404+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
61405+
61406+ return 0;
61407+}
61408+
61409+int
61410+gr_acl_is_capable(const int cap)
61411+{
61412+ return gr_task_acl_is_capable(current, current_cred(), cap);
61413+}
61414+
61415+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
61416+{
61417+ struct acl_subject_label *curracl;
61418+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61419+
61420+ if (!gr_acl_is_enabled())
61421+ return 1;
61422+
61423+ curracl = task->acl;
61424+
61425+ cap_drop = curracl->cap_lower;
61426+ cap_mask = curracl->cap_mask;
61427+
61428+ while ((curracl = curracl->parent_subject)) {
61429+ /* if the cap isn't specified in the current computed mask but is specified in the
61430+ current level subject, and is lowered in the current level subject, then add
61431+ it to the set of dropped capabilities
61432+ otherwise, add the current level subject's mask to the current computed mask
61433+ */
61434+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61435+ cap_raise(cap_mask, cap);
61436+ if (cap_raised(curracl->cap_lower, cap))
61437+ cap_raise(cap_drop, cap);
61438+ }
61439+ }
61440+
61441+ if (!cap_raised(cap_drop, cap))
61442+ return 1;
61443+
61444+ return 0;
61445+}
61446+
61447+int
61448+gr_acl_is_capable_nolog(const int cap)
61449+{
61450+ return gr_task_acl_is_capable_nolog(current, cap);
61451+}
61452+
61453diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
61454new file mode 100644
61455index 0000000..a340c17
61456--- /dev/null
61457+++ b/grsecurity/gracl_fs.c
61458@@ -0,0 +1,431 @@
61459+#include <linux/kernel.h>
61460+#include <linux/sched.h>
61461+#include <linux/types.h>
61462+#include <linux/fs.h>
61463+#include <linux/file.h>
61464+#include <linux/stat.h>
61465+#include <linux/grsecurity.h>
61466+#include <linux/grinternal.h>
61467+#include <linux/gracl.h>
61468+
61469+umode_t
61470+gr_acl_umask(void)
61471+{
61472+ if (unlikely(!gr_acl_is_enabled()))
61473+ return 0;
61474+
61475+ return current->role->umask;
61476+}
61477+
61478+__u32
61479+gr_acl_handle_hidden_file(const struct dentry * dentry,
61480+ const struct vfsmount * mnt)
61481+{
61482+ __u32 mode;
61483+
61484+ if (unlikely(!dentry->d_inode))
61485+ return GR_FIND;
61486+
61487+ mode =
61488+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
61489+
61490+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
61491+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61492+ return mode;
61493+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
61494+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61495+ return 0;
61496+ } else if (unlikely(!(mode & GR_FIND)))
61497+ return 0;
61498+
61499+ return GR_FIND;
61500+}
61501+
61502+__u32
61503+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61504+ int acc_mode)
61505+{
61506+ __u32 reqmode = GR_FIND;
61507+ __u32 mode;
61508+
61509+ if (unlikely(!dentry->d_inode))
61510+ return reqmode;
61511+
61512+ if (acc_mode & MAY_APPEND)
61513+ reqmode |= GR_APPEND;
61514+ else if (acc_mode & MAY_WRITE)
61515+ reqmode |= GR_WRITE;
61516+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
61517+ reqmode |= GR_READ;
61518+
61519+ mode =
61520+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61521+ mnt);
61522+
61523+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61524+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61525+ reqmode & GR_READ ? " reading" : "",
61526+ reqmode & GR_WRITE ? " writing" : reqmode &
61527+ GR_APPEND ? " appending" : "");
61528+ return reqmode;
61529+ } else
61530+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61531+ {
61532+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61533+ reqmode & GR_READ ? " reading" : "",
61534+ reqmode & GR_WRITE ? " writing" : reqmode &
61535+ GR_APPEND ? " appending" : "");
61536+ return 0;
61537+ } else if (unlikely((mode & reqmode) != reqmode))
61538+ return 0;
61539+
61540+ return reqmode;
61541+}
61542+
61543+__u32
61544+gr_acl_handle_creat(const struct dentry * dentry,
61545+ const struct dentry * p_dentry,
61546+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61547+ const int imode)
61548+{
61549+ __u32 reqmode = GR_WRITE | GR_CREATE;
61550+ __u32 mode;
61551+
61552+ if (acc_mode & MAY_APPEND)
61553+ reqmode |= GR_APPEND;
61554+ // if a directory was required or the directory already exists, then
61555+ // don't count this open as a read
61556+ if ((acc_mode & MAY_READ) &&
61557+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
61558+ reqmode |= GR_READ;
61559+ if ((open_flags & O_CREAT) &&
61560+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61561+ reqmode |= GR_SETID;
61562+
61563+ mode =
61564+ gr_check_create(dentry, p_dentry, p_mnt,
61565+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61566+
61567+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61568+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61569+ reqmode & GR_READ ? " reading" : "",
61570+ reqmode & GR_WRITE ? " writing" : reqmode &
61571+ GR_APPEND ? " appending" : "");
61572+ return reqmode;
61573+ } else
61574+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61575+ {
61576+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61577+ reqmode & GR_READ ? " reading" : "",
61578+ reqmode & GR_WRITE ? " writing" : reqmode &
61579+ GR_APPEND ? " appending" : "");
61580+ return 0;
61581+ } else if (unlikely((mode & reqmode) != reqmode))
61582+ return 0;
61583+
61584+ return reqmode;
61585+}
61586+
61587+__u32
61588+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
61589+ const int fmode)
61590+{
61591+ __u32 mode, reqmode = GR_FIND;
61592+
61593+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
61594+ reqmode |= GR_EXEC;
61595+ if (fmode & S_IWOTH)
61596+ reqmode |= GR_WRITE;
61597+ if (fmode & S_IROTH)
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_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61606+ reqmode & GR_READ ? " reading" : "",
61607+ reqmode & GR_WRITE ? " writing" : "",
61608+ reqmode & GR_EXEC ? " executing" : "");
61609+ return reqmode;
61610+ } else
61611+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61612+ {
61613+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61614+ reqmode & GR_READ ? " reading" : "",
61615+ reqmode & GR_WRITE ? " writing" : "",
61616+ reqmode & GR_EXEC ? " executing" : "");
61617+ return 0;
61618+ } else if (unlikely((mode & reqmode) != reqmode))
61619+ return 0;
61620+
61621+ return reqmode;
61622+}
61623+
61624+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
61625+{
61626+ __u32 mode;
61627+
61628+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
61629+
61630+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61631+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
61632+ return mode;
61633+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61634+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
61635+ return 0;
61636+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61637+ return 0;
61638+
61639+ return (reqmode);
61640+}
61641+
61642+__u32
61643+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61644+{
61645+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
61646+}
61647+
61648+__u32
61649+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
61650+{
61651+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
61652+}
61653+
61654+__u32
61655+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
61656+{
61657+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
61658+}
61659+
61660+__u32
61661+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
61662+{
61663+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
61664+}
61665+
61666+__u32
61667+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
61668+ umode_t *modeptr)
61669+{
61670+ umode_t mode;
61671+
61672+ *modeptr &= ~gr_acl_umask();
61673+ mode = *modeptr;
61674+
61675+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
61676+ return 1;
61677+
61678+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
61679+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
61680+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
61681+ GR_CHMOD_ACL_MSG);
61682+ } else {
61683+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
61684+ }
61685+}
61686+
61687+__u32
61688+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
61689+{
61690+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
61691+}
61692+
61693+__u32
61694+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
61695+{
61696+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
61697+}
61698+
61699+__u32
61700+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
61701+{
61702+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
61703+}
61704+
61705+__u32
61706+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
61707+{
61708+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
61709+ GR_UNIXCONNECT_ACL_MSG);
61710+}
61711+
61712+/* hardlinks require at minimum create and link permission,
61713+ any additional privilege required is based on the
61714+ privilege of the file being linked to
61715+*/
61716+__u32
61717+gr_acl_handle_link(const struct dentry * new_dentry,
61718+ const struct dentry * parent_dentry,
61719+ const struct vfsmount * parent_mnt,
61720+ const struct dentry * old_dentry,
61721+ const struct vfsmount * old_mnt, const struct filename *to)
61722+{
61723+ __u32 mode;
61724+ __u32 needmode = GR_CREATE | GR_LINK;
61725+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
61726+
61727+ mode =
61728+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
61729+ old_mnt);
61730+
61731+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
61732+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61733+ return mode;
61734+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61735+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61736+ return 0;
61737+ } else if (unlikely((mode & needmode) != needmode))
61738+ return 0;
61739+
61740+ return 1;
61741+}
61742+
61743+__u32
61744+gr_acl_handle_symlink(const struct dentry * new_dentry,
61745+ const struct dentry * parent_dentry,
61746+ const struct vfsmount * parent_mnt, const struct filename *from)
61747+{
61748+ __u32 needmode = GR_WRITE | GR_CREATE;
61749+ __u32 mode;
61750+
61751+ mode =
61752+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
61753+ GR_CREATE | GR_AUDIT_CREATE |
61754+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
61755+
61756+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
61757+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61758+ return mode;
61759+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61760+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61761+ return 0;
61762+ } else if (unlikely((mode & needmode) != needmode))
61763+ return 0;
61764+
61765+ return (GR_WRITE | GR_CREATE);
61766+}
61767+
61768+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)
61769+{
61770+ __u32 mode;
61771+
61772+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61773+
61774+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61775+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
61776+ return mode;
61777+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61778+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
61779+ return 0;
61780+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61781+ return 0;
61782+
61783+ return (reqmode);
61784+}
61785+
61786+__u32
61787+gr_acl_handle_mknod(const struct dentry * new_dentry,
61788+ const struct dentry * parent_dentry,
61789+ const struct vfsmount * parent_mnt,
61790+ const int mode)
61791+{
61792+ __u32 reqmode = GR_WRITE | GR_CREATE;
61793+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61794+ reqmode |= GR_SETID;
61795+
61796+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61797+ reqmode, GR_MKNOD_ACL_MSG);
61798+}
61799+
61800+__u32
61801+gr_acl_handle_mkdir(const struct dentry *new_dentry,
61802+ const struct dentry *parent_dentry,
61803+ const struct vfsmount *parent_mnt)
61804+{
61805+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61806+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
61807+}
61808+
61809+#define RENAME_CHECK_SUCCESS(old, new) \
61810+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
61811+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
61812+
61813+int
61814+gr_acl_handle_rename(struct dentry *new_dentry,
61815+ struct dentry *parent_dentry,
61816+ const struct vfsmount *parent_mnt,
61817+ struct dentry *old_dentry,
61818+ struct inode *old_parent_inode,
61819+ struct vfsmount *old_mnt, const struct filename *newname)
61820+{
61821+ __u32 comp1, comp2;
61822+ int error = 0;
61823+
61824+ if (unlikely(!gr_acl_is_enabled()))
61825+ return 0;
61826+
61827+ if (!new_dentry->d_inode) {
61828+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
61829+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
61830+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
61831+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
61832+ GR_DELETE | GR_AUDIT_DELETE |
61833+ GR_AUDIT_READ | GR_AUDIT_WRITE |
61834+ GR_SUPPRESS, old_mnt);
61835+ } else {
61836+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
61837+ GR_CREATE | GR_DELETE |
61838+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
61839+ GR_AUDIT_READ | GR_AUDIT_WRITE |
61840+ GR_SUPPRESS, parent_mnt);
61841+ comp2 =
61842+ gr_search_file(old_dentry,
61843+ GR_READ | GR_WRITE | GR_AUDIT_READ |
61844+ GR_DELETE | GR_AUDIT_DELETE |
61845+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
61846+ }
61847+
61848+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
61849+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
61850+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61851+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
61852+ && !(comp2 & GR_SUPPRESS)) {
61853+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61854+ error = -EACCES;
61855+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
61856+ error = -EACCES;
61857+
61858+ return error;
61859+}
61860+
61861+void
61862+gr_acl_handle_exit(void)
61863+{
61864+ u16 id;
61865+ char *rolename;
61866+
61867+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
61868+ !(current->role->roletype & GR_ROLE_PERSIST))) {
61869+ id = current->acl_role_id;
61870+ rolename = current->role->rolename;
61871+ gr_set_acls(1);
61872+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
61873+ }
61874+
61875+ gr_put_exec_file(current);
61876+ return;
61877+}
61878+
61879+int
61880+gr_acl_handle_procpidmem(const struct task_struct *task)
61881+{
61882+ if (unlikely(!gr_acl_is_enabled()))
61883+ return 0;
61884+
61885+ if (task != current && task->acl->mode & GR_PROTPROCFD)
61886+ return -EACCES;
61887+
61888+ return 0;
61889+}
61890diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
61891new file mode 100644
61892index 0000000..4699807
61893--- /dev/null
61894+++ b/grsecurity/gracl_ip.c
61895@@ -0,0 +1,384 @@
61896+#include <linux/kernel.h>
61897+#include <asm/uaccess.h>
61898+#include <asm/errno.h>
61899+#include <net/sock.h>
61900+#include <linux/file.h>
61901+#include <linux/fs.h>
61902+#include <linux/net.h>
61903+#include <linux/in.h>
61904+#include <linux/skbuff.h>
61905+#include <linux/ip.h>
61906+#include <linux/udp.h>
61907+#include <linux/types.h>
61908+#include <linux/sched.h>
61909+#include <linux/netdevice.h>
61910+#include <linux/inetdevice.h>
61911+#include <linux/gracl.h>
61912+#include <linux/grsecurity.h>
61913+#include <linux/grinternal.h>
61914+
61915+#define GR_BIND 0x01
61916+#define GR_CONNECT 0x02
61917+#define GR_INVERT 0x04
61918+#define GR_BINDOVERRIDE 0x08
61919+#define GR_CONNECTOVERRIDE 0x10
61920+#define GR_SOCK_FAMILY 0x20
61921+
61922+static const char * gr_protocols[IPPROTO_MAX] = {
61923+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
61924+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
61925+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
61926+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
61927+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
61928+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
61929+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
61930+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
61931+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
61932+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
61933+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
61934+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
61935+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
61936+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
61937+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
61938+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
61939+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
61940+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
61941+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
61942+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
61943+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
61944+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
61945+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
61946+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
61947+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
61948+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
61949+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
61950+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
61951+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
61952+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
61953+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
61954+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
61955+ };
61956+
61957+static const char * gr_socktypes[SOCK_MAX] = {
61958+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
61959+ "unknown:7", "unknown:8", "unknown:9", "packet"
61960+ };
61961+
61962+static const char * gr_sockfamilies[AF_MAX+1] = {
61963+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
61964+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
61965+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
61966+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
61967+ };
61968+
61969+const char *
61970+gr_proto_to_name(unsigned char proto)
61971+{
61972+ return gr_protocols[proto];
61973+}
61974+
61975+const char *
61976+gr_socktype_to_name(unsigned char type)
61977+{
61978+ return gr_socktypes[type];
61979+}
61980+
61981+const char *
61982+gr_sockfamily_to_name(unsigned char family)
61983+{
61984+ return gr_sockfamilies[family];
61985+}
61986+
61987+int
61988+gr_search_socket(const int domain, const int type, const int protocol)
61989+{
61990+ struct acl_subject_label *curr;
61991+ const struct cred *cred = current_cred();
61992+
61993+ if (unlikely(!gr_acl_is_enabled()))
61994+ goto exit;
61995+
61996+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
61997+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
61998+ goto exit; // let the kernel handle it
61999+
62000+ curr = current->acl;
62001+
62002+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
62003+ /* the family is allowed, if this is PF_INET allow it only if
62004+ the extra sock type/protocol checks pass */
62005+ if (domain == PF_INET)
62006+ goto inet_check;
62007+ goto exit;
62008+ } else {
62009+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62010+ __u32 fakeip = 0;
62011+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62012+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62013+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62014+ gr_to_filename(current->exec_file->f_path.dentry,
62015+ current->exec_file->f_path.mnt) :
62016+ curr->filename, curr->filename,
62017+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
62018+ &current->signal->saved_ip);
62019+ goto exit;
62020+ }
62021+ goto exit_fail;
62022+ }
62023+
62024+inet_check:
62025+ /* the rest of this checking is for IPv4 only */
62026+ if (!curr->ips)
62027+ goto exit;
62028+
62029+ if ((curr->ip_type & (1 << type)) &&
62030+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
62031+ goto exit;
62032+
62033+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62034+ /* we don't place acls on raw sockets , and sometimes
62035+ dgram/ip sockets are opened for ioctl and not
62036+ bind/connect, so we'll fake a bind learn log */
62037+ if (type == SOCK_RAW || type == SOCK_PACKET) {
62038+ __u32 fakeip = 0;
62039+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62040+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62041+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62042+ gr_to_filename(current->exec_file->f_path.dentry,
62043+ current->exec_file->f_path.mnt) :
62044+ curr->filename, curr->filename,
62045+ &fakeip, 0, type,
62046+ protocol, GR_CONNECT, &current->signal->saved_ip);
62047+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
62048+ __u32 fakeip = 0;
62049+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62050+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62051+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62052+ gr_to_filename(current->exec_file->f_path.dentry,
62053+ current->exec_file->f_path.mnt) :
62054+ curr->filename, curr->filename,
62055+ &fakeip, 0, type,
62056+ protocol, GR_BIND, &current->signal->saved_ip);
62057+ }
62058+ /* we'll log when they use connect or bind */
62059+ goto exit;
62060+ }
62061+
62062+exit_fail:
62063+ if (domain == PF_INET)
62064+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
62065+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
62066+ else
62067+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
62068+ gr_socktype_to_name(type), protocol);
62069+
62070+ return 0;
62071+exit:
62072+ return 1;
62073+}
62074+
62075+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)
62076+{
62077+ if ((ip->mode & mode) &&
62078+ (ip_port >= ip->low) &&
62079+ (ip_port <= ip->high) &&
62080+ ((ntohl(ip_addr) & our_netmask) ==
62081+ (ntohl(our_addr) & our_netmask))
62082+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
62083+ && (ip->type & (1 << type))) {
62084+ if (ip->mode & GR_INVERT)
62085+ return 2; // specifically denied
62086+ else
62087+ return 1; // allowed
62088+ }
62089+
62090+ return 0; // not specifically allowed, may continue parsing
62091+}
62092+
62093+static int
62094+gr_search_connectbind(const int full_mode, struct sock *sk,
62095+ struct sockaddr_in *addr, const int type)
62096+{
62097+ char iface[IFNAMSIZ] = {0};
62098+ struct acl_subject_label *curr;
62099+ struct acl_ip_label *ip;
62100+ struct inet_sock *isk;
62101+ struct net_device *dev;
62102+ struct in_device *idev;
62103+ unsigned long i;
62104+ int ret;
62105+ int mode = full_mode & (GR_BIND | GR_CONNECT);
62106+ __u32 ip_addr = 0;
62107+ __u32 our_addr;
62108+ __u32 our_netmask;
62109+ char *p;
62110+ __u16 ip_port = 0;
62111+ const struct cred *cred = current_cred();
62112+
62113+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
62114+ return 0;
62115+
62116+ curr = current->acl;
62117+ isk = inet_sk(sk);
62118+
62119+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
62120+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
62121+ addr->sin_addr.s_addr = curr->inaddr_any_override;
62122+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
62123+ struct sockaddr_in saddr;
62124+ int err;
62125+
62126+ saddr.sin_family = AF_INET;
62127+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
62128+ saddr.sin_port = isk->inet_sport;
62129+
62130+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62131+ if (err)
62132+ return err;
62133+
62134+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62135+ if (err)
62136+ return err;
62137+ }
62138+
62139+ if (!curr->ips)
62140+ return 0;
62141+
62142+ ip_addr = addr->sin_addr.s_addr;
62143+ ip_port = ntohs(addr->sin_port);
62144+
62145+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62146+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62147+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62148+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62149+ gr_to_filename(current->exec_file->f_path.dentry,
62150+ current->exec_file->f_path.mnt) :
62151+ curr->filename, curr->filename,
62152+ &ip_addr, ip_port, type,
62153+ sk->sk_protocol, mode, &current->signal->saved_ip);
62154+ return 0;
62155+ }
62156+
62157+ for (i = 0; i < curr->ip_num; i++) {
62158+ ip = *(curr->ips + i);
62159+ if (ip->iface != NULL) {
62160+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
62161+ p = strchr(iface, ':');
62162+ if (p != NULL)
62163+ *p = '\0';
62164+ dev = dev_get_by_name(sock_net(sk), iface);
62165+ if (dev == NULL)
62166+ continue;
62167+ idev = in_dev_get(dev);
62168+ if (idev == NULL) {
62169+ dev_put(dev);
62170+ continue;
62171+ }
62172+ rcu_read_lock();
62173+ for_ifa(idev) {
62174+ if (!strcmp(ip->iface, ifa->ifa_label)) {
62175+ our_addr = ifa->ifa_address;
62176+ our_netmask = 0xffffffff;
62177+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62178+ if (ret == 1) {
62179+ rcu_read_unlock();
62180+ in_dev_put(idev);
62181+ dev_put(dev);
62182+ return 0;
62183+ } else if (ret == 2) {
62184+ rcu_read_unlock();
62185+ in_dev_put(idev);
62186+ dev_put(dev);
62187+ goto denied;
62188+ }
62189+ }
62190+ } endfor_ifa(idev);
62191+ rcu_read_unlock();
62192+ in_dev_put(idev);
62193+ dev_put(dev);
62194+ } else {
62195+ our_addr = ip->addr;
62196+ our_netmask = ip->netmask;
62197+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62198+ if (ret == 1)
62199+ return 0;
62200+ else if (ret == 2)
62201+ goto denied;
62202+ }
62203+ }
62204+
62205+denied:
62206+ if (mode == GR_BIND)
62207+ 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));
62208+ else if (mode == GR_CONNECT)
62209+ 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));
62210+
62211+ return -EACCES;
62212+}
62213+
62214+int
62215+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
62216+{
62217+ /* always allow disconnection of dgram sockets with connect */
62218+ if (addr->sin_family == AF_UNSPEC)
62219+ return 0;
62220+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
62221+}
62222+
62223+int
62224+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
62225+{
62226+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
62227+}
62228+
62229+int gr_search_listen(struct socket *sock)
62230+{
62231+ struct sock *sk = sock->sk;
62232+ struct sockaddr_in addr;
62233+
62234+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62235+ addr.sin_port = inet_sk(sk)->inet_sport;
62236+
62237+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62238+}
62239+
62240+int gr_search_accept(struct socket *sock)
62241+{
62242+ struct sock *sk = sock->sk;
62243+ struct sockaddr_in addr;
62244+
62245+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62246+ addr.sin_port = inet_sk(sk)->inet_sport;
62247+
62248+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62249+}
62250+
62251+int
62252+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
62253+{
62254+ if (addr)
62255+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
62256+ else {
62257+ struct sockaddr_in sin;
62258+ const struct inet_sock *inet = inet_sk(sk);
62259+
62260+ sin.sin_addr.s_addr = inet->inet_daddr;
62261+ sin.sin_port = inet->inet_dport;
62262+
62263+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62264+ }
62265+}
62266+
62267+int
62268+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
62269+{
62270+ struct sockaddr_in sin;
62271+
62272+ if (unlikely(skb->len < sizeof (struct udphdr)))
62273+ return 0; // skip this packet
62274+
62275+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
62276+ sin.sin_port = udp_hdr(skb)->source;
62277+
62278+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62279+}
62280diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
62281new file mode 100644
62282index 0000000..25f54ef
62283--- /dev/null
62284+++ b/grsecurity/gracl_learn.c
62285@@ -0,0 +1,207 @@
62286+#include <linux/kernel.h>
62287+#include <linux/mm.h>
62288+#include <linux/sched.h>
62289+#include <linux/poll.h>
62290+#include <linux/string.h>
62291+#include <linux/file.h>
62292+#include <linux/types.h>
62293+#include <linux/vmalloc.h>
62294+#include <linux/grinternal.h>
62295+
62296+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
62297+ size_t count, loff_t *ppos);
62298+extern int gr_acl_is_enabled(void);
62299+
62300+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
62301+static int gr_learn_attached;
62302+
62303+/* use a 512k buffer */
62304+#define LEARN_BUFFER_SIZE (512 * 1024)
62305+
62306+static DEFINE_SPINLOCK(gr_learn_lock);
62307+static DEFINE_MUTEX(gr_learn_user_mutex);
62308+
62309+/* we need to maintain two buffers, so that the kernel context of grlearn
62310+ uses a semaphore around the userspace copying, and the other kernel contexts
62311+ use a spinlock when copying into the buffer, since they cannot sleep
62312+*/
62313+static char *learn_buffer;
62314+static char *learn_buffer_user;
62315+static int learn_buffer_len;
62316+static int learn_buffer_user_len;
62317+
62318+static ssize_t
62319+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
62320+{
62321+ DECLARE_WAITQUEUE(wait, current);
62322+ ssize_t retval = 0;
62323+
62324+ add_wait_queue(&learn_wait, &wait);
62325+ set_current_state(TASK_INTERRUPTIBLE);
62326+ do {
62327+ mutex_lock(&gr_learn_user_mutex);
62328+ spin_lock(&gr_learn_lock);
62329+ if (learn_buffer_len)
62330+ break;
62331+ spin_unlock(&gr_learn_lock);
62332+ mutex_unlock(&gr_learn_user_mutex);
62333+ if (file->f_flags & O_NONBLOCK) {
62334+ retval = -EAGAIN;
62335+ goto out;
62336+ }
62337+ if (signal_pending(current)) {
62338+ retval = -ERESTARTSYS;
62339+ goto out;
62340+ }
62341+
62342+ schedule();
62343+ } while (1);
62344+
62345+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
62346+ learn_buffer_user_len = learn_buffer_len;
62347+ retval = learn_buffer_len;
62348+ learn_buffer_len = 0;
62349+
62350+ spin_unlock(&gr_learn_lock);
62351+
62352+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
62353+ retval = -EFAULT;
62354+
62355+ mutex_unlock(&gr_learn_user_mutex);
62356+out:
62357+ set_current_state(TASK_RUNNING);
62358+ remove_wait_queue(&learn_wait, &wait);
62359+ return retval;
62360+}
62361+
62362+static unsigned int
62363+poll_learn(struct file * file, poll_table * wait)
62364+{
62365+ poll_wait(file, &learn_wait, wait);
62366+
62367+ if (learn_buffer_len)
62368+ return (POLLIN | POLLRDNORM);
62369+
62370+ return 0;
62371+}
62372+
62373+void
62374+gr_clear_learn_entries(void)
62375+{
62376+ char *tmp;
62377+
62378+ mutex_lock(&gr_learn_user_mutex);
62379+ spin_lock(&gr_learn_lock);
62380+ tmp = learn_buffer;
62381+ learn_buffer = NULL;
62382+ spin_unlock(&gr_learn_lock);
62383+ if (tmp)
62384+ vfree(tmp);
62385+ if (learn_buffer_user != NULL) {
62386+ vfree(learn_buffer_user);
62387+ learn_buffer_user = NULL;
62388+ }
62389+ learn_buffer_len = 0;
62390+ mutex_unlock(&gr_learn_user_mutex);
62391+
62392+ return;
62393+}
62394+
62395+void
62396+gr_add_learn_entry(const char *fmt, ...)
62397+{
62398+ va_list args;
62399+ unsigned int len;
62400+
62401+ if (!gr_learn_attached)
62402+ return;
62403+
62404+ spin_lock(&gr_learn_lock);
62405+
62406+ /* leave a gap at the end so we know when it's "full" but don't have to
62407+ compute the exact length of the string we're trying to append
62408+ */
62409+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
62410+ spin_unlock(&gr_learn_lock);
62411+ wake_up_interruptible(&learn_wait);
62412+ return;
62413+ }
62414+ if (learn_buffer == NULL) {
62415+ spin_unlock(&gr_learn_lock);
62416+ return;
62417+ }
62418+
62419+ va_start(args, fmt);
62420+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
62421+ va_end(args);
62422+
62423+ learn_buffer_len += len + 1;
62424+
62425+ spin_unlock(&gr_learn_lock);
62426+ wake_up_interruptible(&learn_wait);
62427+
62428+ return;
62429+}
62430+
62431+static int
62432+open_learn(struct inode *inode, struct file *file)
62433+{
62434+ if (file->f_mode & FMODE_READ && gr_learn_attached)
62435+ return -EBUSY;
62436+ if (file->f_mode & FMODE_READ) {
62437+ int retval = 0;
62438+ mutex_lock(&gr_learn_user_mutex);
62439+ if (learn_buffer == NULL)
62440+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
62441+ if (learn_buffer_user == NULL)
62442+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
62443+ if (learn_buffer == NULL) {
62444+ retval = -ENOMEM;
62445+ goto out_error;
62446+ }
62447+ if (learn_buffer_user == NULL) {
62448+ retval = -ENOMEM;
62449+ goto out_error;
62450+ }
62451+ learn_buffer_len = 0;
62452+ learn_buffer_user_len = 0;
62453+ gr_learn_attached = 1;
62454+out_error:
62455+ mutex_unlock(&gr_learn_user_mutex);
62456+ return retval;
62457+ }
62458+ return 0;
62459+}
62460+
62461+static int
62462+close_learn(struct inode *inode, struct file *file)
62463+{
62464+ if (file->f_mode & FMODE_READ) {
62465+ char *tmp = NULL;
62466+ mutex_lock(&gr_learn_user_mutex);
62467+ spin_lock(&gr_learn_lock);
62468+ tmp = learn_buffer;
62469+ learn_buffer = NULL;
62470+ spin_unlock(&gr_learn_lock);
62471+ if (tmp)
62472+ vfree(tmp);
62473+ if (learn_buffer_user != NULL) {
62474+ vfree(learn_buffer_user);
62475+ learn_buffer_user = NULL;
62476+ }
62477+ learn_buffer_len = 0;
62478+ learn_buffer_user_len = 0;
62479+ gr_learn_attached = 0;
62480+ mutex_unlock(&gr_learn_user_mutex);
62481+ }
62482+
62483+ return 0;
62484+}
62485+
62486+const struct file_operations grsec_fops = {
62487+ .read = read_learn,
62488+ .write = write_grsec_handler,
62489+ .open = open_learn,
62490+ .release = close_learn,
62491+ .poll = poll_learn,
62492+};
62493diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
62494new file mode 100644
62495index 0000000..39645c9
62496--- /dev/null
62497+++ b/grsecurity/gracl_res.c
62498@@ -0,0 +1,68 @@
62499+#include <linux/kernel.h>
62500+#include <linux/sched.h>
62501+#include <linux/gracl.h>
62502+#include <linux/grinternal.h>
62503+
62504+static const char *restab_log[] = {
62505+ [RLIMIT_CPU] = "RLIMIT_CPU",
62506+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
62507+ [RLIMIT_DATA] = "RLIMIT_DATA",
62508+ [RLIMIT_STACK] = "RLIMIT_STACK",
62509+ [RLIMIT_CORE] = "RLIMIT_CORE",
62510+ [RLIMIT_RSS] = "RLIMIT_RSS",
62511+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
62512+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
62513+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
62514+ [RLIMIT_AS] = "RLIMIT_AS",
62515+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
62516+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
62517+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
62518+ [RLIMIT_NICE] = "RLIMIT_NICE",
62519+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
62520+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
62521+ [GR_CRASH_RES] = "RLIMIT_CRASH"
62522+};
62523+
62524+void
62525+gr_log_resource(const struct task_struct *task,
62526+ const int res, const unsigned long wanted, const int gt)
62527+{
62528+ const struct cred *cred;
62529+ unsigned long rlim;
62530+
62531+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
62532+ return;
62533+
62534+ // not yet supported resource
62535+ if (unlikely(!restab_log[res]))
62536+ return;
62537+
62538+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
62539+ rlim = task_rlimit_max(task, res);
62540+ else
62541+ rlim = task_rlimit(task, res);
62542+
62543+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
62544+ return;
62545+
62546+ rcu_read_lock();
62547+ cred = __task_cred(task);
62548+
62549+ if (res == RLIMIT_NPROC &&
62550+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
62551+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
62552+ goto out_rcu_unlock;
62553+ else if (res == RLIMIT_MEMLOCK &&
62554+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
62555+ goto out_rcu_unlock;
62556+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
62557+ goto out_rcu_unlock;
62558+ rcu_read_unlock();
62559+
62560+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
62561+
62562+ return;
62563+out_rcu_unlock:
62564+ rcu_read_unlock();
62565+ return;
62566+}
62567diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
62568new file mode 100644
62569index 0000000..8c8fc9d
62570--- /dev/null
62571+++ b/grsecurity/gracl_segv.c
62572@@ -0,0 +1,303 @@
62573+#include <linux/kernel.h>
62574+#include <linux/mm.h>
62575+#include <asm/uaccess.h>
62576+#include <asm/errno.h>
62577+#include <asm/mman.h>
62578+#include <net/sock.h>
62579+#include <linux/file.h>
62580+#include <linux/fs.h>
62581+#include <linux/net.h>
62582+#include <linux/in.h>
62583+#include <linux/slab.h>
62584+#include <linux/types.h>
62585+#include <linux/sched.h>
62586+#include <linux/timer.h>
62587+#include <linux/gracl.h>
62588+#include <linux/grsecurity.h>
62589+#include <linux/grinternal.h>
62590+
62591+static struct crash_uid *uid_set;
62592+static unsigned short uid_used;
62593+static DEFINE_SPINLOCK(gr_uid_lock);
62594+extern rwlock_t gr_inode_lock;
62595+extern struct acl_subject_label *
62596+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
62597+ struct acl_role_label *role);
62598+
62599+#ifdef CONFIG_BTRFS_FS
62600+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
62601+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
62602+#endif
62603+
62604+static inline dev_t __get_dev(const struct dentry *dentry)
62605+{
62606+#ifdef CONFIG_BTRFS_FS
62607+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
62608+ return get_btrfs_dev_from_inode(dentry->d_inode);
62609+ else
62610+#endif
62611+ return dentry->d_inode->i_sb->s_dev;
62612+}
62613+
62614+int
62615+gr_init_uidset(void)
62616+{
62617+ uid_set =
62618+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
62619+ uid_used = 0;
62620+
62621+ return uid_set ? 1 : 0;
62622+}
62623+
62624+void
62625+gr_free_uidset(void)
62626+{
62627+ if (uid_set)
62628+ kfree(uid_set);
62629+
62630+ return;
62631+}
62632+
62633+int
62634+gr_find_uid(const uid_t uid)
62635+{
62636+ struct crash_uid *tmp = uid_set;
62637+ uid_t buid;
62638+ int low = 0, high = uid_used - 1, mid;
62639+
62640+ while (high >= low) {
62641+ mid = (low + high) >> 1;
62642+ buid = tmp[mid].uid;
62643+ if (buid == uid)
62644+ return mid;
62645+ if (buid > uid)
62646+ high = mid - 1;
62647+ if (buid < uid)
62648+ low = mid + 1;
62649+ }
62650+
62651+ return -1;
62652+}
62653+
62654+static __inline__ void
62655+gr_insertsort(void)
62656+{
62657+ unsigned short i, j;
62658+ struct crash_uid index;
62659+
62660+ for (i = 1; i < uid_used; i++) {
62661+ index = uid_set[i];
62662+ j = i;
62663+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
62664+ uid_set[j] = uid_set[j - 1];
62665+ j--;
62666+ }
62667+ uid_set[j] = index;
62668+ }
62669+
62670+ return;
62671+}
62672+
62673+static __inline__ void
62674+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
62675+{
62676+ int loc;
62677+ uid_t uid = GR_GLOBAL_UID(kuid);
62678+
62679+ if (uid_used == GR_UIDTABLE_MAX)
62680+ return;
62681+
62682+ loc = gr_find_uid(uid);
62683+
62684+ if (loc >= 0) {
62685+ uid_set[loc].expires = expires;
62686+ return;
62687+ }
62688+
62689+ uid_set[uid_used].uid = uid;
62690+ uid_set[uid_used].expires = expires;
62691+ uid_used++;
62692+
62693+ gr_insertsort();
62694+
62695+ return;
62696+}
62697+
62698+void
62699+gr_remove_uid(const unsigned short loc)
62700+{
62701+ unsigned short i;
62702+
62703+ for (i = loc + 1; i < uid_used; i++)
62704+ uid_set[i - 1] = uid_set[i];
62705+
62706+ uid_used--;
62707+
62708+ return;
62709+}
62710+
62711+int
62712+gr_check_crash_uid(const kuid_t kuid)
62713+{
62714+ int loc;
62715+ int ret = 0;
62716+ uid_t uid;
62717+
62718+ if (unlikely(!gr_acl_is_enabled()))
62719+ return 0;
62720+
62721+ uid = GR_GLOBAL_UID(kuid);
62722+
62723+ spin_lock(&gr_uid_lock);
62724+ loc = gr_find_uid(uid);
62725+
62726+ if (loc < 0)
62727+ goto out_unlock;
62728+
62729+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
62730+ gr_remove_uid(loc);
62731+ else
62732+ ret = 1;
62733+
62734+out_unlock:
62735+ spin_unlock(&gr_uid_lock);
62736+ return ret;
62737+}
62738+
62739+static __inline__ int
62740+proc_is_setxid(const struct cred *cred)
62741+{
62742+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
62743+ !uid_eq(cred->uid, cred->fsuid))
62744+ return 1;
62745+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
62746+ !gid_eq(cred->gid, cred->fsgid))
62747+ return 1;
62748+
62749+ return 0;
62750+}
62751+
62752+extern int gr_fake_force_sig(int sig, struct task_struct *t);
62753+
62754+void
62755+gr_handle_crash(struct task_struct *task, const int sig)
62756+{
62757+ struct acl_subject_label *curr;
62758+ struct task_struct *tsk, *tsk2;
62759+ const struct cred *cred;
62760+ const struct cred *cred2;
62761+
62762+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
62763+ return;
62764+
62765+ if (unlikely(!gr_acl_is_enabled()))
62766+ return;
62767+
62768+ curr = task->acl;
62769+
62770+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
62771+ return;
62772+
62773+ if (time_before_eq(curr->expires, get_seconds())) {
62774+ curr->expires = 0;
62775+ curr->crashes = 0;
62776+ }
62777+
62778+ curr->crashes++;
62779+
62780+ if (!curr->expires)
62781+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
62782+
62783+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62784+ time_after(curr->expires, get_seconds())) {
62785+ rcu_read_lock();
62786+ cred = __task_cred(task);
62787+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
62788+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62789+ spin_lock(&gr_uid_lock);
62790+ gr_insert_uid(cred->uid, curr->expires);
62791+ spin_unlock(&gr_uid_lock);
62792+ curr->expires = 0;
62793+ curr->crashes = 0;
62794+ read_lock(&tasklist_lock);
62795+ do_each_thread(tsk2, tsk) {
62796+ cred2 = __task_cred(tsk);
62797+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
62798+ gr_fake_force_sig(SIGKILL, tsk);
62799+ } while_each_thread(tsk2, tsk);
62800+ read_unlock(&tasklist_lock);
62801+ } else {
62802+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62803+ read_lock(&tasklist_lock);
62804+ read_lock(&grsec_exec_file_lock);
62805+ do_each_thread(tsk2, tsk) {
62806+ if (likely(tsk != task)) {
62807+ // if this thread has the same subject as the one that triggered
62808+ // RES_CRASH and it's the same binary, kill it
62809+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
62810+ gr_fake_force_sig(SIGKILL, tsk);
62811+ }
62812+ } while_each_thread(tsk2, tsk);
62813+ read_unlock(&grsec_exec_file_lock);
62814+ read_unlock(&tasklist_lock);
62815+ }
62816+ rcu_read_unlock();
62817+ }
62818+
62819+ return;
62820+}
62821+
62822+int
62823+gr_check_crash_exec(const struct file *filp)
62824+{
62825+ struct acl_subject_label *curr;
62826+
62827+ if (unlikely(!gr_acl_is_enabled()))
62828+ return 0;
62829+
62830+ read_lock(&gr_inode_lock);
62831+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
62832+ __get_dev(filp->f_path.dentry),
62833+ current->role);
62834+ read_unlock(&gr_inode_lock);
62835+
62836+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
62837+ (!curr->crashes && !curr->expires))
62838+ return 0;
62839+
62840+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62841+ time_after(curr->expires, get_seconds()))
62842+ return 1;
62843+ else if (time_before_eq(curr->expires, get_seconds())) {
62844+ curr->crashes = 0;
62845+ curr->expires = 0;
62846+ }
62847+
62848+ return 0;
62849+}
62850+
62851+void
62852+gr_handle_alertkill(struct task_struct *task)
62853+{
62854+ struct acl_subject_label *curracl;
62855+ __u32 curr_ip;
62856+ struct task_struct *p, *p2;
62857+
62858+ if (unlikely(!gr_acl_is_enabled()))
62859+ return;
62860+
62861+ curracl = task->acl;
62862+ curr_ip = task->signal->curr_ip;
62863+
62864+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
62865+ read_lock(&tasklist_lock);
62866+ do_each_thread(p2, p) {
62867+ if (p->signal->curr_ip == curr_ip)
62868+ gr_fake_force_sig(SIGKILL, p);
62869+ } while_each_thread(p2, p);
62870+ read_unlock(&tasklist_lock);
62871+ } else if (curracl->mode & GR_KILLPROC)
62872+ gr_fake_force_sig(SIGKILL, task);
62873+
62874+ return;
62875+}
62876diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
62877new file mode 100644
62878index 0000000..98011b0
62879--- /dev/null
62880+++ b/grsecurity/gracl_shm.c
62881@@ -0,0 +1,40 @@
62882+#include <linux/kernel.h>
62883+#include <linux/mm.h>
62884+#include <linux/sched.h>
62885+#include <linux/file.h>
62886+#include <linux/ipc.h>
62887+#include <linux/gracl.h>
62888+#include <linux/grsecurity.h>
62889+#include <linux/grinternal.h>
62890+
62891+int
62892+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62893+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
62894+{
62895+ struct task_struct *task;
62896+
62897+ if (!gr_acl_is_enabled())
62898+ return 1;
62899+
62900+ rcu_read_lock();
62901+ read_lock(&tasklist_lock);
62902+
62903+ task = find_task_by_vpid(shm_cprid);
62904+
62905+ if (unlikely(!task))
62906+ task = find_task_by_vpid(shm_lapid);
62907+
62908+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
62909+ (task_pid_nr(task) == shm_lapid)) &&
62910+ (task->acl->mode & GR_PROTSHM) &&
62911+ (task->acl != current->acl))) {
62912+ read_unlock(&tasklist_lock);
62913+ rcu_read_unlock();
62914+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
62915+ return 0;
62916+ }
62917+ read_unlock(&tasklist_lock);
62918+ rcu_read_unlock();
62919+
62920+ return 1;
62921+}
62922diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
62923new file mode 100644
62924index 0000000..bc0be01
62925--- /dev/null
62926+++ b/grsecurity/grsec_chdir.c
62927@@ -0,0 +1,19 @@
62928+#include <linux/kernel.h>
62929+#include <linux/sched.h>
62930+#include <linux/fs.h>
62931+#include <linux/file.h>
62932+#include <linux/grsecurity.h>
62933+#include <linux/grinternal.h>
62934+
62935+void
62936+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
62937+{
62938+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62939+ if ((grsec_enable_chdir && grsec_enable_group &&
62940+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
62941+ !grsec_enable_group)) {
62942+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
62943+ }
62944+#endif
62945+ return;
62946+}
62947diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
62948new file mode 100644
62949index 0000000..6d2de57
62950--- /dev/null
62951+++ b/grsecurity/grsec_chroot.c
62952@@ -0,0 +1,357 @@
62953+#include <linux/kernel.h>
62954+#include <linux/module.h>
62955+#include <linux/sched.h>
62956+#include <linux/file.h>
62957+#include <linux/fs.h>
62958+#include <linux/mount.h>
62959+#include <linux/types.h>
62960+#include "../fs/mount.h"
62961+#include <linux/grsecurity.h>
62962+#include <linux/grinternal.h>
62963+
62964+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
62965+{
62966+#ifdef CONFIG_GRKERNSEC
62967+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
62968+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
62969+ task->gr_is_chrooted = 1;
62970+ else
62971+ task->gr_is_chrooted = 0;
62972+
62973+ task->gr_chroot_dentry = path->dentry;
62974+#endif
62975+ return;
62976+}
62977+
62978+void gr_clear_chroot_entries(struct task_struct *task)
62979+{
62980+#ifdef CONFIG_GRKERNSEC
62981+ task->gr_is_chrooted = 0;
62982+ task->gr_chroot_dentry = NULL;
62983+#endif
62984+ return;
62985+}
62986+
62987+int
62988+gr_handle_chroot_unix(const pid_t pid)
62989+{
62990+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62991+ struct task_struct *p;
62992+
62993+ if (unlikely(!grsec_enable_chroot_unix))
62994+ return 1;
62995+
62996+ if (likely(!proc_is_chrooted(current)))
62997+ return 1;
62998+
62999+ rcu_read_lock();
63000+ read_lock(&tasklist_lock);
63001+ p = find_task_by_vpid_unrestricted(pid);
63002+ if (unlikely(p && !have_same_root(current, p))) {
63003+ read_unlock(&tasklist_lock);
63004+ rcu_read_unlock();
63005+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
63006+ return 0;
63007+ }
63008+ read_unlock(&tasklist_lock);
63009+ rcu_read_unlock();
63010+#endif
63011+ return 1;
63012+}
63013+
63014+int
63015+gr_handle_chroot_nice(void)
63016+{
63017+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63018+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
63019+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
63020+ return -EPERM;
63021+ }
63022+#endif
63023+ return 0;
63024+}
63025+
63026+int
63027+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
63028+{
63029+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63030+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
63031+ && proc_is_chrooted(current)) {
63032+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
63033+ return -EACCES;
63034+ }
63035+#endif
63036+ return 0;
63037+}
63038+
63039+int
63040+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
63041+{
63042+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63043+ struct task_struct *p;
63044+ int ret = 0;
63045+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
63046+ return ret;
63047+
63048+ read_lock(&tasklist_lock);
63049+ do_each_pid_task(pid, type, p) {
63050+ if (!have_same_root(current, p)) {
63051+ ret = 1;
63052+ goto out;
63053+ }
63054+ } while_each_pid_task(pid, type, p);
63055+out:
63056+ read_unlock(&tasklist_lock);
63057+ return ret;
63058+#endif
63059+ return 0;
63060+}
63061+
63062+int
63063+gr_pid_is_chrooted(struct task_struct *p)
63064+{
63065+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63066+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
63067+ return 0;
63068+
63069+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
63070+ !have_same_root(current, p)) {
63071+ return 1;
63072+ }
63073+#endif
63074+ return 0;
63075+}
63076+
63077+EXPORT_SYMBOL(gr_pid_is_chrooted);
63078+
63079+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
63080+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
63081+{
63082+ struct path path, currentroot;
63083+ int ret = 0;
63084+
63085+ path.dentry = (struct dentry *)u_dentry;
63086+ path.mnt = (struct vfsmount *)u_mnt;
63087+ get_fs_root(current->fs, &currentroot);
63088+ if (path_is_under(&path, &currentroot))
63089+ ret = 1;
63090+ path_put(&currentroot);
63091+
63092+ return ret;
63093+}
63094+#endif
63095+
63096+int
63097+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
63098+{
63099+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63100+ if (!grsec_enable_chroot_fchdir)
63101+ return 1;
63102+
63103+ if (!proc_is_chrooted(current))
63104+ return 1;
63105+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
63106+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
63107+ return 0;
63108+ }
63109+#endif
63110+ return 1;
63111+}
63112+
63113+int
63114+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63115+ const time_t shm_createtime)
63116+{
63117+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63118+ struct task_struct *p;
63119+ time_t starttime;
63120+
63121+ if (unlikely(!grsec_enable_chroot_shmat))
63122+ return 1;
63123+
63124+ if (likely(!proc_is_chrooted(current)))
63125+ return 1;
63126+
63127+ rcu_read_lock();
63128+ read_lock(&tasklist_lock);
63129+
63130+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
63131+ starttime = p->start_time.tv_sec;
63132+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
63133+ if (have_same_root(current, p)) {
63134+ goto allow;
63135+ } else {
63136+ read_unlock(&tasklist_lock);
63137+ rcu_read_unlock();
63138+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63139+ return 0;
63140+ }
63141+ }
63142+ /* creator exited, pid reuse, fall through to next check */
63143+ }
63144+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
63145+ if (unlikely(!have_same_root(current, p))) {
63146+ read_unlock(&tasklist_lock);
63147+ rcu_read_unlock();
63148+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63149+ return 0;
63150+ }
63151+ }
63152+
63153+allow:
63154+ read_unlock(&tasklist_lock);
63155+ rcu_read_unlock();
63156+#endif
63157+ return 1;
63158+}
63159+
63160+void
63161+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
63162+{
63163+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63164+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
63165+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
63166+#endif
63167+ return;
63168+}
63169+
63170+int
63171+gr_handle_chroot_mknod(const struct dentry *dentry,
63172+ const struct vfsmount *mnt, const int mode)
63173+{
63174+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63175+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
63176+ proc_is_chrooted(current)) {
63177+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
63178+ return -EPERM;
63179+ }
63180+#endif
63181+ return 0;
63182+}
63183+
63184+int
63185+gr_handle_chroot_mount(const struct dentry *dentry,
63186+ const struct vfsmount *mnt, const char *dev_name)
63187+{
63188+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63189+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
63190+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
63191+ return -EPERM;
63192+ }
63193+#endif
63194+ return 0;
63195+}
63196+
63197+int
63198+gr_handle_chroot_pivot(void)
63199+{
63200+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63201+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
63202+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
63203+ return -EPERM;
63204+ }
63205+#endif
63206+ return 0;
63207+}
63208+
63209+int
63210+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
63211+{
63212+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63213+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
63214+ !gr_is_outside_chroot(dentry, mnt)) {
63215+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
63216+ return -EPERM;
63217+ }
63218+#endif
63219+ return 0;
63220+}
63221+
63222+extern const char *captab_log[];
63223+extern int captab_log_entries;
63224+
63225+int
63226+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63227+{
63228+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63229+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63230+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63231+ if (cap_raised(chroot_caps, cap)) {
63232+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
63233+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
63234+ }
63235+ return 0;
63236+ }
63237+ }
63238+#endif
63239+ return 1;
63240+}
63241+
63242+int
63243+gr_chroot_is_capable(const int cap)
63244+{
63245+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63246+ return gr_task_chroot_is_capable(current, current_cred(), cap);
63247+#endif
63248+ return 1;
63249+}
63250+
63251+int
63252+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
63253+{
63254+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63255+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63256+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63257+ if (cap_raised(chroot_caps, cap)) {
63258+ return 0;
63259+ }
63260+ }
63261+#endif
63262+ return 1;
63263+}
63264+
63265+int
63266+gr_chroot_is_capable_nolog(const int cap)
63267+{
63268+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63269+ return gr_task_chroot_is_capable_nolog(current, cap);
63270+#endif
63271+ return 1;
63272+}
63273+
63274+int
63275+gr_handle_chroot_sysctl(const int op)
63276+{
63277+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63278+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
63279+ proc_is_chrooted(current))
63280+ return -EACCES;
63281+#endif
63282+ return 0;
63283+}
63284+
63285+void
63286+gr_handle_chroot_chdir(struct path *path)
63287+{
63288+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63289+ if (grsec_enable_chroot_chdir)
63290+ set_fs_pwd(current->fs, path);
63291+#endif
63292+ return;
63293+}
63294+
63295+int
63296+gr_handle_chroot_chmod(const struct dentry *dentry,
63297+ const struct vfsmount *mnt, const int mode)
63298+{
63299+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63300+ /* allow chmod +s on directories, but not files */
63301+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
63302+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
63303+ proc_is_chrooted(current)) {
63304+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
63305+ return -EPERM;
63306+ }
63307+#endif
63308+ return 0;
63309+}
63310diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
63311new file mode 100644
63312index 0000000..207d409
63313--- /dev/null
63314+++ b/grsecurity/grsec_disabled.c
63315@@ -0,0 +1,434 @@
63316+#include <linux/kernel.h>
63317+#include <linux/module.h>
63318+#include <linux/sched.h>
63319+#include <linux/file.h>
63320+#include <linux/fs.h>
63321+#include <linux/kdev_t.h>
63322+#include <linux/net.h>
63323+#include <linux/in.h>
63324+#include <linux/ip.h>
63325+#include <linux/skbuff.h>
63326+#include <linux/sysctl.h>
63327+
63328+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63329+void
63330+pax_set_initial_flags(struct linux_binprm *bprm)
63331+{
63332+ return;
63333+}
63334+#endif
63335+
63336+#ifdef CONFIG_SYSCTL
63337+__u32
63338+gr_handle_sysctl(const struct ctl_table * table, const int op)
63339+{
63340+ return 0;
63341+}
63342+#endif
63343+
63344+#ifdef CONFIG_TASKSTATS
63345+int gr_is_taskstats_denied(int pid)
63346+{
63347+ return 0;
63348+}
63349+#endif
63350+
63351+int
63352+gr_acl_is_enabled(void)
63353+{
63354+ return 0;
63355+}
63356+
63357+void
63358+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
63359+{
63360+ return;
63361+}
63362+
63363+int
63364+gr_handle_rawio(const struct inode *inode)
63365+{
63366+ return 0;
63367+}
63368+
63369+void
63370+gr_acl_handle_psacct(struct task_struct *task, const long code)
63371+{
63372+ return;
63373+}
63374+
63375+int
63376+gr_handle_ptrace(struct task_struct *task, const long request)
63377+{
63378+ return 0;
63379+}
63380+
63381+int
63382+gr_handle_proc_ptrace(struct task_struct *task)
63383+{
63384+ return 0;
63385+}
63386+
63387+int
63388+gr_set_acls(const int type)
63389+{
63390+ return 0;
63391+}
63392+
63393+int
63394+gr_check_hidden_task(const struct task_struct *tsk)
63395+{
63396+ return 0;
63397+}
63398+
63399+int
63400+gr_check_protected_task(const struct task_struct *task)
63401+{
63402+ return 0;
63403+}
63404+
63405+int
63406+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
63407+{
63408+ return 0;
63409+}
63410+
63411+void
63412+gr_copy_label(struct task_struct *tsk)
63413+{
63414+ return;
63415+}
63416+
63417+void
63418+gr_set_pax_flags(struct task_struct *task)
63419+{
63420+ return;
63421+}
63422+
63423+int
63424+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
63425+ const int unsafe_share)
63426+{
63427+ return 0;
63428+}
63429+
63430+void
63431+gr_handle_delete(const ino_t ino, const dev_t dev)
63432+{
63433+ return;
63434+}
63435+
63436+void
63437+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
63438+{
63439+ return;
63440+}
63441+
63442+void
63443+gr_handle_crash(struct task_struct *task, const int sig)
63444+{
63445+ return;
63446+}
63447+
63448+int
63449+gr_check_crash_exec(const struct file *filp)
63450+{
63451+ return 0;
63452+}
63453+
63454+int
63455+gr_check_crash_uid(const kuid_t uid)
63456+{
63457+ return 0;
63458+}
63459+
63460+void
63461+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63462+ struct dentry *old_dentry,
63463+ struct dentry *new_dentry,
63464+ struct vfsmount *mnt, const __u8 replace)
63465+{
63466+ return;
63467+}
63468+
63469+int
63470+gr_search_socket(const int family, const int type, const int protocol)
63471+{
63472+ return 1;
63473+}
63474+
63475+int
63476+gr_search_connectbind(const int mode, const struct socket *sock,
63477+ const struct sockaddr_in *addr)
63478+{
63479+ return 0;
63480+}
63481+
63482+void
63483+gr_handle_alertkill(struct task_struct *task)
63484+{
63485+ return;
63486+}
63487+
63488+__u32
63489+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
63490+{
63491+ return 1;
63492+}
63493+
63494+__u32
63495+gr_acl_handle_hidden_file(const struct dentry * dentry,
63496+ const struct vfsmount * mnt)
63497+{
63498+ return 1;
63499+}
63500+
63501+__u32
63502+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63503+ int acc_mode)
63504+{
63505+ return 1;
63506+}
63507+
63508+__u32
63509+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63510+{
63511+ return 1;
63512+}
63513+
63514+__u32
63515+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
63516+{
63517+ return 1;
63518+}
63519+
63520+int
63521+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
63522+ unsigned int *vm_flags)
63523+{
63524+ return 1;
63525+}
63526+
63527+__u32
63528+gr_acl_handle_truncate(const struct dentry * dentry,
63529+ const struct vfsmount * mnt)
63530+{
63531+ return 1;
63532+}
63533+
63534+__u32
63535+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
63536+{
63537+ return 1;
63538+}
63539+
63540+__u32
63541+gr_acl_handle_access(const struct dentry * dentry,
63542+ const struct vfsmount * mnt, const int fmode)
63543+{
63544+ return 1;
63545+}
63546+
63547+__u32
63548+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
63549+ umode_t *mode)
63550+{
63551+ return 1;
63552+}
63553+
63554+__u32
63555+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
63556+{
63557+ return 1;
63558+}
63559+
63560+__u32
63561+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
63562+{
63563+ return 1;
63564+}
63565+
63566+void
63567+grsecurity_init(void)
63568+{
63569+ return;
63570+}
63571+
63572+umode_t gr_acl_umask(void)
63573+{
63574+ return 0;
63575+}
63576+
63577+__u32
63578+gr_acl_handle_mknod(const struct dentry * new_dentry,
63579+ const struct dentry * parent_dentry,
63580+ const struct vfsmount * parent_mnt,
63581+ const int mode)
63582+{
63583+ return 1;
63584+}
63585+
63586+__u32
63587+gr_acl_handle_mkdir(const struct dentry * new_dentry,
63588+ const struct dentry * parent_dentry,
63589+ const struct vfsmount * parent_mnt)
63590+{
63591+ return 1;
63592+}
63593+
63594+__u32
63595+gr_acl_handle_symlink(const struct dentry * new_dentry,
63596+ const struct dentry * parent_dentry,
63597+ const struct vfsmount * parent_mnt, const struct filename *from)
63598+{
63599+ return 1;
63600+}
63601+
63602+__u32
63603+gr_acl_handle_link(const struct dentry * new_dentry,
63604+ const struct dentry * parent_dentry,
63605+ const struct vfsmount * parent_mnt,
63606+ const struct dentry * old_dentry,
63607+ const struct vfsmount * old_mnt, const struct filename *to)
63608+{
63609+ return 1;
63610+}
63611+
63612+int
63613+gr_acl_handle_rename(const struct dentry *new_dentry,
63614+ const struct dentry *parent_dentry,
63615+ const struct vfsmount *parent_mnt,
63616+ const struct dentry *old_dentry,
63617+ const struct inode *old_parent_inode,
63618+ const struct vfsmount *old_mnt, const struct filename *newname)
63619+{
63620+ return 0;
63621+}
63622+
63623+int
63624+gr_acl_handle_filldir(const struct file *file, const char *name,
63625+ const int namelen, const ino_t ino)
63626+{
63627+ return 1;
63628+}
63629+
63630+int
63631+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63632+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63633+{
63634+ return 1;
63635+}
63636+
63637+int
63638+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
63639+{
63640+ return 0;
63641+}
63642+
63643+int
63644+gr_search_accept(const struct socket *sock)
63645+{
63646+ return 0;
63647+}
63648+
63649+int
63650+gr_search_listen(const struct socket *sock)
63651+{
63652+ return 0;
63653+}
63654+
63655+int
63656+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
63657+{
63658+ return 0;
63659+}
63660+
63661+__u32
63662+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
63663+{
63664+ return 1;
63665+}
63666+
63667+__u32
63668+gr_acl_handle_creat(const struct dentry * dentry,
63669+ const struct dentry * p_dentry,
63670+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63671+ const int imode)
63672+{
63673+ return 1;
63674+}
63675+
63676+void
63677+gr_acl_handle_exit(void)
63678+{
63679+ return;
63680+}
63681+
63682+int
63683+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
63684+{
63685+ return 1;
63686+}
63687+
63688+void
63689+gr_set_role_label(const kuid_t uid, const kgid_t gid)
63690+{
63691+ return;
63692+}
63693+
63694+int
63695+gr_acl_handle_procpidmem(const struct task_struct *task)
63696+{
63697+ return 0;
63698+}
63699+
63700+int
63701+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
63702+{
63703+ return 0;
63704+}
63705+
63706+int
63707+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
63708+{
63709+ return 0;
63710+}
63711+
63712+void
63713+gr_set_kernel_label(struct task_struct *task)
63714+{
63715+ return;
63716+}
63717+
63718+int
63719+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63720+{
63721+ return 0;
63722+}
63723+
63724+int
63725+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63726+{
63727+ return 0;
63728+}
63729+
63730+int gr_acl_enable_at_secure(void)
63731+{
63732+ return 0;
63733+}
63734+
63735+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63736+{
63737+ return dentry->d_inode->i_sb->s_dev;
63738+}
63739+
63740+void gr_put_exec_file(struct task_struct *task)
63741+{
63742+ return;
63743+}
63744+
63745+EXPORT_SYMBOL(gr_set_kernel_label);
63746+#ifdef CONFIG_SECURITY
63747+EXPORT_SYMBOL(gr_check_user_change);
63748+EXPORT_SYMBOL(gr_check_group_change);
63749+#endif
63750diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
63751new file mode 100644
63752index 0000000..387032b
63753--- /dev/null
63754+++ b/grsecurity/grsec_exec.c
63755@@ -0,0 +1,187 @@
63756+#include <linux/kernel.h>
63757+#include <linux/sched.h>
63758+#include <linux/file.h>
63759+#include <linux/binfmts.h>
63760+#include <linux/fs.h>
63761+#include <linux/types.h>
63762+#include <linux/grdefs.h>
63763+#include <linux/grsecurity.h>
63764+#include <linux/grinternal.h>
63765+#include <linux/capability.h>
63766+#include <linux/module.h>
63767+#include <linux/compat.h>
63768+
63769+#include <asm/uaccess.h>
63770+
63771+#ifdef CONFIG_GRKERNSEC_EXECLOG
63772+static char gr_exec_arg_buf[132];
63773+static DEFINE_MUTEX(gr_exec_arg_mutex);
63774+#endif
63775+
63776+struct user_arg_ptr {
63777+#ifdef CONFIG_COMPAT
63778+ bool is_compat;
63779+#endif
63780+ union {
63781+ const char __user *const __user *native;
63782+#ifdef CONFIG_COMPAT
63783+ const compat_uptr_t __user *compat;
63784+#endif
63785+ } ptr;
63786+};
63787+
63788+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
63789+
63790+void
63791+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
63792+{
63793+#ifdef CONFIG_GRKERNSEC_EXECLOG
63794+ char *grarg = gr_exec_arg_buf;
63795+ unsigned int i, x, execlen = 0;
63796+ char c;
63797+
63798+ if (!((grsec_enable_execlog && grsec_enable_group &&
63799+ in_group_p(grsec_audit_gid))
63800+ || (grsec_enable_execlog && !grsec_enable_group)))
63801+ return;
63802+
63803+ mutex_lock(&gr_exec_arg_mutex);
63804+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
63805+
63806+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
63807+ const char __user *p;
63808+ unsigned int len;
63809+
63810+ p = get_user_arg_ptr(argv, i);
63811+ if (IS_ERR(p))
63812+ goto log;
63813+
63814+ len = strnlen_user(p, 128 - execlen);
63815+ if (len > 128 - execlen)
63816+ len = 128 - execlen;
63817+ else if (len > 0)
63818+ len--;
63819+ if (copy_from_user(grarg + execlen, p, len))
63820+ goto log;
63821+
63822+ /* rewrite unprintable characters */
63823+ for (x = 0; x < len; x++) {
63824+ c = *(grarg + execlen + x);
63825+ if (c < 32 || c > 126)
63826+ *(grarg + execlen + x) = ' ';
63827+ }
63828+
63829+ execlen += len;
63830+ *(grarg + execlen) = ' ';
63831+ *(grarg + execlen + 1) = '\0';
63832+ execlen++;
63833+ }
63834+
63835+ log:
63836+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
63837+ bprm->file->f_path.mnt, grarg);
63838+ mutex_unlock(&gr_exec_arg_mutex);
63839+#endif
63840+ return;
63841+}
63842+
63843+#ifdef CONFIG_GRKERNSEC
63844+extern int gr_acl_is_capable(const int cap);
63845+extern int gr_acl_is_capable_nolog(const int cap);
63846+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63847+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
63848+extern int gr_chroot_is_capable(const int cap);
63849+extern int gr_chroot_is_capable_nolog(const int cap);
63850+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63851+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
63852+#endif
63853+
63854+const char *captab_log[] = {
63855+ "CAP_CHOWN",
63856+ "CAP_DAC_OVERRIDE",
63857+ "CAP_DAC_READ_SEARCH",
63858+ "CAP_FOWNER",
63859+ "CAP_FSETID",
63860+ "CAP_KILL",
63861+ "CAP_SETGID",
63862+ "CAP_SETUID",
63863+ "CAP_SETPCAP",
63864+ "CAP_LINUX_IMMUTABLE",
63865+ "CAP_NET_BIND_SERVICE",
63866+ "CAP_NET_BROADCAST",
63867+ "CAP_NET_ADMIN",
63868+ "CAP_NET_RAW",
63869+ "CAP_IPC_LOCK",
63870+ "CAP_IPC_OWNER",
63871+ "CAP_SYS_MODULE",
63872+ "CAP_SYS_RAWIO",
63873+ "CAP_SYS_CHROOT",
63874+ "CAP_SYS_PTRACE",
63875+ "CAP_SYS_PACCT",
63876+ "CAP_SYS_ADMIN",
63877+ "CAP_SYS_BOOT",
63878+ "CAP_SYS_NICE",
63879+ "CAP_SYS_RESOURCE",
63880+ "CAP_SYS_TIME",
63881+ "CAP_SYS_TTY_CONFIG",
63882+ "CAP_MKNOD",
63883+ "CAP_LEASE",
63884+ "CAP_AUDIT_WRITE",
63885+ "CAP_AUDIT_CONTROL",
63886+ "CAP_SETFCAP",
63887+ "CAP_MAC_OVERRIDE",
63888+ "CAP_MAC_ADMIN",
63889+ "CAP_SYSLOG",
63890+ "CAP_WAKE_ALARM"
63891+};
63892+
63893+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
63894+
63895+int gr_is_capable(const int cap)
63896+{
63897+#ifdef CONFIG_GRKERNSEC
63898+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
63899+ return 1;
63900+ return 0;
63901+#else
63902+ return 1;
63903+#endif
63904+}
63905+
63906+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63907+{
63908+#ifdef CONFIG_GRKERNSEC
63909+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
63910+ return 1;
63911+ return 0;
63912+#else
63913+ return 1;
63914+#endif
63915+}
63916+
63917+int gr_is_capable_nolog(const int cap)
63918+{
63919+#ifdef CONFIG_GRKERNSEC
63920+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
63921+ return 1;
63922+ return 0;
63923+#else
63924+ return 1;
63925+#endif
63926+}
63927+
63928+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
63929+{
63930+#ifdef CONFIG_GRKERNSEC
63931+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
63932+ return 1;
63933+ return 0;
63934+#else
63935+ return 1;
63936+#endif
63937+}
63938+
63939+EXPORT_SYMBOL(gr_is_capable);
63940+EXPORT_SYMBOL(gr_is_capable_nolog);
63941+EXPORT_SYMBOL(gr_task_is_capable);
63942+EXPORT_SYMBOL(gr_task_is_capable_nolog);
63943diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
63944new file mode 100644
63945index 0000000..06cc6ea
63946--- /dev/null
63947+++ b/grsecurity/grsec_fifo.c
63948@@ -0,0 +1,24 @@
63949+#include <linux/kernel.h>
63950+#include <linux/sched.h>
63951+#include <linux/fs.h>
63952+#include <linux/file.h>
63953+#include <linux/grinternal.h>
63954+
63955+int
63956+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
63957+ const struct dentry *dir, const int flag, const int acc_mode)
63958+{
63959+#ifdef CONFIG_GRKERNSEC_FIFO
63960+ const struct cred *cred = current_cred();
63961+
63962+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
63963+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
63964+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
63965+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
63966+ if (!inode_permission(dentry->d_inode, acc_mode))
63967+ 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));
63968+ return -EACCES;
63969+ }
63970+#endif
63971+ return 0;
63972+}
63973diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
63974new file mode 100644
63975index 0000000..8ca18bf
63976--- /dev/null
63977+++ b/grsecurity/grsec_fork.c
63978@@ -0,0 +1,23 @@
63979+#include <linux/kernel.h>
63980+#include <linux/sched.h>
63981+#include <linux/grsecurity.h>
63982+#include <linux/grinternal.h>
63983+#include <linux/errno.h>
63984+
63985+void
63986+gr_log_forkfail(const int retval)
63987+{
63988+#ifdef CONFIG_GRKERNSEC_FORKFAIL
63989+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
63990+ switch (retval) {
63991+ case -EAGAIN:
63992+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
63993+ break;
63994+ case -ENOMEM:
63995+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
63996+ break;
63997+ }
63998+ }
63999+#endif
64000+ return;
64001+}
64002diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
64003new file mode 100644
64004index 0000000..a862e9f
64005--- /dev/null
64006+++ b/grsecurity/grsec_init.c
64007@@ -0,0 +1,283 @@
64008+#include <linux/kernel.h>
64009+#include <linux/sched.h>
64010+#include <linux/mm.h>
64011+#include <linux/gracl.h>
64012+#include <linux/slab.h>
64013+#include <linux/vmalloc.h>
64014+#include <linux/percpu.h>
64015+#include <linux/module.h>
64016+
64017+int grsec_enable_ptrace_readexec;
64018+int grsec_enable_setxid;
64019+int grsec_enable_symlinkown;
64020+kgid_t grsec_symlinkown_gid;
64021+int grsec_enable_brute;
64022+int grsec_enable_link;
64023+int grsec_enable_dmesg;
64024+int grsec_enable_harden_ptrace;
64025+int grsec_enable_fifo;
64026+int grsec_enable_execlog;
64027+int grsec_enable_signal;
64028+int grsec_enable_forkfail;
64029+int grsec_enable_audit_ptrace;
64030+int grsec_enable_time;
64031+int grsec_enable_audit_textrel;
64032+int grsec_enable_group;
64033+kgid_t grsec_audit_gid;
64034+int grsec_enable_chdir;
64035+int grsec_enable_mount;
64036+int grsec_enable_rofs;
64037+int grsec_enable_chroot_findtask;
64038+int grsec_enable_chroot_mount;
64039+int grsec_enable_chroot_shmat;
64040+int grsec_enable_chroot_fchdir;
64041+int grsec_enable_chroot_double;
64042+int grsec_enable_chroot_pivot;
64043+int grsec_enable_chroot_chdir;
64044+int grsec_enable_chroot_chmod;
64045+int grsec_enable_chroot_mknod;
64046+int grsec_enable_chroot_nice;
64047+int grsec_enable_chroot_execlog;
64048+int grsec_enable_chroot_caps;
64049+int grsec_enable_chroot_sysctl;
64050+int grsec_enable_chroot_unix;
64051+int grsec_enable_tpe;
64052+kgid_t grsec_tpe_gid;
64053+int grsec_enable_blackhole;
64054+#ifdef CONFIG_IPV6_MODULE
64055+EXPORT_SYMBOL(grsec_enable_blackhole);
64056+#endif
64057+int grsec_lastack_retries;
64058+int grsec_enable_tpe_all;
64059+int grsec_enable_tpe_invert;
64060+int grsec_enable_socket_all;
64061+kgid_t grsec_socket_all_gid;
64062+int grsec_enable_socket_client;
64063+kgid_t grsec_socket_client_gid;
64064+int grsec_enable_socket_server;
64065+kgid_t grsec_socket_server_gid;
64066+int grsec_resource_logging;
64067+int grsec_disable_privio;
64068+int grsec_enable_log_rwxmaps;
64069+int grsec_lock;
64070+
64071+DEFINE_SPINLOCK(grsec_alert_lock);
64072+unsigned long grsec_alert_wtime = 0;
64073+unsigned long grsec_alert_fyet = 0;
64074+
64075+DEFINE_SPINLOCK(grsec_audit_lock);
64076+
64077+DEFINE_RWLOCK(grsec_exec_file_lock);
64078+
64079+char *gr_shared_page[4];
64080+
64081+char *gr_alert_log_fmt;
64082+char *gr_audit_log_fmt;
64083+char *gr_alert_log_buf;
64084+char *gr_audit_log_buf;
64085+
64086+extern struct gr_arg *gr_usermode;
64087+extern unsigned char *gr_system_salt;
64088+extern unsigned char *gr_system_sum;
64089+
64090+void __init
64091+grsecurity_init(void)
64092+{
64093+ int j;
64094+ /* create the per-cpu shared pages */
64095+
64096+#ifdef CONFIG_X86
64097+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
64098+#endif
64099+
64100+ for (j = 0; j < 4; j++) {
64101+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
64102+ if (gr_shared_page[j] == NULL) {
64103+ panic("Unable to allocate grsecurity shared page");
64104+ return;
64105+ }
64106+ }
64107+
64108+ /* allocate log buffers */
64109+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
64110+ if (!gr_alert_log_fmt) {
64111+ panic("Unable to allocate grsecurity alert log format buffer");
64112+ return;
64113+ }
64114+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
64115+ if (!gr_audit_log_fmt) {
64116+ panic("Unable to allocate grsecurity audit log format buffer");
64117+ return;
64118+ }
64119+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64120+ if (!gr_alert_log_buf) {
64121+ panic("Unable to allocate grsecurity alert log buffer");
64122+ return;
64123+ }
64124+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64125+ if (!gr_audit_log_buf) {
64126+ panic("Unable to allocate grsecurity audit log buffer");
64127+ return;
64128+ }
64129+
64130+ /* allocate memory for authentication structure */
64131+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
64132+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
64133+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
64134+
64135+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
64136+ panic("Unable to allocate grsecurity authentication structure");
64137+ return;
64138+ }
64139+
64140+
64141+#ifdef CONFIG_GRKERNSEC_IO
64142+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
64143+ grsec_disable_privio = 1;
64144+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64145+ grsec_disable_privio = 1;
64146+#else
64147+ grsec_disable_privio = 0;
64148+#endif
64149+#endif
64150+
64151+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64152+ /* for backward compatibility, tpe_invert always defaults to on if
64153+ enabled in the kernel
64154+ */
64155+ grsec_enable_tpe_invert = 1;
64156+#endif
64157+
64158+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64159+#ifndef CONFIG_GRKERNSEC_SYSCTL
64160+ grsec_lock = 1;
64161+#endif
64162+
64163+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64164+ grsec_enable_audit_textrel = 1;
64165+#endif
64166+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64167+ grsec_enable_log_rwxmaps = 1;
64168+#endif
64169+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64170+ grsec_enable_group = 1;
64171+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
64172+#endif
64173+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64174+ grsec_enable_ptrace_readexec = 1;
64175+#endif
64176+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64177+ grsec_enable_chdir = 1;
64178+#endif
64179+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64180+ grsec_enable_harden_ptrace = 1;
64181+#endif
64182+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64183+ grsec_enable_mount = 1;
64184+#endif
64185+#ifdef CONFIG_GRKERNSEC_LINK
64186+ grsec_enable_link = 1;
64187+#endif
64188+#ifdef CONFIG_GRKERNSEC_BRUTE
64189+ grsec_enable_brute = 1;
64190+#endif
64191+#ifdef CONFIG_GRKERNSEC_DMESG
64192+ grsec_enable_dmesg = 1;
64193+#endif
64194+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
64195+ grsec_enable_blackhole = 1;
64196+ grsec_lastack_retries = 4;
64197+#endif
64198+#ifdef CONFIG_GRKERNSEC_FIFO
64199+ grsec_enable_fifo = 1;
64200+#endif
64201+#ifdef CONFIG_GRKERNSEC_EXECLOG
64202+ grsec_enable_execlog = 1;
64203+#endif
64204+#ifdef CONFIG_GRKERNSEC_SETXID
64205+ grsec_enable_setxid = 1;
64206+#endif
64207+#ifdef CONFIG_GRKERNSEC_SIGNAL
64208+ grsec_enable_signal = 1;
64209+#endif
64210+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64211+ grsec_enable_forkfail = 1;
64212+#endif
64213+#ifdef CONFIG_GRKERNSEC_TIME
64214+ grsec_enable_time = 1;
64215+#endif
64216+#ifdef CONFIG_GRKERNSEC_RESLOG
64217+ grsec_resource_logging = 1;
64218+#endif
64219+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64220+ grsec_enable_chroot_findtask = 1;
64221+#endif
64222+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64223+ grsec_enable_chroot_unix = 1;
64224+#endif
64225+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64226+ grsec_enable_chroot_mount = 1;
64227+#endif
64228+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64229+ grsec_enable_chroot_fchdir = 1;
64230+#endif
64231+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64232+ grsec_enable_chroot_shmat = 1;
64233+#endif
64234+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64235+ grsec_enable_audit_ptrace = 1;
64236+#endif
64237+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64238+ grsec_enable_chroot_double = 1;
64239+#endif
64240+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64241+ grsec_enable_chroot_pivot = 1;
64242+#endif
64243+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64244+ grsec_enable_chroot_chdir = 1;
64245+#endif
64246+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64247+ grsec_enable_chroot_chmod = 1;
64248+#endif
64249+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64250+ grsec_enable_chroot_mknod = 1;
64251+#endif
64252+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64253+ grsec_enable_chroot_nice = 1;
64254+#endif
64255+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64256+ grsec_enable_chroot_execlog = 1;
64257+#endif
64258+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64259+ grsec_enable_chroot_caps = 1;
64260+#endif
64261+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64262+ grsec_enable_chroot_sysctl = 1;
64263+#endif
64264+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64265+ grsec_enable_symlinkown = 1;
64266+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
64267+#endif
64268+#ifdef CONFIG_GRKERNSEC_TPE
64269+ grsec_enable_tpe = 1;
64270+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
64271+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64272+ grsec_enable_tpe_all = 1;
64273+#endif
64274+#endif
64275+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64276+ grsec_enable_socket_all = 1;
64277+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
64278+#endif
64279+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64280+ grsec_enable_socket_client = 1;
64281+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
64282+#endif
64283+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64284+ grsec_enable_socket_server = 1;
64285+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
64286+#endif
64287+#endif
64288+
64289+ return;
64290+}
64291diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
64292new file mode 100644
64293index 0000000..5e05e20
64294--- /dev/null
64295+++ b/grsecurity/grsec_link.c
64296@@ -0,0 +1,58 @@
64297+#include <linux/kernel.h>
64298+#include <linux/sched.h>
64299+#include <linux/fs.h>
64300+#include <linux/file.h>
64301+#include <linux/grinternal.h>
64302+
64303+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
64304+{
64305+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64306+ const struct inode *link_inode = link->dentry->d_inode;
64307+
64308+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
64309+ /* ignore root-owned links, e.g. /proc/self */
64310+ gr_is_global_nonroot(link_inode->i_uid) && target &&
64311+ !uid_eq(link_inode->i_uid, target->i_uid)) {
64312+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
64313+ return 1;
64314+ }
64315+#endif
64316+ return 0;
64317+}
64318+
64319+int
64320+gr_handle_follow_link(const struct inode *parent,
64321+ const struct inode *inode,
64322+ const struct dentry *dentry, const struct vfsmount *mnt)
64323+{
64324+#ifdef CONFIG_GRKERNSEC_LINK
64325+ const struct cred *cred = current_cred();
64326+
64327+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
64328+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
64329+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
64330+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
64331+ return -EACCES;
64332+ }
64333+#endif
64334+ return 0;
64335+}
64336+
64337+int
64338+gr_handle_hardlink(const struct dentry *dentry,
64339+ const struct vfsmount *mnt,
64340+ struct inode *inode, const int mode, const struct filename *to)
64341+{
64342+#ifdef CONFIG_GRKERNSEC_LINK
64343+ const struct cred *cred = current_cred();
64344+
64345+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
64346+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
64347+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
64348+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
64349+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
64350+ return -EPERM;
64351+ }
64352+#endif
64353+ return 0;
64354+}
64355diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
64356new file mode 100644
64357index 0000000..7c06085
64358--- /dev/null
64359+++ b/grsecurity/grsec_log.c
64360@@ -0,0 +1,326 @@
64361+#include <linux/kernel.h>
64362+#include <linux/sched.h>
64363+#include <linux/file.h>
64364+#include <linux/tty.h>
64365+#include <linux/fs.h>
64366+#include <linux/grinternal.h>
64367+
64368+#ifdef CONFIG_TREE_PREEMPT_RCU
64369+#define DISABLE_PREEMPT() preempt_disable()
64370+#define ENABLE_PREEMPT() preempt_enable()
64371+#else
64372+#define DISABLE_PREEMPT()
64373+#define ENABLE_PREEMPT()
64374+#endif
64375+
64376+#define BEGIN_LOCKS(x) \
64377+ DISABLE_PREEMPT(); \
64378+ rcu_read_lock(); \
64379+ read_lock(&tasklist_lock); \
64380+ read_lock(&grsec_exec_file_lock); \
64381+ if (x != GR_DO_AUDIT) \
64382+ spin_lock(&grsec_alert_lock); \
64383+ else \
64384+ spin_lock(&grsec_audit_lock)
64385+
64386+#define END_LOCKS(x) \
64387+ if (x != GR_DO_AUDIT) \
64388+ spin_unlock(&grsec_alert_lock); \
64389+ else \
64390+ spin_unlock(&grsec_audit_lock); \
64391+ read_unlock(&grsec_exec_file_lock); \
64392+ read_unlock(&tasklist_lock); \
64393+ rcu_read_unlock(); \
64394+ ENABLE_PREEMPT(); \
64395+ if (x == GR_DONT_AUDIT) \
64396+ gr_handle_alertkill(current)
64397+
64398+enum {
64399+ FLOODING,
64400+ NO_FLOODING
64401+};
64402+
64403+extern char *gr_alert_log_fmt;
64404+extern char *gr_audit_log_fmt;
64405+extern char *gr_alert_log_buf;
64406+extern char *gr_audit_log_buf;
64407+
64408+static int gr_log_start(int audit)
64409+{
64410+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
64411+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
64412+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64413+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
64414+ unsigned long curr_secs = get_seconds();
64415+
64416+ if (audit == GR_DO_AUDIT)
64417+ goto set_fmt;
64418+
64419+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
64420+ grsec_alert_wtime = curr_secs;
64421+ grsec_alert_fyet = 0;
64422+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
64423+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
64424+ grsec_alert_fyet++;
64425+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
64426+ grsec_alert_wtime = curr_secs;
64427+ grsec_alert_fyet++;
64428+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
64429+ return FLOODING;
64430+ }
64431+ else return FLOODING;
64432+
64433+set_fmt:
64434+#endif
64435+ memset(buf, 0, PAGE_SIZE);
64436+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
64437+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
64438+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64439+ } else if (current->signal->curr_ip) {
64440+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
64441+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
64442+ } else if (gr_acl_is_enabled()) {
64443+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
64444+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64445+ } else {
64446+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
64447+ strcpy(buf, fmt);
64448+ }
64449+
64450+ return NO_FLOODING;
64451+}
64452+
64453+static void gr_log_middle(int audit, const char *msg, va_list ap)
64454+ __attribute__ ((format (printf, 2, 0)));
64455+
64456+static void gr_log_middle(int audit, const char *msg, va_list ap)
64457+{
64458+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64459+ unsigned int len = strlen(buf);
64460+
64461+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64462+
64463+ return;
64464+}
64465+
64466+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64467+ __attribute__ ((format (printf, 2, 3)));
64468+
64469+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64470+{
64471+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64472+ unsigned int len = strlen(buf);
64473+ va_list ap;
64474+
64475+ va_start(ap, msg);
64476+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64477+ va_end(ap);
64478+
64479+ return;
64480+}
64481+
64482+static void gr_log_end(int audit, int append_default)
64483+{
64484+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64485+ if (append_default) {
64486+ struct task_struct *task = current;
64487+ struct task_struct *parent = task->real_parent;
64488+ const struct cred *cred = __task_cred(task);
64489+ const struct cred *pcred = __task_cred(parent);
64490+ unsigned int len = strlen(buf);
64491+
64492+ 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));
64493+ }
64494+
64495+ printk("%s\n", buf);
64496+
64497+ return;
64498+}
64499+
64500+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
64501+{
64502+ int logtype;
64503+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
64504+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
64505+ void *voidptr = NULL;
64506+ int num1 = 0, num2 = 0;
64507+ unsigned long ulong1 = 0, ulong2 = 0;
64508+ struct dentry *dentry = NULL;
64509+ struct vfsmount *mnt = NULL;
64510+ struct file *file = NULL;
64511+ struct task_struct *task = NULL;
64512+ const struct cred *cred, *pcred;
64513+ va_list ap;
64514+
64515+ BEGIN_LOCKS(audit);
64516+ logtype = gr_log_start(audit);
64517+ if (logtype == FLOODING) {
64518+ END_LOCKS(audit);
64519+ return;
64520+ }
64521+ va_start(ap, argtypes);
64522+ switch (argtypes) {
64523+ case GR_TTYSNIFF:
64524+ task = va_arg(ap, struct task_struct *);
64525+ 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));
64526+ break;
64527+ case GR_SYSCTL_HIDDEN:
64528+ str1 = va_arg(ap, char *);
64529+ gr_log_middle_varargs(audit, msg, result, str1);
64530+ break;
64531+ case GR_RBAC:
64532+ dentry = va_arg(ap, struct dentry *);
64533+ mnt = va_arg(ap, struct vfsmount *);
64534+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
64535+ break;
64536+ case GR_RBAC_STR:
64537+ dentry = va_arg(ap, struct dentry *);
64538+ mnt = va_arg(ap, struct vfsmount *);
64539+ str1 = va_arg(ap, char *);
64540+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
64541+ break;
64542+ case GR_STR_RBAC:
64543+ str1 = va_arg(ap, char *);
64544+ dentry = va_arg(ap, struct dentry *);
64545+ mnt = va_arg(ap, struct vfsmount *);
64546+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
64547+ break;
64548+ case GR_RBAC_MODE2:
64549+ dentry = va_arg(ap, struct dentry *);
64550+ mnt = va_arg(ap, struct vfsmount *);
64551+ str1 = va_arg(ap, char *);
64552+ str2 = va_arg(ap, char *);
64553+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
64554+ break;
64555+ case GR_RBAC_MODE3:
64556+ dentry = va_arg(ap, struct dentry *);
64557+ mnt = va_arg(ap, struct vfsmount *);
64558+ str1 = va_arg(ap, char *);
64559+ str2 = va_arg(ap, char *);
64560+ str3 = va_arg(ap, char *);
64561+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
64562+ break;
64563+ case GR_FILENAME:
64564+ dentry = va_arg(ap, struct dentry *);
64565+ mnt = va_arg(ap, struct vfsmount *);
64566+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
64567+ break;
64568+ case GR_STR_FILENAME:
64569+ str1 = va_arg(ap, char *);
64570+ dentry = va_arg(ap, struct dentry *);
64571+ mnt = va_arg(ap, struct vfsmount *);
64572+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
64573+ break;
64574+ case GR_FILENAME_STR:
64575+ dentry = va_arg(ap, struct dentry *);
64576+ mnt = va_arg(ap, struct vfsmount *);
64577+ str1 = va_arg(ap, char *);
64578+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
64579+ break;
64580+ case GR_FILENAME_TWO_INT:
64581+ dentry = va_arg(ap, struct dentry *);
64582+ mnt = va_arg(ap, struct vfsmount *);
64583+ num1 = va_arg(ap, int);
64584+ num2 = va_arg(ap, int);
64585+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
64586+ break;
64587+ case GR_FILENAME_TWO_INT_STR:
64588+ dentry = va_arg(ap, struct dentry *);
64589+ mnt = va_arg(ap, struct vfsmount *);
64590+ num1 = va_arg(ap, int);
64591+ num2 = va_arg(ap, int);
64592+ str1 = va_arg(ap, char *);
64593+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
64594+ break;
64595+ case GR_TEXTREL:
64596+ file = va_arg(ap, struct file *);
64597+ ulong1 = va_arg(ap, unsigned long);
64598+ ulong2 = va_arg(ap, unsigned long);
64599+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
64600+ break;
64601+ case GR_PTRACE:
64602+ task = va_arg(ap, struct task_struct *);
64603+ 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));
64604+ break;
64605+ case GR_RESOURCE:
64606+ task = va_arg(ap, struct task_struct *);
64607+ cred = __task_cred(task);
64608+ pcred = __task_cred(task->real_parent);
64609+ ulong1 = va_arg(ap, unsigned long);
64610+ str1 = va_arg(ap, char *);
64611+ ulong2 = va_arg(ap, unsigned long);
64612+ 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));
64613+ break;
64614+ case GR_CAP:
64615+ task = va_arg(ap, struct task_struct *);
64616+ cred = __task_cred(task);
64617+ pcred = __task_cred(task->real_parent);
64618+ str1 = va_arg(ap, char *);
64619+ 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));
64620+ break;
64621+ case GR_SIG:
64622+ str1 = va_arg(ap, char *);
64623+ voidptr = va_arg(ap, void *);
64624+ gr_log_middle_varargs(audit, msg, str1, voidptr);
64625+ break;
64626+ case GR_SIG2:
64627+ task = va_arg(ap, struct task_struct *);
64628+ cred = __task_cred(task);
64629+ pcred = __task_cred(task->real_parent);
64630+ num1 = va_arg(ap, int);
64631+ 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));
64632+ break;
64633+ case GR_CRASH1:
64634+ task = va_arg(ap, struct task_struct *);
64635+ cred = __task_cred(task);
64636+ pcred = __task_cred(task->real_parent);
64637+ ulong1 = va_arg(ap, unsigned long);
64638+ 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);
64639+ break;
64640+ case GR_CRASH2:
64641+ task = va_arg(ap, struct task_struct *);
64642+ cred = __task_cred(task);
64643+ pcred = __task_cred(task->real_parent);
64644+ ulong1 = va_arg(ap, unsigned long);
64645+ 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);
64646+ break;
64647+ case GR_RWXMAP:
64648+ file = va_arg(ap, struct file *);
64649+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
64650+ break;
64651+ case GR_PSACCT:
64652+ {
64653+ unsigned int wday, cday;
64654+ __u8 whr, chr;
64655+ __u8 wmin, cmin;
64656+ __u8 wsec, csec;
64657+ char cur_tty[64] = { 0 };
64658+ char parent_tty[64] = { 0 };
64659+
64660+ task = va_arg(ap, struct task_struct *);
64661+ wday = va_arg(ap, unsigned int);
64662+ cday = va_arg(ap, unsigned int);
64663+ whr = va_arg(ap, int);
64664+ chr = va_arg(ap, int);
64665+ wmin = va_arg(ap, int);
64666+ cmin = va_arg(ap, int);
64667+ wsec = va_arg(ap, int);
64668+ csec = va_arg(ap, int);
64669+ ulong1 = va_arg(ap, unsigned long);
64670+ cred = __task_cred(task);
64671+ pcred = __task_cred(task->real_parent);
64672+
64673+ 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));
64674+ }
64675+ break;
64676+ default:
64677+ gr_log_middle(audit, msg, ap);
64678+ }
64679+ va_end(ap);
64680+ // these don't need DEFAULTSECARGS printed on the end
64681+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
64682+ gr_log_end(audit, 0);
64683+ else
64684+ gr_log_end(audit, 1);
64685+ END_LOCKS(audit);
64686+}
64687diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
64688new file mode 100644
64689index 0000000..f536303
64690--- /dev/null
64691+++ b/grsecurity/grsec_mem.c
64692@@ -0,0 +1,40 @@
64693+#include <linux/kernel.h>
64694+#include <linux/sched.h>
64695+#include <linux/mm.h>
64696+#include <linux/mman.h>
64697+#include <linux/grinternal.h>
64698+
64699+void
64700+gr_handle_ioperm(void)
64701+{
64702+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
64703+ return;
64704+}
64705+
64706+void
64707+gr_handle_iopl(void)
64708+{
64709+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
64710+ return;
64711+}
64712+
64713+void
64714+gr_handle_mem_readwrite(u64 from, u64 to)
64715+{
64716+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
64717+ return;
64718+}
64719+
64720+void
64721+gr_handle_vm86(void)
64722+{
64723+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
64724+ return;
64725+}
64726+
64727+void
64728+gr_log_badprocpid(const char *entry)
64729+{
64730+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
64731+ return;
64732+}
64733diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
64734new file mode 100644
64735index 0000000..2131422
64736--- /dev/null
64737+++ b/grsecurity/grsec_mount.c
64738@@ -0,0 +1,62 @@
64739+#include <linux/kernel.h>
64740+#include <linux/sched.h>
64741+#include <linux/mount.h>
64742+#include <linux/grsecurity.h>
64743+#include <linux/grinternal.h>
64744+
64745+void
64746+gr_log_remount(const char *devname, const int retval)
64747+{
64748+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64749+ if (grsec_enable_mount && (retval >= 0))
64750+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
64751+#endif
64752+ return;
64753+}
64754+
64755+void
64756+gr_log_unmount(const char *devname, const int retval)
64757+{
64758+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64759+ if (grsec_enable_mount && (retval >= 0))
64760+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
64761+#endif
64762+ return;
64763+}
64764+
64765+void
64766+gr_log_mount(const char *from, const char *to, const int retval)
64767+{
64768+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64769+ if (grsec_enable_mount && (retval >= 0))
64770+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
64771+#endif
64772+ return;
64773+}
64774+
64775+int
64776+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
64777+{
64778+#ifdef CONFIG_GRKERNSEC_ROFS
64779+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
64780+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
64781+ return -EPERM;
64782+ } else
64783+ return 0;
64784+#endif
64785+ return 0;
64786+}
64787+
64788+int
64789+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
64790+{
64791+#ifdef CONFIG_GRKERNSEC_ROFS
64792+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
64793+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
64794+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
64795+ return -EPERM;
64796+ } else
64797+ return 0;
64798+#endif
64799+ return 0;
64800+}
64801diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
64802new file mode 100644
64803index 0000000..a3b12a0
64804--- /dev/null
64805+++ b/grsecurity/grsec_pax.c
64806@@ -0,0 +1,36 @@
64807+#include <linux/kernel.h>
64808+#include <linux/sched.h>
64809+#include <linux/mm.h>
64810+#include <linux/file.h>
64811+#include <linux/grinternal.h>
64812+#include <linux/grsecurity.h>
64813+
64814+void
64815+gr_log_textrel(struct vm_area_struct * vma)
64816+{
64817+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64818+ if (grsec_enable_audit_textrel)
64819+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
64820+#endif
64821+ return;
64822+}
64823+
64824+void
64825+gr_log_rwxmmap(struct file *file)
64826+{
64827+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64828+ if (grsec_enable_log_rwxmaps)
64829+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
64830+#endif
64831+ return;
64832+}
64833+
64834+void
64835+gr_log_rwxmprotect(struct file *file)
64836+{
64837+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64838+ if (grsec_enable_log_rwxmaps)
64839+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
64840+#endif
64841+ return;
64842+}
64843diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
64844new file mode 100644
64845index 0000000..f7f29aa
64846--- /dev/null
64847+++ b/grsecurity/grsec_ptrace.c
64848@@ -0,0 +1,30 @@
64849+#include <linux/kernel.h>
64850+#include <linux/sched.h>
64851+#include <linux/grinternal.h>
64852+#include <linux/security.h>
64853+
64854+void
64855+gr_audit_ptrace(struct task_struct *task)
64856+{
64857+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64858+ if (grsec_enable_audit_ptrace)
64859+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
64860+#endif
64861+ return;
64862+}
64863+
64864+int
64865+gr_ptrace_readexec(struct file *file, int unsafe_flags)
64866+{
64867+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64868+ const struct dentry *dentry = file->f_path.dentry;
64869+ const struct vfsmount *mnt = file->f_path.mnt;
64870+
64871+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
64872+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
64873+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
64874+ return -EACCES;
64875+ }
64876+#endif
64877+ return 0;
64878+}
64879diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
64880new file mode 100644
64881index 0000000..e09715a
64882--- /dev/null
64883+++ b/grsecurity/grsec_sig.c
64884@@ -0,0 +1,222 @@
64885+#include <linux/kernel.h>
64886+#include <linux/sched.h>
64887+#include <linux/delay.h>
64888+#include <linux/grsecurity.h>
64889+#include <linux/grinternal.h>
64890+#include <linux/hardirq.h>
64891+
64892+char *signames[] = {
64893+ [SIGSEGV] = "Segmentation fault",
64894+ [SIGILL] = "Illegal instruction",
64895+ [SIGABRT] = "Abort",
64896+ [SIGBUS] = "Invalid alignment/Bus error"
64897+};
64898+
64899+void
64900+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
64901+{
64902+#ifdef CONFIG_GRKERNSEC_SIGNAL
64903+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
64904+ (sig == SIGABRT) || (sig == SIGBUS))) {
64905+ if (task_pid_nr(t) == task_pid_nr(current)) {
64906+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
64907+ } else {
64908+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
64909+ }
64910+ }
64911+#endif
64912+ return;
64913+}
64914+
64915+int
64916+gr_handle_signal(const struct task_struct *p, const int sig)
64917+{
64918+#ifdef CONFIG_GRKERNSEC
64919+ /* ignore the 0 signal for protected task checks */
64920+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
64921+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
64922+ return -EPERM;
64923+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
64924+ return -EPERM;
64925+ }
64926+#endif
64927+ return 0;
64928+}
64929+
64930+#ifdef CONFIG_GRKERNSEC
64931+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
64932+
64933+int gr_fake_force_sig(int sig, struct task_struct *t)
64934+{
64935+ unsigned long int flags;
64936+ int ret, blocked, ignored;
64937+ struct k_sigaction *action;
64938+
64939+ spin_lock_irqsave(&t->sighand->siglock, flags);
64940+ action = &t->sighand->action[sig-1];
64941+ ignored = action->sa.sa_handler == SIG_IGN;
64942+ blocked = sigismember(&t->blocked, sig);
64943+ if (blocked || ignored) {
64944+ action->sa.sa_handler = SIG_DFL;
64945+ if (blocked) {
64946+ sigdelset(&t->blocked, sig);
64947+ recalc_sigpending_and_wake(t);
64948+ }
64949+ }
64950+ if (action->sa.sa_handler == SIG_DFL)
64951+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
64952+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
64953+
64954+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
64955+
64956+ return ret;
64957+}
64958+#endif
64959+
64960+#ifdef CONFIG_GRKERNSEC_BRUTE
64961+#define GR_USER_BAN_TIME (15 * 60)
64962+#define GR_DAEMON_BRUTE_TIME (30 * 60)
64963+
64964+static int __get_dumpable(unsigned long mm_flags)
64965+{
64966+ int ret;
64967+
64968+ ret = mm_flags & MMF_DUMPABLE_MASK;
64969+ return (ret >= 2) ? 2 : ret;
64970+}
64971+#endif
64972+
64973+void gr_handle_brute_attach(unsigned long mm_flags)
64974+{
64975+#ifdef CONFIG_GRKERNSEC_BRUTE
64976+ struct task_struct *p = current;
64977+ kuid_t uid = GLOBAL_ROOT_UID;
64978+ int daemon = 0;
64979+
64980+ if (!grsec_enable_brute)
64981+ return;
64982+
64983+ rcu_read_lock();
64984+ read_lock(&tasklist_lock);
64985+ read_lock(&grsec_exec_file_lock);
64986+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
64987+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
64988+ p->real_parent->brute = 1;
64989+ daemon = 1;
64990+ } else {
64991+ const struct cred *cred = __task_cred(p), *cred2;
64992+ struct task_struct *tsk, *tsk2;
64993+
64994+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
64995+ struct user_struct *user;
64996+
64997+ uid = cred->uid;
64998+
64999+ /* this is put upon execution past expiration */
65000+ user = find_user(uid);
65001+ if (user == NULL)
65002+ goto unlock;
65003+ user->banned = 1;
65004+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
65005+ if (user->ban_expires == ~0UL)
65006+ user->ban_expires--;
65007+
65008+ do_each_thread(tsk2, tsk) {
65009+ cred2 = __task_cred(tsk);
65010+ if (tsk != p && uid_eq(cred2->uid, uid))
65011+ gr_fake_force_sig(SIGKILL, tsk);
65012+ } while_each_thread(tsk2, tsk);
65013+ }
65014+ }
65015+unlock:
65016+ read_unlock(&grsec_exec_file_lock);
65017+ read_unlock(&tasklist_lock);
65018+ rcu_read_unlock();
65019+
65020+ if (gr_is_global_nonroot(uid))
65021+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
65022+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
65023+ else if (daemon)
65024+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
65025+
65026+#endif
65027+ return;
65028+}
65029+
65030+void gr_handle_brute_check(void)
65031+{
65032+#ifdef CONFIG_GRKERNSEC_BRUTE
65033+ struct task_struct *p = current;
65034+
65035+ if (unlikely(p->brute)) {
65036+ if (!grsec_enable_brute)
65037+ p->brute = 0;
65038+ else if (time_before(get_seconds(), p->brute_expires))
65039+ msleep(30 * 1000);
65040+ }
65041+#endif
65042+ return;
65043+}
65044+
65045+void gr_handle_kernel_exploit(void)
65046+{
65047+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
65048+ const struct cred *cred;
65049+ struct task_struct *tsk, *tsk2;
65050+ struct user_struct *user;
65051+ kuid_t uid;
65052+
65053+ if (in_irq() || in_serving_softirq() || in_nmi())
65054+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
65055+
65056+ uid = current_uid();
65057+
65058+ if (gr_is_global_root(uid))
65059+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
65060+ else {
65061+ /* kill all the processes of this user, hold a reference
65062+ to their creds struct, and prevent them from creating
65063+ another process until system reset
65064+ */
65065+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
65066+ GR_GLOBAL_UID(uid));
65067+ /* we intentionally leak this ref */
65068+ user = get_uid(current->cred->user);
65069+ if (user) {
65070+ user->banned = 1;
65071+ user->ban_expires = ~0UL;
65072+ }
65073+
65074+ read_lock(&tasklist_lock);
65075+ do_each_thread(tsk2, tsk) {
65076+ cred = __task_cred(tsk);
65077+ if (uid_eq(cred->uid, uid))
65078+ gr_fake_force_sig(SIGKILL, tsk);
65079+ } while_each_thread(tsk2, tsk);
65080+ read_unlock(&tasklist_lock);
65081+ }
65082+#endif
65083+}
65084+
65085+int __gr_process_user_ban(struct user_struct *user)
65086+{
65087+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65088+ if (unlikely(user->banned)) {
65089+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
65090+ user->banned = 0;
65091+ user->ban_expires = 0;
65092+ free_uid(user);
65093+ } else
65094+ return -EPERM;
65095+ }
65096+#endif
65097+ return 0;
65098+}
65099+
65100+int gr_process_user_ban(void)
65101+{
65102+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65103+ return __gr_process_user_ban(current->cred->user);
65104+#endif
65105+ return 0;
65106+}
65107diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
65108new file mode 100644
65109index 0000000..4030d57
65110--- /dev/null
65111+++ b/grsecurity/grsec_sock.c
65112@@ -0,0 +1,244 @@
65113+#include <linux/kernel.h>
65114+#include <linux/module.h>
65115+#include <linux/sched.h>
65116+#include <linux/file.h>
65117+#include <linux/net.h>
65118+#include <linux/in.h>
65119+#include <linux/ip.h>
65120+#include <net/sock.h>
65121+#include <net/inet_sock.h>
65122+#include <linux/grsecurity.h>
65123+#include <linux/grinternal.h>
65124+#include <linux/gracl.h>
65125+
65126+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
65127+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
65128+
65129+EXPORT_SYMBOL(gr_search_udp_recvmsg);
65130+EXPORT_SYMBOL(gr_search_udp_sendmsg);
65131+
65132+#ifdef CONFIG_UNIX_MODULE
65133+EXPORT_SYMBOL(gr_acl_handle_unix);
65134+EXPORT_SYMBOL(gr_acl_handle_mknod);
65135+EXPORT_SYMBOL(gr_handle_chroot_unix);
65136+EXPORT_SYMBOL(gr_handle_create);
65137+#endif
65138+
65139+#ifdef CONFIG_GRKERNSEC
65140+#define gr_conn_table_size 32749
65141+struct conn_table_entry {
65142+ struct conn_table_entry *next;
65143+ struct signal_struct *sig;
65144+};
65145+
65146+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
65147+DEFINE_SPINLOCK(gr_conn_table_lock);
65148+
65149+extern const char * gr_socktype_to_name(unsigned char type);
65150+extern const char * gr_proto_to_name(unsigned char proto);
65151+extern const char * gr_sockfamily_to_name(unsigned char family);
65152+
65153+static __inline__ int
65154+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
65155+{
65156+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
65157+}
65158+
65159+static __inline__ int
65160+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
65161+ __u16 sport, __u16 dport)
65162+{
65163+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
65164+ sig->gr_sport == sport && sig->gr_dport == dport))
65165+ return 1;
65166+ else
65167+ return 0;
65168+}
65169+
65170+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
65171+{
65172+ struct conn_table_entry **match;
65173+ unsigned int index;
65174+
65175+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65176+ sig->gr_sport, sig->gr_dport,
65177+ gr_conn_table_size);
65178+
65179+ newent->sig = sig;
65180+
65181+ match = &gr_conn_table[index];
65182+ newent->next = *match;
65183+ *match = newent;
65184+
65185+ return;
65186+}
65187+
65188+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
65189+{
65190+ struct conn_table_entry *match, *last = NULL;
65191+ unsigned int index;
65192+
65193+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65194+ sig->gr_sport, sig->gr_dport,
65195+ gr_conn_table_size);
65196+
65197+ match = gr_conn_table[index];
65198+ while (match && !conn_match(match->sig,
65199+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
65200+ sig->gr_dport)) {
65201+ last = match;
65202+ match = match->next;
65203+ }
65204+
65205+ if (match) {
65206+ if (last)
65207+ last->next = match->next;
65208+ else
65209+ gr_conn_table[index] = NULL;
65210+ kfree(match);
65211+ }
65212+
65213+ return;
65214+}
65215+
65216+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
65217+ __u16 sport, __u16 dport)
65218+{
65219+ struct conn_table_entry *match;
65220+ unsigned int index;
65221+
65222+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
65223+
65224+ match = gr_conn_table[index];
65225+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
65226+ match = match->next;
65227+
65228+ if (match)
65229+ return match->sig;
65230+ else
65231+ return NULL;
65232+}
65233+
65234+#endif
65235+
65236+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
65237+{
65238+#ifdef CONFIG_GRKERNSEC
65239+ struct signal_struct *sig = task->signal;
65240+ struct conn_table_entry *newent;
65241+
65242+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
65243+ if (newent == NULL)
65244+ return;
65245+ /* no bh lock needed since we are called with bh disabled */
65246+ spin_lock(&gr_conn_table_lock);
65247+ gr_del_task_from_ip_table_nolock(sig);
65248+ sig->gr_saddr = inet->inet_rcv_saddr;
65249+ sig->gr_daddr = inet->inet_daddr;
65250+ sig->gr_sport = inet->inet_sport;
65251+ sig->gr_dport = inet->inet_dport;
65252+ gr_add_to_task_ip_table_nolock(sig, newent);
65253+ spin_unlock(&gr_conn_table_lock);
65254+#endif
65255+ return;
65256+}
65257+
65258+void gr_del_task_from_ip_table(struct task_struct *task)
65259+{
65260+#ifdef CONFIG_GRKERNSEC
65261+ spin_lock_bh(&gr_conn_table_lock);
65262+ gr_del_task_from_ip_table_nolock(task->signal);
65263+ spin_unlock_bh(&gr_conn_table_lock);
65264+#endif
65265+ return;
65266+}
65267+
65268+void
65269+gr_attach_curr_ip(const struct sock *sk)
65270+{
65271+#ifdef CONFIG_GRKERNSEC
65272+ struct signal_struct *p, *set;
65273+ const struct inet_sock *inet = inet_sk(sk);
65274+
65275+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
65276+ return;
65277+
65278+ set = current->signal;
65279+
65280+ spin_lock_bh(&gr_conn_table_lock);
65281+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
65282+ inet->inet_dport, inet->inet_sport);
65283+ if (unlikely(p != NULL)) {
65284+ set->curr_ip = p->curr_ip;
65285+ set->used_accept = 1;
65286+ gr_del_task_from_ip_table_nolock(p);
65287+ spin_unlock_bh(&gr_conn_table_lock);
65288+ return;
65289+ }
65290+ spin_unlock_bh(&gr_conn_table_lock);
65291+
65292+ set->curr_ip = inet->inet_daddr;
65293+ set->used_accept = 1;
65294+#endif
65295+ return;
65296+}
65297+
65298+int
65299+gr_handle_sock_all(const int family, const int type, const int protocol)
65300+{
65301+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65302+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
65303+ (family != AF_UNIX)) {
65304+ if (family == AF_INET)
65305+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
65306+ else
65307+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
65308+ return -EACCES;
65309+ }
65310+#endif
65311+ return 0;
65312+}
65313+
65314+int
65315+gr_handle_sock_server(const struct sockaddr *sck)
65316+{
65317+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65318+ if (grsec_enable_socket_server &&
65319+ in_group_p(grsec_socket_server_gid) &&
65320+ sck && (sck->sa_family != AF_UNIX) &&
65321+ (sck->sa_family != AF_LOCAL)) {
65322+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65323+ return -EACCES;
65324+ }
65325+#endif
65326+ return 0;
65327+}
65328+
65329+int
65330+gr_handle_sock_server_other(const struct sock *sck)
65331+{
65332+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65333+ if (grsec_enable_socket_server &&
65334+ in_group_p(grsec_socket_server_gid) &&
65335+ sck && (sck->sk_family != AF_UNIX) &&
65336+ (sck->sk_family != AF_LOCAL)) {
65337+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65338+ return -EACCES;
65339+ }
65340+#endif
65341+ return 0;
65342+}
65343+
65344+int
65345+gr_handle_sock_client(const struct sockaddr *sck)
65346+{
65347+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65348+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
65349+ sck && (sck->sa_family != AF_UNIX) &&
65350+ (sck->sa_family != AF_LOCAL)) {
65351+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
65352+ return -EACCES;
65353+ }
65354+#endif
65355+ return 0;
65356+}
65357diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
65358new file mode 100644
65359index 0000000..f55ef0f
65360--- /dev/null
65361+++ b/grsecurity/grsec_sysctl.c
65362@@ -0,0 +1,469 @@
65363+#include <linux/kernel.h>
65364+#include <linux/sched.h>
65365+#include <linux/sysctl.h>
65366+#include <linux/grsecurity.h>
65367+#include <linux/grinternal.h>
65368+
65369+int
65370+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
65371+{
65372+#ifdef CONFIG_GRKERNSEC_SYSCTL
65373+ if (dirname == NULL || name == NULL)
65374+ return 0;
65375+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
65376+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
65377+ return -EACCES;
65378+ }
65379+#endif
65380+ return 0;
65381+}
65382+
65383+#ifdef CONFIG_GRKERNSEC_ROFS
65384+static int __maybe_unused one = 1;
65385+#endif
65386+
65387+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
65388+struct ctl_table grsecurity_table[] = {
65389+#ifdef CONFIG_GRKERNSEC_SYSCTL
65390+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
65391+#ifdef CONFIG_GRKERNSEC_IO
65392+ {
65393+ .procname = "disable_priv_io",
65394+ .data = &grsec_disable_privio,
65395+ .maxlen = sizeof(int),
65396+ .mode = 0600,
65397+ .proc_handler = &proc_dointvec,
65398+ },
65399+#endif
65400+#endif
65401+#ifdef CONFIG_GRKERNSEC_LINK
65402+ {
65403+ .procname = "linking_restrictions",
65404+ .data = &grsec_enable_link,
65405+ .maxlen = sizeof(int),
65406+ .mode = 0600,
65407+ .proc_handler = &proc_dointvec,
65408+ },
65409+#endif
65410+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65411+ {
65412+ .procname = "enforce_symlinksifowner",
65413+ .data = &grsec_enable_symlinkown,
65414+ .maxlen = sizeof(int),
65415+ .mode = 0600,
65416+ .proc_handler = &proc_dointvec,
65417+ },
65418+ {
65419+ .procname = "symlinkown_gid",
65420+ .data = &grsec_symlinkown_gid,
65421+ .maxlen = sizeof(int),
65422+ .mode = 0600,
65423+ .proc_handler = &proc_dointvec,
65424+ },
65425+#endif
65426+#ifdef CONFIG_GRKERNSEC_BRUTE
65427+ {
65428+ .procname = "deter_bruteforce",
65429+ .data = &grsec_enable_brute,
65430+ .maxlen = sizeof(int),
65431+ .mode = 0600,
65432+ .proc_handler = &proc_dointvec,
65433+ },
65434+#endif
65435+#ifdef CONFIG_GRKERNSEC_FIFO
65436+ {
65437+ .procname = "fifo_restrictions",
65438+ .data = &grsec_enable_fifo,
65439+ .maxlen = sizeof(int),
65440+ .mode = 0600,
65441+ .proc_handler = &proc_dointvec,
65442+ },
65443+#endif
65444+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65445+ {
65446+ .procname = "ptrace_readexec",
65447+ .data = &grsec_enable_ptrace_readexec,
65448+ .maxlen = sizeof(int),
65449+ .mode = 0600,
65450+ .proc_handler = &proc_dointvec,
65451+ },
65452+#endif
65453+#ifdef CONFIG_GRKERNSEC_SETXID
65454+ {
65455+ .procname = "consistent_setxid",
65456+ .data = &grsec_enable_setxid,
65457+ .maxlen = sizeof(int),
65458+ .mode = 0600,
65459+ .proc_handler = &proc_dointvec,
65460+ },
65461+#endif
65462+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65463+ {
65464+ .procname = "ip_blackhole",
65465+ .data = &grsec_enable_blackhole,
65466+ .maxlen = sizeof(int),
65467+ .mode = 0600,
65468+ .proc_handler = &proc_dointvec,
65469+ },
65470+ {
65471+ .procname = "lastack_retries",
65472+ .data = &grsec_lastack_retries,
65473+ .maxlen = sizeof(int),
65474+ .mode = 0600,
65475+ .proc_handler = &proc_dointvec,
65476+ },
65477+#endif
65478+#ifdef CONFIG_GRKERNSEC_EXECLOG
65479+ {
65480+ .procname = "exec_logging",
65481+ .data = &grsec_enable_execlog,
65482+ .maxlen = sizeof(int),
65483+ .mode = 0600,
65484+ .proc_handler = &proc_dointvec,
65485+ },
65486+#endif
65487+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65488+ {
65489+ .procname = "rwxmap_logging",
65490+ .data = &grsec_enable_log_rwxmaps,
65491+ .maxlen = sizeof(int),
65492+ .mode = 0600,
65493+ .proc_handler = &proc_dointvec,
65494+ },
65495+#endif
65496+#ifdef CONFIG_GRKERNSEC_SIGNAL
65497+ {
65498+ .procname = "signal_logging",
65499+ .data = &grsec_enable_signal,
65500+ .maxlen = sizeof(int),
65501+ .mode = 0600,
65502+ .proc_handler = &proc_dointvec,
65503+ },
65504+#endif
65505+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65506+ {
65507+ .procname = "forkfail_logging",
65508+ .data = &grsec_enable_forkfail,
65509+ .maxlen = sizeof(int),
65510+ .mode = 0600,
65511+ .proc_handler = &proc_dointvec,
65512+ },
65513+#endif
65514+#ifdef CONFIG_GRKERNSEC_TIME
65515+ {
65516+ .procname = "timechange_logging",
65517+ .data = &grsec_enable_time,
65518+ .maxlen = sizeof(int),
65519+ .mode = 0600,
65520+ .proc_handler = &proc_dointvec,
65521+ },
65522+#endif
65523+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65524+ {
65525+ .procname = "chroot_deny_shmat",
65526+ .data = &grsec_enable_chroot_shmat,
65527+ .maxlen = sizeof(int),
65528+ .mode = 0600,
65529+ .proc_handler = &proc_dointvec,
65530+ },
65531+#endif
65532+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65533+ {
65534+ .procname = "chroot_deny_unix",
65535+ .data = &grsec_enable_chroot_unix,
65536+ .maxlen = sizeof(int),
65537+ .mode = 0600,
65538+ .proc_handler = &proc_dointvec,
65539+ },
65540+#endif
65541+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65542+ {
65543+ .procname = "chroot_deny_mount",
65544+ .data = &grsec_enable_chroot_mount,
65545+ .maxlen = sizeof(int),
65546+ .mode = 0600,
65547+ .proc_handler = &proc_dointvec,
65548+ },
65549+#endif
65550+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65551+ {
65552+ .procname = "chroot_deny_fchdir",
65553+ .data = &grsec_enable_chroot_fchdir,
65554+ .maxlen = sizeof(int),
65555+ .mode = 0600,
65556+ .proc_handler = &proc_dointvec,
65557+ },
65558+#endif
65559+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65560+ {
65561+ .procname = "chroot_deny_chroot",
65562+ .data = &grsec_enable_chroot_double,
65563+ .maxlen = sizeof(int),
65564+ .mode = 0600,
65565+ .proc_handler = &proc_dointvec,
65566+ },
65567+#endif
65568+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65569+ {
65570+ .procname = "chroot_deny_pivot",
65571+ .data = &grsec_enable_chroot_pivot,
65572+ .maxlen = sizeof(int),
65573+ .mode = 0600,
65574+ .proc_handler = &proc_dointvec,
65575+ },
65576+#endif
65577+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65578+ {
65579+ .procname = "chroot_enforce_chdir",
65580+ .data = &grsec_enable_chroot_chdir,
65581+ .maxlen = sizeof(int),
65582+ .mode = 0600,
65583+ .proc_handler = &proc_dointvec,
65584+ },
65585+#endif
65586+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65587+ {
65588+ .procname = "chroot_deny_chmod",
65589+ .data = &grsec_enable_chroot_chmod,
65590+ .maxlen = sizeof(int),
65591+ .mode = 0600,
65592+ .proc_handler = &proc_dointvec,
65593+ },
65594+#endif
65595+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65596+ {
65597+ .procname = "chroot_deny_mknod",
65598+ .data = &grsec_enable_chroot_mknod,
65599+ .maxlen = sizeof(int),
65600+ .mode = 0600,
65601+ .proc_handler = &proc_dointvec,
65602+ },
65603+#endif
65604+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65605+ {
65606+ .procname = "chroot_restrict_nice",
65607+ .data = &grsec_enable_chroot_nice,
65608+ .maxlen = sizeof(int),
65609+ .mode = 0600,
65610+ .proc_handler = &proc_dointvec,
65611+ },
65612+#endif
65613+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65614+ {
65615+ .procname = "chroot_execlog",
65616+ .data = &grsec_enable_chroot_execlog,
65617+ .maxlen = sizeof(int),
65618+ .mode = 0600,
65619+ .proc_handler = &proc_dointvec,
65620+ },
65621+#endif
65622+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65623+ {
65624+ .procname = "chroot_caps",
65625+ .data = &grsec_enable_chroot_caps,
65626+ .maxlen = sizeof(int),
65627+ .mode = 0600,
65628+ .proc_handler = &proc_dointvec,
65629+ },
65630+#endif
65631+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65632+ {
65633+ .procname = "chroot_deny_sysctl",
65634+ .data = &grsec_enable_chroot_sysctl,
65635+ .maxlen = sizeof(int),
65636+ .mode = 0600,
65637+ .proc_handler = &proc_dointvec,
65638+ },
65639+#endif
65640+#ifdef CONFIG_GRKERNSEC_TPE
65641+ {
65642+ .procname = "tpe",
65643+ .data = &grsec_enable_tpe,
65644+ .maxlen = sizeof(int),
65645+ .mode = 0600,
65646+ .proc_handler = &proc_dointvec,
65647+ },
65648+ {
65649+ .procname = "tpe_gid",
65650+ .data = &grsec_tpe_gid,
65651+ .maxlen = sizeof(int),
65652+ .mode = 0600,
65653+ .proc_handler = &proc_dointvec,
65654+ },
65655+#endif
65656+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65657+ {
65658+ .procname = "tpe_invert",
65659+ .data = &grsec_enable_tpe_invert,
65660+ .maxlen = sizeof(int),
65661+ .mode = 0600,
65662+ .proc_handler = &proc_dointvec,
65663+ },
65664+#endif
65665+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65666+ {
65667+ .procname = "tpe_restrict_all",
65668+ .data = &grsec_enable_tpe_all,
65669+ .maxlen = sizeof(int),
65670+ .mode = 0600,
65671+ .proc_handler = &proc_dointvec,
65672+ },
65673+#endif
65674+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65675+ {
65676+ .procname = "socket_all",
65677+ .data = &grsec_enable_socket_all,
65678+ .maxlen = sizeof(int),
65679+ .mode = 0600,
65680+ .proc_handler = &proc_dointvec,
65681+ },
65682+ {
65683+ .procname = "socket_all_gid",
65684+ .data = &grsec_socket_all_gid,
65685+ .maxlen = sizeof(int),
65686+ .mode = 0600,
65687+ .proc_handler = &proc_dointvec,
65688+ },
65689+#endif
65690+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65691+ {
65692+ .procname = "socket_client",
65693+ .data = &grsec_enable_socket_client,
65694+ .maxlen = sizeof(int),
65695+ .mode = 0600,
65696+ .proc_handler = &proc_dointvec,
65697+ },
65698+ {
65699+ .procname = "socket_client_gid",
65700+ .data = &grsec_socket_client_gid,
65701+ .maxlen = sizeof(int),
65702+ .mode = 0600,
65703+ .proc_handler = &proc_dointvec,
65704+ },
65705+#endif
65706+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65707+ {
65708+ .procname = "socket_server",
65709+ .data = &grsec_enable_socket_server,
65710+ .maxlen = sizeof(int),
65711+ .mode = 0600,
65712+ .proc_handler = &proc_dointvec,
65713+ },
65714+ {
65715+ .procname = "socket_server_gid",
65716+ .data = &grsec_socket_server_gid,
65717+ .maxlen = sizeof(int),
65718+ .mode = 0600,
65719+ .proc_handler = &proc_dointvec,
65720+ },
65721+#endif
65722+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65723+ {
65724+ .procname = "audit_group",
65725+ .data = &grsec_enable_group,
65726+ .maxlen = sizeof(int),
65727+ .mode = 0600,
65728+ .proc_handler = &proc_dointvec,
65729+ },
65730+ {
65731+ .procname = "audit_gid",
65732+ .data = &grsec_audit_gid,
65733+ .maxlen = sizeof(int),
65734+ .mode = 0600,
65735+ .proc_handler = &proc_dointvec,
65736+ },
65737+#endif
65738+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65739+ {
65740+ .procname = "audit_chdir",
65741+ .data = &grsec_enable_chdir,
65742+ .maxlen = sizeof(int),
65743+ .mode = 0600,
65744+ .proc_handler = &proc_dointvec,
65745+ },
65746+#endif
65747+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65748+ {
65749+ .procname = "audit_mount",
65750+ .data = &grsec_enable_mount,
65751+ .maxlen = sizeof(int),
65752+ .mode = 0600,
65753+ .proc_handler = &proc_dointvec,
65754+ },
65755+#endif
65756+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65757+ {
65758+ .procname = "audit_textrel",
65759+ .data = &grsec_enable_audit_textrel,
65760+ .maxlen = sizeof(int),
65761+ .mode = 0600,
65762+ .proc_handler = &proc_dointvec,
65763+ },
65764+#endif
65765+#ifdef CONFIG_GRKERNSEC_DMESG
65766+ {
65767+ .procname = "dmesg",
65768+ .data = &grsec_enable_dmesg,
65769+ .maxlen = sizeof(int),
65770+ .mode = 0600,
65771+ .proc_handler = &proc_dointvec,
65772+ },
65773+#endif
65774+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65775+ {
65776+ .procname = "chroot_findtask",
65777+ .data = &grsec_enable_chroot_findtask,
65778+ .maxlen = sizeof(int),
65779+ .mode = 0600,
65780+ .proc_handler = &proc_dointvec,
65781+ },
65782+#endif
65783+#ifdef CONFIG_GRKERNSEC_RESLOG
65784+ {
65785+ .procname = "resource_logging",
65786+ .data = &grsec_resource_logging,
65787+ .maxlen = sizeof(int),
65788+ .mode = 0600,
65789+ .proc_handler = &proc_dointvec,
65790+ },
65791+#endif
65792+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65793+ {
65794+ .procname = "audit_ptrace",
65795+ .data = &grsec_enable_audit_ptrace,
65796+ .maxlen = sizeof(int),
65797+ .mode = 0600,
65798+ .proc_handler = &proc_dointvec,
65799+ },
65800+#endif
65801+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65802+ {
65803+ .procname = "harden_ptrace",
65804+ .data = &grsec_enable_harden_ptrace,
65805+ .maxlen = sizeof(int),
65806+ .mode = 0600,
65807+ .proc_handler = &proc_dointvec,
65808+ },
65809+#endif
65810+ {
65811+ .procname = "grsec_lock",
65812+ .data = &grsec_lock,
65813+ .maxlen = sizeof(int),
65814+ .mode = 0600,
65815+ .proc_handler = &proc_dointvec,
65816+ },
65817+#endif
65818+#ifdef CONFIG_GRKERNSEC_ROFS
65819+ {
65820+ .procname = "romount_protect",
65821+ .data = &grsec_enable_rofs,
65822+ .maxlen = sizeof(int),
65823+ .mode = 0600,
65824+ .proc_handler = &proc_dointvec_minmax,
65825+ .extra1 = &one,
65826+ .extra2 = &one,
65827+ },
65828+#endif
65829+ { }
65830+};
65831+#endif
65832diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
65833new file mode 100644
65834index 0000000..0dc13c3
65835--- /dev/null
65836+++ b/grsecurity/grsec_time.c
65837@@ -0,0 +1,16 @@
65838+#include <linux/kernel.h>
65839+#include <linux/sched.h>
65840+#include <linux/grinternal.h>
65841+#include <linux/module.h>
65842+
65843+void
65844+gr_log_timechange(void)
65845+{
65846+#ifdef CONFIG_GRKERNSEC_TIME
65847+ if (grsec_enable_time)
65848+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
65849+#endif
65850+ return;
65851+}
65852+
65853+EXPORT_SYMBOL(gr_log_timechange);
65854diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
65855new file mode 100644
65856index 0000000..ee57dcf
65857--- /dev/null
65858+++ b/grsecurity/grsec_tpe.c
65859@@ -0,0 +1,73 @@
65860+#include <linux/kernel.h>
65861+#include <linux/sched.h>
65862+#include <linux/file.h>
65863+#include <linux/fs.h>
65864+#include <linux/grinternal.h>
65865+
65866+extern int gr_acl_tpe_check(void);
65867+
65868+int
65869+gr_tpe_allow(const struct file *file)
65870+{
65871+#ifdef CONFIG_GRKERNSEC
65872+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
65873+ const struct cred *cred = current_cred();
65874+ char *msg = NULL;
65875+ char *msg2 = NULL;
65876+
65877+ // never restrict root
65878+ if (gr_is_global_root(cred->uid))
65879+ return 1;
65880+
65881+ if (grsec_enable_tpe) {
65882+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65883+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
65884+ msg = "not being in trusted group";
65885+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
65886+ msg = "being in untrusted group";
65887+#else
65888+ if (in_group_p(grsec_tpe_gid))
65889+ msg = "being in untrusted group";
65890+#endif
65891+ }
65892+ if (!msg && gr_acl_tpe_check())
65893+ msg = "being in untrusted role";
65894+
65895+ // not in any affected group/role
65896+ if (!msg)
65897+ goto next_check;
65898+
65899+ if (gr_is_global_nonroot(inode->i_uid))
65900+ msg2 = "file in non-root-owned directory";
65901+ else if (inode->i_mode & S_IWOTH)
65902+ msg2 = "file in world-writable directory";
65903+ else if (inode->i_mode & S_IWGRP)
65904+ msg2 = "file in group-writable directory";
65905+
65906+ if (msg && msg2) {
65907+ char fullmsg[70] = {0};
65908+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
65909+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
65910+ return 0;
65911+ }
65912+ msg = NULL;
65913+next_check:
65914+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65915+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
65916+ return 1;
65917+
65918+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
65919+ msg = "directory not owned by user";
65920+ else if (inode->i_mode & S_IWOTH)
65921+ msg = "file in world-writable directory";
65922+ else if (inode->i_mode & S_IWGRP)
65923+ msg = "file in group-writable directory";
65924+
65925+ if (msg) {
65926+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
65927+ return 0;
65928+ }
65929+#endif
65930+#endif
65931+ return 1;
65932+}
65933diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
65934new file mode 100644
65935index 0000000..9f7b1ac
65936--- /dev/null
65937+++ b/grsecurity/grsum.c
65938@@ -0,0 +1,61 @@
65939+#include <linux/err.h>
65940+#include <linux/kernel.h>
65941+#include <linux/sched.h>
65942+#include <linux/mm.h>
65943+#include <linux/scatterlist.h>
65944+#include <linux/crypto.h>
65945+#include <linux/gracl.h>
65946+
65947+
65948+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
65949+#error "crypto and sha256 must be built into the kernel"
65950+#endif
65951+
65952+int
65953+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
65954+{
65955+ char *p;
65956+ struct crypto_hash *tfm;
65957+ struct hash_desc desc;
65958+ struct scatterlist sg;
65959+ unsigned char temp_sum[GR_SHA_LEN];
65960+ volatile int retval = 0;
65961+ volatile int dummy = 0;
65962+ unsigned int i;
65963+
65964+ sg_init_table(&sg, 1);
65965+
65966+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
65967+ if (IS_ERR(tfm)) {
65968+ /* should never happen, since sha256 should be built in */
65969+ return 1;
65970+ }
65971+
65972+ desc.tfm = tfm;
65973+ desc.flags = 0;
65974+
65975+ crypto_hash_init(&desc);
65976+
65977+ p = salt;
65978+ sg_set_buf(&sg, p, GR_SALT_LEN);
65979+ crypto_hash_update(&desc, &sg, sg.length);
65980+
65981+ p = entry->pw;
65982+ sg_set_buf(&sg, p, strlen(p));
65983+
65984+ crypto_hash_update(&desc, &sg, sg.length);
65985+
65986+ crypto_hash_final(&desc, temp_sum);
65987+
65988+ memset(entry->pw, 0, GR_PW_LEN);
65989+
65990+ for (i = 0; i < GR_SHA_LEN; i++)
65991+ if (sum[i] != temp_sum[i])
65992+ retval = 1;
65993+ else
65994+ dummy = 1; // waste a cycle
65995+
65996+ crypto_free_hash(tfm);
65997+
65998+ return retval;
65999+}
66000diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
66001index 77ff547..181834f 100644
66002--- a/include/asm-generic/4level-fixup.h
66003+++ b/include/asm-generic/4level-fixup.h
66004@@ -13,8 +13,10 @@
66005 #define pmd_alloc(mm, pud, address) \
66006 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
66007 NULL: pmd_offset(pud, address))
66008+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
66009
66010 #define pud_alloc(mm, pgd, address) (pgd)
66011+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
66012 #define pud_offset(pgd, start) (pgd)
66013 #define pud_none(pud) 0
66014 #define pud_bad(pud) 0
66015diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
66016index b7babf0..04ad282 100644
66017--- a/include/asm-generic/atomic-long.h
66018+++ b/include/asm-generic/atomic-long.h
66019@@ -22,6 +22,12 @@
66020
66021 typedef atomic64_t atomic_long_t;
66022
66023+#ifdef CONFIG_PAX_REFCOUNT
66024+typedef atomic64_unchecked_t atomic_long_unchecked_t;
66025+#else
66026+typedef atomic64_t atomic_long_unchecked_t;
66027+#endif
66028+
66029 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
66030
66031 static inline long atomic_long_read(atomic_long_t *l)
66032@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66033 return (long)atomic64_read(v);
66034 }
66035
66036+#ifdef CONFIG_PAX_REFCOUNT
66037+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66038+{
66039+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66040+
66041+ return (long)atomic64_read_unchecked(v);
66042+}
66043+#endif
66044+
66045 static inline void atomic_long_set(atomic_long_t *l, long i)
66046 {
66047 atomic64_t *v = (atomic64_t *)l;
66048@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66049 atomic64_set(v, i);
66050 }
66051
66052+#ifdef CONFIG_PAX_REFCOUNT
66053+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66054+{
66055+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66056+
66057+ atomic64_set_unchecked(v, i);
66058+}
66059+#endif
66060+
66061 static inline void atomic_long_inc(atomic_long_t *l)
66062 {
66063 atomic64_t *v = (atomic64_t *)l;
66064@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66065 atomic64_inc(v);
66066 }
66067
66068+#ifdef CONFIG_PAX_REFCOUNT
66069+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66070+{
66071+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66072+
66073+ atomic64_inc_unchecked(v);
66074+}
66075+#endif
66076+
66077 static inline void atomic_long_dec(atomic_long_t *l)
66078 {
66079 atomic64_t *v = (atomic64_t *)l;
66080@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66081 atomic64_dec(v);
66082 }
66083
66084+#ifdef CONFIG_PAX_REFCOUNT
66085+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66086+{
66087+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66088+
66089+ atomic64_dec_unchecked(v);
66090+}
66091+#endif
66092+
66093 static inline void atomic_long_add(long i, atomic_long_t *l)
66094 {
66095 atomic64_t *v = (atomic64_t *)l;
66096@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66097 atomic64_add(i, v);
66098 }
66099
66100+#ifdef CONFIG_PAX_REFCOUNT
66101+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66102+{
66103+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66104+
66105+ atomic64_add_unchecked(i, v);
66106+}
66107+#endif
66108+
66109 static inline void atomic_long_sub(long i, atomic_long_t *l)
66110 {
66111 atomic64_t *v = (atomic64_t *)l;
66112@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66113 atomic64_sub(i, v);
66114 }
66115
66116+#ifdef CONFIG_PAX_REFCOUNT
66117+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66118+{
66119+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66120+
66121+ atomic64_sub_unchecked(i, v);
66122+}
66123+#endif
66124+
66125 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66126 {
66127 atomic64_t *v = (atomic64_t *)l;
66128@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66129 return (long)atomic64_add_return(i, v);
66130 }
66131
66132+#ifdef CONFIG_PAX_REFCOUNT
66133+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66134+{
66135+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66136+
66137+ return (long)atomic64_add_return_unchecked(i, v);
66138+}
66139+#endif
66140+
66141 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66142 {
66143 atomic64_t *v = (atomic64_t *)l;
66144@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66145 return (long)atomic64_inc_return(v);
66146 }
66147
66148+#ifdef CONFIG_PAX_REFCOUNT
66149+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66150+{
66151+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66152+
66153+ return (long)atomic64_inc_return_unchecked(v);
66154+}
66155+#endif
66156+
66157 static inline long atomic_long_dec_return(atomic_long_t *l)
66158 {
66159 atomic64_t *v = (atomic64_t *)l;
66160@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66161
66162 typedef atomic_t atomic_long_t;
66163
66164+#ifdef CONFIG_PAX_REFCOUNT
66165+typedef atomic_unchecked_t atomic_long_unchecked_t;
66166+#else
66167+typedef atomic_t atomic_long_unchecked_t;
66168+#endif
66169+
66170 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
66171 static inline long atomic_long_read(atomic_long_t *l)
66172 {
66173@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66174 return (long)atomic_read(v);
66175 }
66176
66177+#ifdef CONFIG_PAX_REFCOUNT
66178+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66179+{
66180+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66181+
66182+ return (long)atomic_read_unchecked(v);
66183+}
66184+#endif
66185+
66186 static inline void atomic_long_set(atomic_long_t *l, long i)
66187 {
66188 atomic_t *v = (atomic_t *)l;
66189@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66190 atomic_set(v, i);
66191 }
66192
66193+#ifdef CONFIG_PAX_REFCOUNT
66194+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66195+{
66196+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66197+
66198+ atomic_set_unchecked(v, i);
66199+}
66200+#endif
66201+
66202 static inline void atomic_long_inc(atomic_long_t *l)
66203 {
66204 atomic_t *v = (atomic_t *)l;
66205@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66206 atomic_inc(v);
66207 }
66208
66209+#ifdef CONFIG_PAX_REFCOUNT
66210+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66211+{
66212+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66213+
66214+ atomic_inc_unchecked(v);
66215+}
66216+#endif
66217+
66218 static inline void atomic_long_dec(atomic_long_t *l)
66219 {
66220 atomic_t *v = (atomic_t *)l;
66221@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66222 atomic_dec(v);
66223 }
66224
66225+#ifdef CONFIG_PAX_REFCOUNT
66226+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66227+{
66228+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66229+
66230+ atomic_dec_unchecked(v);
66231+}
66232+#endif
66233+
66234 static inline void atomic_long_add(long i, atomic_long_t *l)
66235 {
66236 atomic_t *v = (atomic_t *)l;
66237@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66238 atomic_add(i, v);
66239 }
66240
66241+#ifdef CONFIG_PAX_REFCOUNT
66242+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66243+{
66244+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66245+
66246+ atomic_add_unchecked(i, v);
66247+}
66248+#endif
66249+
66250 static inline void atomic_long_sub(long i, atomic_long_t *l)
66251 {
66252 atomic_t *v = (atomic_t *)l;
66253@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66254 atomic_sub(i, v);
66255 }
66256
66257+#ifdef CONFIG_PAX_REFCOUNT
66258+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66259+{
66260+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66261+
66262+ atomic_sub_unchecked(i, v);
66263+}
66264+#endif
66265+
66266 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66267 {
66268 atomic_t *v = (atomic_t *)l;
66269@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66270 return (long)atomic_add_return(i, v);
66271 }
66272
66273+#ifdef CONFIG_PAX_REFCOUNT
66274+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66275+{
66276+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66277+
66278+ return (long)atomic_add_return_unchecked(i, v);
66279+}
66280+
66281+#endif
66282+
66283 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66284 {
66285 atomic_t *v = (atomic_t *)l;
66286@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66287 return (long)atomic_inc_return(v);
66288 }
66289
66290+#ifdef CONFIG_PAX_REFCOUNT
66291+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66292+{
66293+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66294+
66295+ return (long)atomic_inc_return_unchecked(v);
66296+}
66297+#endif
66298+
66299 static inline long atomic_long_dec_return(atomic_long_t *l)
66300 {
66301 atomic_t *v = (atomic_t *)l;
66302@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66303
66304 #endif /* BITS_PER_LONG == 64 */
66305
66306+#ifdef CONFIG_PAX_REFCOUNT
66307+static inline void pax_refcount_needs_these_functions(void)
66308+{
66309+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
66310+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
66311+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
66312+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
66313+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
66314+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
66315+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
66316+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
66317+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
66318+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
66319+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
66320+#ifdef CONFIG_X86
66321+ atomic_clear_mask_unchecked(0, NULL);
66322+ atomic_set_mask_unchecked(0, NULL);
66323+#endif
66324+
66325+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
66326+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
66327+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
66328+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
66329+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
66330+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
66331+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
66332+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
66333+}
66334+#else
66335+#define atomic_read_unchecked(v) atomic_read(v)
66336+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
66337+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
66338+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
66339+#define atomic_inc_unchecked(v) atomic_inc(v)
66340+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
66341+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
66342+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
66343+#define atomic_dec_unchecked(v) atomic_dec(v)
66344+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
66345+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
66346+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
66347+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
66348+
66349+#define atomic_long_read_unchecked(v) atomic_long_read(v)
66350+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
66351+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
66352+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
66353+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
66354+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
66355+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
66356+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
66357+#endif
66358+
66359 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
66360diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
66361index 1ced641..c896ee8 100644
66362--- a/include/asm-generic/atomic.h
66363+++ b/include/asm-generic/atomic.h
66364@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
66365 * Atomically clears the bits set in @mask from @v
66366 */
66367 #ifndef atomic_clear_mask
66368-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
66369+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
66370 {
66371 unsigned long flags;
66372
66373diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
66374index b18ce4f..2ee2843 100644
66375--- a/include/asm-generic/atomic64.h
66376+++ b/include/asm-generic/atomic64.h
66377@@ -16,6 +16,8 @@ typedef struct {
66378 long long counter;
66379 } atomic64_t;
66380
66381+typedef atomic64_t atomic64_unchecked_t;
66382+
66383 #define ATOMIC64_INIT(i) { (i) }
66384
66385 extern long long atomic64_read(const atomic64_t *v);
66386@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
66387 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
66388 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
66389
66390+#define atomic64_read_unchecked(v) atomic64_read(v)
66391+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
66392+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
66393+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
66394+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
66395+#define atomic64_inc_unchecked(v) atomic64_inc(v)
66396+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
66397+#define atomic64_dec_unchecked(v) atomic64_dec(v)
66398+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
66399+
66400 #endif /* _ASM_GENERIC_ATOMIC64_H */
66401diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
66402index 1bfcfe5..e04c5c9 100644
66403--- a/include/asm-generic/cache.h
66404+++ b/include/asm-generic/cache.h
66405@@ -6,7 +6,7 @@
66406 * cache lines need to provide their own cache.h.
66407 */
66408
66409-#define L1_CACHE_SHIFT 5
66410-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
66411+#define L1_CACHE_SHIFT 5UL
66412+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
66413
66414 #endif /* __ASM_GENERIC_CACHE_H */
66415diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
66416index 0d68a1e..b74a761 100644
66417--- a/include/asm-generic/emergency-restart.h
66418+++ b/include/asm-generic/emergency-restart.h
66419@@ -1,7 +1,7 @@
66420 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
66421 #define _ASM_GENERIC_EMERGENCY_RESTART_H
66422
66423-static inline void machine_emergency_restart(void)
66424+static inline __noreturn void machine_emergency_restart(void)
66425 {
66426 machine_restart(NULL);
66427 }
66428diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
66429index 90f99c7..00ce236 100644
66430--- a/include/asm-generic/kmap_types.h
66431+++ b/include/asm-generic/kmap_types.h
66432@@ -2,9 +2,9 @@
66433 #define _ASM_GENERIC_KMAP_TYPES_H
66434
66435 #ifdef __WITH_KM_FENCE
66436-# define KM_TYPE_NR 41
66437+# define KM_TYPE_NR 42
66438 #else
66439-# define KM_TYPE_NR 20
66440+# define KM_TYPE_NR 21
66441 #endif
66442
66443 #endif
66444diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
66445index 9ceb03b..62b0b8f 100644
66446--- a/include/asm-generic/local.h
66447+++ b/include/asm-generic/local.h
66448@@ -23,24 +23,37 @@ typedef struct
66449 atomic_long_t a;
66450 } local_t;
66451
66452+typedef struct {
66453+ atomic_long_unchecked_t a;
66454+} local_unchecked_t;
66455+
66456 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
66457
66458 #define local_read(l) atomic_long_read(&(l)->a)
66459+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
66460 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
66461+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
66462 #define local_inc(l) atomic_long_inc(&(l)->a)
66463+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
66464 #define local_dec(l) atomic_long_dec(&(l)->a)
66465+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
66466 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
66467+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
66468 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
66469+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
66470
66471 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
66472 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
66473 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
66474 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
66475 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
66476+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
66477 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
66478 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
66479+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
66480
66481 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66482+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66483 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
66484 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
66485 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
66486diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
66487index 725612b..9cc513a 100644
66488--- a/include/asm-generic/pgtable-nopmd.h
66489+++ b/include/asm-generic/pgtable-nopmd.h
66490@@ -1,14 +1,19 @@
66491 #ifndef _PGTABLE_NOPMD_H
66492 #define _PGTABLE_NOPMD_H
66493
66494-#ifndef __ASSEMBLY__
66495-
66496 #include <asm-generic/pgtable-nopud.h>
66497
66498-struct mm_struct;
66499-
66500 #define __PAGETABLE_PMD_FOLDED
66501
66502+#define PMD_SHIFT PUD_SHIFT
66503+#define PTRS_PER_PMD 1
66504+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
66505+#define PMD_MASK (~(PMD_SIZE-1))
66506+
66507+#ifndef __ASSEMBLY__
66508+
66509+struct mm_struct;
66510+
66511 /*
66512 * Having the pmd type consist of a pud gets the size right, and allows
66513 * us to conceptually access the pud entry that this pmd is folded into
66514@@ -16,11 +21,6 @@ struct mm_struct;
66515 */
66516 typedef struct { pud_t pud; } pmd_t;
66517
66518-#define PMD_SHIFT PUD_SHIFT
66519-#define PTRS_PER_PMD 1
66520-#define PMD_SIZE (1UL << PMD_SHIFT)
66521-#define PMD_MASK (~(PMD_SIZE-1))
66522-
66523 /*
66524 * The "pud_xxx()" functions here are trivial for a folded two-level
66525 * setup: the pmd is never bad, and a pmd always exists (as it's folded
66526diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
66527index 810431d..0ec4804f 100644
66528--- a/include/asm-generic/pgtable-nopud.h
66529+++ b/include/asm-generic/pgtable-nopud.h
66530@@ -1,10 +1,15 @@
66531 #ifndef _PGTABLE_NOPUD_H
66532 #define _PGTABLE_NOPUD_H
66533
66534-#ifndef __ASSEMBLY__
66535-
66536 #define __PAGETABLE_PUD_FOLDED
66537
66538+#define PUD_SHIFT PGDIR_SHIFT
66539+#define PTRS_PER_PUD 1
66540+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
66541+#define PUD_MASK (~(PUD_SIZE-1))
66542+
66543+#ifndef __ASSEMBLY__
66544+
66545 /*
66546 * Having the pud type consist of a pgd gets the size right, and allows
66547 * us to conceptually access the pgd entry that this pud is folded into
66548@@ -12,11 +17,6 @@
66549 */
66550 typedef struct { pgd_t pgd; } pud_t;
66551
66552-#define PUD_SHIFT PGDIR_SHIFT
66553-#define PTRS_PER_PUD 1
66554-#define PUD_SIZE (1UL << PUD_SHIFT)
66555-#define PUD_MASK (~(PUD_SIZE-1))
66556-
66557 /*
66558 * The "pgd_xxx()" functions here are trivial for a folded two-level
66559 * setup: the pud is never bad, and a pud always exists (as it's folded
66560@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
66561 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
66562
66563 #define pgd_populate(mm, pgd, pud) do { } while (0)
66564+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
66565 /*
66566 * (puds are folded into pgds so this doesn't get actually called,
66567 * but the define is needed for a generic inline function.)
66568diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
66569index 5cf680a..4b74d62 100644
66570--- a/include/asm-generic/pgtable.h
66571+++ b/include/asm-generic/pgtable.h
66572@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
66573 }
66574 #endif /* CONFIG_NUMA_BALANCING */
66575
66576+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
66577+static inline unsigned long pax_open_kernel(void) { return 0; }
66578+#endif
66579+
66580+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
66581+static inline unsigned long pax_close_kernel(void) { return 0; }
66582+#endif
66583+
66584 #endif /* CONFIG_MMU */
66585
66586 #endif /* !__ASSEMBLY__ */
66587diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
66588index d1ea7ce..b1ebf2a 100644
66589--- a/include/asm-generic/vmlinux.lds.h
66590+++ b/include/asm-generic/vmlinux.lds.h
66591@@ -218,6 +218,7 @@
66592 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
66593 VMLINUX_SYMBOL(__start_rodata) = .; \
66594 *(.rodata) *(.rodata.*) \
66595+ *(.data..read_only) \
66596 *(__vermagic) /* Kernel version magic */ \
66597 . = ALIGN(8); \
66598 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
66599@@ -725,17 +726,18 @@
66600 * section in the linker script will go there too. @phdr should have
66601 * a leading colon.
66602 *
66603- * Note that this macros defines __per_cpu_load as an absolute symbol.
66604+ * Note that this macros defines per_cpu_load as an absolute symbol.
66605 * If there is no need to put the percpu section at a predetermined
66606 * address, use PERCPU_SECTION.
66607 */
66608 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
66609- VMLINUX_SYMBOL(__per_cpu_load) = .; \
66610- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
66611+ per_cpu_load = .; \
66612+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
66613 - LOAD_OFFSET) { \
66614+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
66615 PERCPU_INPUT(cacheline) \
66616 } phdr \
66617- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
66618+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
66619
66620 /**
66621 * PERCPU_SECTION - define output section for percpu area, simple version
66622diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
66623index 418d270..bfd2794 100644
66624--- a/include/crypto/algapi.h
66625+++ b/include/crypto/algapi.h
66626@@ -34,7 +34,7 @@ struct crypto_type {
66627 unsigned int maskclear;
66628 unsigned int maskset;
66629 unsigned int tfmsize;
66630-};
66631+} __do_const;
66632
66633 struct crypto_instance {
66634 struct crypto_alg alg;
66635diff --git a/include/drm/drmP.h b/include/drm/drmP.h
66636index fad21c9..ab858bc 100644
66637--- a/include/drm/drmP.h
66638+++ b/include/drm/drmP.h
66639@@ -72,6 +72,7 @@
66640 #include <linux/workqueue.h>
66641 #include <linux/poll.h>
66642 #include <asm/pgalloc.h>
66643+#include <asm/local.h>
66644 #include <drm/drm.h>
66645 #include <drm/drm_sarea.h>
66646
66647@@ -293,10 +294,12 @@ do { \
66648 * \param cmd command.
66649 * \param arg argument.
66650 */
66651-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
66652+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
66653+ struct drm_file *file_priv);
66654+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
66655 struct drm_file *file_priv);
66656
66657-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66658+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
66659 unsigned long arg);
66660
66661 #define DRM_IOCTL_NR(n) _IOC_NR(n)
66662@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66663 struct drm_ioctl_desc {
66664 unsigned int cmd;
66665 int flags;
66666- drm_ioctl_t *func;
66667+ drm_ioctl_t func;
66668 unsigned int cmd_drv;
66669-};
66670+} __do_const;
66671
66672 /**
66673 * Creates a driver or general drm_ioctl_desc array entry for the given
66674@@ -995,7 +998,7 @@ struct drm_info_list {
66675 int (*show)(struct seq_file*, void*); /** show callback */
66676 u32 driver_features; /**< Required driver features for this entry */
66677 void *data;
66678-};
66679+} __do_const;
66680
66681 /**
66682 * debugfs node structure. This structure represents a debugfs file.
66683@@ -1068,7 +1071,7 @@ struct drm_device {
66684
66685 /** \name Usage Counters */
66686 /*@{ */
66687- int open_count; /**< Outstanding files open */
66688+ local_t open_count; /**< Outstanding files open */
66689 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
66690 atomic_t vma_count; /**< Outstanding vma areas open */
66691 int buf_use; /**< Buffers in use -- cannot alloc */
66692@@ -1079,7 +1082,7 @@ struct drm_device {
66693 /*@{ */
66694 unsigned long counters;
66695 enum drm_stat_type types[15];
66696- atomic_t counts[15];
66697+ atomic_unchecked_t counts[15];
66698 /*@} */
66699
66700 struct list_head filelist;
66701diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
66702index f43d556..94d9343 100644
66703--- a/include/drm/drm_crtc_helper.h
66704+++ b/include/drm/drm_crtc_helper.h
66705@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
66706 struct drm_connector *connector);
66707 /* disable encoder when not in use - more explicit than dpms off */
66708 void (*disable)(struct drm_encoder *encoder);
66709-};
66710+} __no_const;
66711
66712 /**
66713 * drm_connector_helper_funcs - helper operations for connectors
66714diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
66715index 72dcbe8..8db58d7 100644
66716--- a/include/drm/ttm/ttm_memory.h
66717+++ b/include/drm/ttm/ttm_memory.h
66718@@ -48,7 +48,7 @@
66719
66720 struct ttm_mem_shrink {
66721 int (*do_shrink) (struct ttm_mem_shrink *);
66722-};
66723+} __no_const;
66724
66725 /**
66726 * struct ttm_mem_global - Global memory accounting structure.
66727diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
66728index 4b840e8..155d235 100644
66729--- a/include/keys/asymmetric-subtype.h
66730+++ b/include/keys/asymmetric-subtype.h
66731@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
66732 /* Verify the signature on a key of this subtype (optional) */
66733 int (*verify_signature)(const struct key *key,
66734 const struct public_key_signature *sig);
66735-};
66736+} __do_const;
66737
66738 /**
66739 * asymmetric_key_subtype - Get the subtype from an asymmetric key
66740diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
66741index c1da539..1dcec55 100644
66742--- a/include/linux/atmdev.h
66743+++ b/include/linux/atmdev.h
66744@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
66745 #endif
66746
66747 struct k_atm_aal_stats {
66748-#define __HANDLE_ITEM(i) atomic_t i
66749+#define __HANDLE_ITEM(i) atomic_unchecked_t i
66750 __AAL_STAT_ITEMS
66751 #undef __HANDLE_ITEM
66752 };
66753@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
66754 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
66755 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
66756 struct module *owner;
66757-};
66758+} __do_const ;
66759
66760 struct atmphy_ops {
66761 int (*start)(struct atm_dev *dev);
66762diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
66763index 0530b98..96a8ac0 100644
66764--- a/include/linux/binfmts.h
66765+++ b/include/linux/binfmts.h
66766@@ -73,8 +73,9 @@ struct linux_binfmt {
66767 int (*load_binary)(struct linux_binprm *);
66768 int (*load_shlib)(struct file *);
66769 int (*core_dump)(struct coredump_params *cprm);
66770+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
66771 unsigned long min_coredump; /* minimal dump size */
66772-};
66773+} __do_const;
66774
66775 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
66776
66777diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
66778index f94bc83..62b9cfe 100644
66779--- a/include/linux/blkdev.h
66780+++ b/include/linux/blkdev.h
66781@@ -1498,7 +1498,7 @@ struct block_device_operations {
66782 /* this callback is with swap_lock and sometimes page table lock held */
66783 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
66784 struct module *owner;
66785-};
66786+} __do_const;
66787
66788 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
66789 unsigned long);
66790diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
66791index 7c2e030..b72475d 100644
66792--- a/include/linux/blktrace_api.h
66793+++ b/include/linux/blktrace_api.h
66794@@ -23,7 +23,7 @@ struct blk_trace {
66795 struct dentry *dir;
66796 struct dentry *dropped_file;
66797 struct dentry *msg_file;
66798- atomic_t dropped;
66799+ atomic_unchecked_t dropped;
66800 };
66801
66802 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
66803diff --git a/include/linux/cache.h b/include/linux/cache.h
66804index 4c57065..4307975 100644
66805--- a/include/linux/cache.h
66806+++ b/include/linux/cache.h
66807@@ -16,6 +16,10 @@
66808 #define __read_mostly
66809 #endif
66810
66811+#ifndef __read_only
66812+#define __read_only __read_mostly
66813+#endif
66814+
66815 #ifndef ____cacheline_aligned
66816 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
66817 #endif
66818diff --git a/include/linux/capability.h b/include/linux/capability.h
66819index 98503b7..cc36d18 100644
66820--- a/include/linux/capability.h
66821+++ b/include/linux/capability.h
66822@@ -211,8 +211,13 @@ extern bool capable(int cap);
66823 extern bool ns_capable(struct user_namespace *ns, int cap);
66824 extern bool nsown_capable(int cap);
66825 extern bool inode_capable(const struct inode *inode, int cap);
66826+extern bool capable_nolog(int cap);
66827+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
66828+extern bool inode_capable_nolog(const struct inode *inode, int cap);
66829
66830 /* audit system wants to get cap info from files as well */
66831 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
66832
66833+extern int is_privileged_binary(const struct dentry *dentry);
66834+
66835 #endif /* !_LINUX_CAPABILITY_H */
66836diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
66837index 8609d57..86e4d79 100644
66838--- a/include/linux/cdrom.h
66839+++ b/include/linux/cdrom.h
66840@@ -87,7 +87,6 @@ struct cdrom_device_ops {
66841
66842 /* driver specifications */
66843 const int capability; /* capability flags */
66844- int n_minors; /* number of active minor devices */
66845 /* handle uniform packets for scsi type devices (scsi,atapi) */
66846 int (*generic_packet) (struct cdrom_device_info *,
66847 struct packet_command *);
66848diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
66849index 42e55de..1cd0e66 100644
66850--- a/include/linux/cleancache.h
66851+++ b/include/linux/cleancache.h
66852@@ -31,7 +31,7 @@ struct cleancache_ops {
66853 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
66854 void (*invalidate_inode)(int, struct cleancache_filekey);
66855 void (*invalidate_fs)(int);
66856-};
66857+} __no_const;
66858
66859 extern struct cleancache_ops
66860 cleancache_register_ops(struct cleancache_ops *ops);
66861diff --git a/include/linux/compat.h b/include/linux/compat.h
66862index dec7e2d..e1d5880 100644
66863--- a/include/linux/compat.h
66864+++ b/include/linux/compat.h
66865@@ -311,14 +311,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
66866 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
66867 int version, void __user *uptr);
66868 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
66869- void __user *uptr);
66870+ void __user *uptr) __intentional_overflow(0);
66871 #else
66872 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
66873 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
66874 compat_ssize_t msgsz, int msgflg);
66875 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
66876 compat_ssize_t msgsz, long msgtyp, int msgflg);
66877-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
66878+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
66879 #endif
66880 long compat_sys_msgctl(int first, int second, void __user *uptr);
66881 long compat_sys_shmctl(int first, int second, void __user *uptr);
66882diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
66883index 662fd1b..e801992 100644
66884--- a/include/linux/compiler-gcc4.h
66885+++ b/include/linux/compiler-gcc4.h
66886@@ -34,6 +34,21 @@
66887 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
66888
66889 #if __GNUC_MINOR__ >= 5
66890+
66891+#ifdef CONSTIFY_PLUGIN
66892+#define __no_const __attribute__((no_const))
66893+#define __do_const __attribute__((do_const))
66894+#endif
66895+
66896+#ifdef SIZE_OVERFLOW_PLUGIN
66897+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
66898+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
66899+#endif
66900+
66901+#ifdef LATENT_ENTROPY_PLUGIN
66902+#define __latent_entropy __attribute__((latent_entropy))
66903+#endif
66904+
66905 /*
66906 * Mark a position in code as unreachable. This can be used to
66907 * suppress control flow warnings after asm blocks that transfer
66908@@ -49,6 +64,11 @@
66909 #define __noclone __attribute__((__noclone__))
66910
66911 #endif
66912+
66913+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
66914+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
66915+#define __bos0(ptr) __bos((ptr), 0)
66916+#define __bos1(ptr) __bos((ptr), 1)
66917 #endif
66918
66919 #if __GNUC_MINOR__ >= 6
66920diff --git a/include/linux/compiler.h b/include/linux/compiler.h
66921index dd852b7..72924c0 100644
66922--- a/include/linux/compiler.h
66923+++ b/include/linux/compiler.h
66924@@ -5,11 +5,14 @@
66925
66926 #ifdef __CHECKER__
66927 # define __user __attribute__((noderef, address_space(1)))
66928+# define __force_user __force __user
66929 # define __kernel __attribute__((address_space(0)))
66930+# define __force_kernel __force __kernel
66931 # define __safe __attribute__((safe))
66932 # define __force __attribute__((force))
66933 # define __nocast __attribute__((nocast))
66934 # define __iomem __attribute__((noderef, address_space(2)))
66935+# define __force_iomem __force __iomem
66936 # define __must_hold(x) __attribute__((context(x,1,1)))
66937 # define __acquires(x) __attribute__((context(x,0,1)))
66938 # define __releases(x) __attribute__((context(x,1,0)))
66939@@ -17,20 +20,48 @@
66940 # define __release(x) __context__(x,-1)
66941 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
66942 # define __percpu __attribute__((noderef, address_space(3)))
66943+# define __force_percpu __force __percpu
66944 #ifdef CONFIG_SPARSE_RCU_POINTER
66945 # define __rcu __attribute__((noderef, address_space(4)))
66946+# define __force_rcu __force __rcu
66947 #else
66948 # define __rcu
66949+# define __force_rcu
66950 #endif
66951 extern void __chk_user_ptr(const volatile void __user *);
66952 extern void __chk_io_ptr(const volatile void __iomem *);
66953+#elif defined(CHECKER_PLUGIN)
66954+//# define __user
66955+//# define __force_user
66956+//# define __kernel
66957+//# define __force_kernel
66958+# define __safe
66959+# define __force
66960+# define __nocast
66961+# define __iomem
66962+# define __force_iomem
66963+# define __chk_user_ptr(x) (void)0
66964+# define __chk_io_ptr(x) (void)0
66965+# define __builtin_warning(x, y...) (1)
66966+# define __acquires(x)
66967+# define __releases(x)
66968+# define __acquire(x) (void)0
66969+# define __release(x) (void)0
66970+# define __cond_lock(x,c) (c)
66971+# define __percpu
66972+# define __force_percpu
66973+# define __rcu
66974+# define __force_rcu
66975 #else
66976 # define __user
66977+# define __force_user
66978 # define __kernel
66979+# define __force_kernel
66980 # define __safe
66981 # define __force
66982 # define __nocast
66983 # define __iomem
66984+# define __force_iomem
66985 # define __chk_user_ptr(x) (void)0
66986 # define __chk_io_ptr(x) (void)0
66987 # define __builtin_warning(x, y...) (1)
66988@@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
66989 # define __release(x) (void)0
66990 # define __cond_lock(x,c) (c)
66991 # define __percpu
66992+# define __force_percpu
66993 # define __rcu
66994+# define __force_rcu
66995 #endif
66996
66997 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
66998@@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66999 # define __attribute_const__ /* unimplemented */
67000 #endif
67001
67002+#ifndef __no_const
67003+# define __no_const
67004+#endif
67005+
67006+#ifndef __do_const
67007+# define __do_const
67008+#endif
67009+
67010+#ifndef __size_overflow
67011+# define __size_overflow(...)
67012+#endif
67013+
67014+#ifndef __intentional_overflow
67015+# define __intentional_overflow(...)
67016+#endif
67017+
67018+#ifndef __latent_entropy
67019+# define __latent_entropy
67020+#endif
67021+
67022 /*
67023 * Tell gcc if a function is cold. The compiler will assume any path
67024 * directly leading to the call is unlikely.
67025@@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67026 #define __cold
67027 #endif
67028
67029+#ifndef __alloc_size
67030+#define __alloc_size(...)
67031+#endif
67032+
67033+#ifndef __bos
67034+#define __bos(ptr, arg)
67035+#endif
67036+
67037+#ifndef __bos0
67038+#define __bos0(ptr)
67039+#endif
67040+
67041+#ifndef __bos1
67042+#define __bos1(ptr)
67043+#endif
67044+
67045 /* Simple shorthand for a section definition */
67046 #ifndef __section
67047 # define __section(S) __attribute__ ((__section__(#S)))
67048@@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67049 * use is to mediate communication between process-level code and irq/NMI
67050 * handlers, all running on the same CPU.
67051 */
67052-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
67053+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
67054+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
67055
67056 #endif /* __LINUX_COMPILER_H */
67057diff --git a/include/linux/completion.h b/include/linux/completion.h
67058index 51494e6..0fd1b61 100644
67059--- a/include/linux/completion.h
67060+++ b/include/linux/completion.h
67061@@ -78,13 +78,13 @@ static inline void init_completion(struct completion *x)
67062
67063 extern void wait_for_completion(struct completion *);
67064 extern int wait_for_completion_interruptible(struct completion *x);
67065-extern int wait_for_completion_killable(struct completion *x);
67066+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
67067 extern unsigned long wait_for_completion_timeout(struct completion *x,
67068 unsigned long timeout);
67069 extern long wait_for_completion_interruptible_timeout(
67070- struct completion *x, unsigned long timeout);
67071+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67072 extern long wait_for_completion_killable_timeout(
67073- struct completion *x, unsigned long timeout);
67074+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67075 extern bool try_wait_for_completion(struct completion *x);
67076 extern bool completion_done(struct completion *x);
67077
67078diff --git a/include/linux/configfs.h b/include/linux/configfs.h
67079index 34025df..d94bbbc 100644
67080--- a/include/linux/configfs.h
67081+++ b/include/linux/configfs.h
67082@@ -125,7 +125,7 @@ struct configfs_attribute {
67083 const char *ca_name;
67084 struct module *ca_owner;
67085 umode_t ca_mode;
67086-};
67087+} __do_const;
67088
67089 /*
67090 * Users often need to create attribute structures for their configurable
67091diff --git a/include/linux/cpu.h b/include/linux/cpu.h
67092index ce7a074..01ab8ac 100644
67093--- a/include/linux/cpu.h
67094+++ b/include/linux/cpu.h
67095@@ -115,7 +115,7 @@ enum {
67096 /* Need to know about CPUs going up/down? */
67097 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
67098 #define cpu_notifier(fn, pri) { \
67099- static struct notifier_block fn##_nb __cpuinitdata = \
67100+ static struct notifier_block fn##_nb = \
67101 { .notifier_call = fn, .priority = pri }; \
67102 register_cpu_notifier(&fn##_nb); \
67103 }
67104diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
67105index a55b88e..fba90c5 100644
67106--- a/include/linux/cpufreq.h
67107+++ b/include/linux/cpufreq.h
67108@@ -240,7 +240,7 @@ struct cpufreq_driver {
67109 int (*suspend) (struct cpufreq_policy *policy);
67110 int (*resume) (struct cpufreq_policy *policy);
67111 struct freq_attr **attr;
67112-};
67113+} __do_const;
67114
67115 /* flags */
67116
67117@@ -299,6 +299,7 @@ struct global_attr {
67118 ssize_t (*store)(struct kobject *a, struct attribute *b,
67119 const char *c, size_t count);
67120 };
67121+typedef struct global_attr __no_const global_attr_no_const;
67122
67123 #define define_one_global_ro(_name) \
67124 static struct global_attr _name = \
67125diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
67126index 24cd1037..20a63aae 100644
67127--- a/include/linux/cpuidle.h
67128+++ b/include/linux/cpuidle.h
67129@@ -54,7 +54,8 @@ struct cpuidle_state {
67130 int index);
67131
67132 int (*enter_dead) (struct cpuidle_device *dev, int index);
67133-};
67134+} __do_const;
67135+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
67136
67137 /* Idle State Flags */
67138 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
67139@@ -216,7 +217,7 @@ struct cpuidle_governor {
67140 void (*reflect) (struct cpuidle_device *dev, int index);
67141
67142 struct module *owner;
67143-};
67144+} __do_const;
67145
67146 #ifdef CONFIG_CPU_IDLE
67147
67148diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
67149index 0325602..5e9feff 100644
67150--- a/include/linux/cpumask.h
67151+++ b/include/linux/cpumask.h
67152@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67153 }
67154
67155 /* Valid inputs for n are -1 and 0. */
67156-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67157+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67158 {
67159 return n+1;
67160 }
67161
67162-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67163+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67164 {
67165 return n+1;
67166 }
67167
67168-static inline unsigned int cpumask_next_and(int n,
67169+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
67170 const struct cpumask *srcp,
67171 const struct cpumask *andp)
67172 {
67173@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67174 *
67175 * Returns >= nr_cpu_ids if no further cpus set.
67176 */
67177-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67178+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67179 {
67180 /* -1 is a legal arg here. */
67181 if (n != -1)
67182@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67183 *
67184 * Returns >= nr_cpu_ids if no further cpus unset.
67185 */
67186-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67187+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67188 {
67189 /* -1 is a legal arg here. */
67190 if (n != -1)
67191@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67192 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
67193 }
67194
67195-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
67196+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
67197 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
67198
67199 /**
67200diff --git a/include/linux/cred.h b/include/linux/cred.h
67201index 04421e8..6bce4ef 100644
67202--- a/include/linux/cred.h
67203+++ b/include/linux/cred.h
67204@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
67205 static inline void validate_process_creds(void)
67206 {
67207 }
67208+static inline void validate_task_creds(struct task_struct *task)
67209+{
67210+}
67211 #endif
67212
67213 /**
67214diff --git a/include/linux/crypto.h b/include/linux/crypto.h
67215index b92eadf..b4ecdc1 100644
67216--- a/include/linux/crypto.h
67217+++ b/include/linux/crypto.h
67218@@ -373,7 +373,7 @@ struct cipher_tfm {
67219 const u8 *key, unsigned int keylen);
67220 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67221 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67222-};
67223+} __no_const;
67224
67225 struct hash_tfm {
67226 int (*init)(struct hash_desc *desc);
67227@@ -394,13 +394,13 @@ struct compress_tfm {
67228 int (*cot_decompress)(struct crypto_tfm *tfm,
67229 const u8 *src, unsigned int slen,
67230 u8 *dst, unsigned int *dlen);
67231-};
67232+} __no_const;
67233
67234 struct rng_tfm {
67235 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
67236 unsigned int dlen);
67237 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
67238-};
67239+} __no_const;
67240
67241 #define crt_ablkcipher crt_u.ablkcipher
67242 #define crt_aead crt_u.aead
67243diff --git a/include/linux/ctype.h b/include/linux/ctype.h
67244index 8acfe31..6ffccd63 100644
67245--- a/include/linux/ctype.h
67246+++ b/include/linux/ctype.h
67247@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
67248 * Fast implementation of tolower() for internal usage. Do not use in your
67249 * code.
67250 */
67251-static inline char _tolower(const char c)
67252+static inline unsigned char _tolower(const unsigned char c)
67253 {
67254 return c | 0x20;
67255 }
67256diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
67257index 7925bf0..d5143d2 100644
67258--- a/include/linux/decompress/mm.h
67259+++ b/include/linux/decompress/mm.h
67260@@ -77,7 +77,7 @@ static void free(void *where)
67261 * warnings when not needed (indeed large_malloc / large_free are not
67262 * needed by inflate */
67263
67264-#define malloc(a) kmalloc(a, GFP_KERNEL)
67265+#define malloc(a) kmalloc((a), GFP_KERNEL)
67266 #define free(a) kfree(a)
67267
67268 #define large_malloc(a) vmalloc(a)
67269diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
67270index e83ef39..33e0eb3 100644
67271--- a/include/linux/devfreq.h
67272+++ b/include/linux/devfreq.h
67273@@ -114,7 +114,7 @@ struct devfreq_governor {
67274 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
67275 int (*event_handler)(struct devfreq *devfreq,
67276 unsigned int event, void *data);
67277-};
67278+} __do_const;
67279
67280 /**
67281 * struct devfreq - Device devfreq structure
67282diff --git a/include/linux/device.h b/include/linux/device.h
67283index 43dcda9..7a1fb65 100644
67284--- a/include/linux/device.h
67285+++ b/include/linux/device.h
67286@@ -294,7 +294,7 @@ struct subsys_interface {
67287 struct list_head node;
67288 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
67289 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
67290-};
67291+} __do_const;
67292
67293 int subsys_interface_register(struct subsys_interface *sif);
67294 void subsys_interface_unregister(struct subsys_interface *sif);
67295@@ -474,7 +474,7 @@ struct device_type {
67296 void (*release)(struct device *dev);
67297
67298 const struct dev_pm_ops *pm;
67299-};
67300+} __do_const;
67301
67302 /* interface for exporting device attributes */
67303 struct device_attribute {
67304@@ -484,11 +484,12 @@ struct device_attribute {
67305 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
67306 const char *buf, size_t count);
67307 };
67308+typedef struct device_attribute __no_const device_attribute_no_const;
67309
67310 struct dev_ext_attribute {
67311 struct device_attribute attr;
67312 void *var;
67313-};
67314+} __do_const;
67315
67316 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
67317 char *buf);
67318diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
67319index 94af418..b1ca7a2 100644
67320--- a/include/linux/dma-mapping.h
67321+++ b/include/linux/dma-mapping.h
67322@@ -54,7 +54,7 @@ struct dma_map_ops {
67323 u64 (*get_required_mask)(struct device *dev);
67324 #endif
67325 int is_phys;
67326-};
67327+} __do_const;
67328
67329 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
67330
67331diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
67332index d3201e4..8281e63 100644
67333--- a/include/linux/dmaengine.h
67334+++ b/include/linux/dmaengine.h
67335@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
67336 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
67337 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
67338
67339-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67340+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67341 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
67342-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67343+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67344 struct dma_pinned_list *pinned_list, struct page *page,
67345 unsigned int offset, size_t len);
67346
67347diff --git a/include/linux/efi.h b/include/linux/efi.h
67348index 7a9498a..155713d 100644
67349--- a/include/linux/efi.h
67350+++ b/include/linux/efi.h
67351@@ -733,6 +733,7 @@ struct efivar_operations {
67352 efi_set_variable_t *set_variable;
67353 efi_query_variable_info_t *query_variable_info;
67354 };
67355+typedef struct efivar_operations __no_const efivar_operations_no_const;
67356
67357 struct efivars {
67358 /*
67359diff --git a/include/linux/elf.h b/include/linux/elf.h
67360index 8c9048e..16a4665 100644
67361--- a/include/linux/elf.h
67362+++ b/include/linux/elf.h
67363@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
67364 #define elf_note elf32_note
67365 #define elf_addr_t Elf32_Off
67366 #define Elf_Half Elf32_Half
67367+#define elf_dyn Elf32_Dyn
67368
67369 #else
67370
67371@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
67372 #define elf_note elf64_note
67373 #define elf_addr_t Elf64_Off
67374 #define Elf_Half Elf64_Half
67375+#define elf_dyn Elf64_Dyn
67376
67377 #endif
67378
67379diff --git a/include/linux/err.h b/include/linux/err.h
67380index f2edce2..cc2082c 100644
67381--- a/include/linux/err.h
67382+++ b/include/linux/err.h
67383@@ -19,12 +19,12 @@
67384
67385 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
67386
67387-static inline void * __must_check ERR_PTR(long error)
67388+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
67389 {
67390 return (void *) error;
67391 }
67392
67393-static inline long __must_check PTR_ERR(const void *ptr)
67394+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
67395 {
67396 return (long) ptr;
67397 }
67398diff --git a/include/linux/extcon.h b/include/linux/extcon.h
67399index fcb51c8..bdafcf6 100644
67400--- a/include/linux/extcon.h
67401+++ b/include/linux/extcon.h
67402@@ -134,7 +134,7 @@ struct extcon_dev {
67403 /* /sys/class/extcon/.../mutually_exclusive/... */
67404 struct attribute_group attr_g_muex;
67405 struct attribute **attrs_muex;
67406- struct device_attribute *d_attrs_muex;
67407+ device_attribute_no_const *d_attrs_muex;
67408 };
67409
67410 /**
67411diff --git a/include/linux/fb.h b/include/linux/fb.h
67412index c7a9571..02eeffe 100644
67413--- a/include/linux/fb.h
67414+++ b/include/linux/fb.h
67415@@ -302,7 +302,7 @@ struct fb_ops {
67416 /* called at KDB enter and leave time to prepare the console */
67417 int (*fb_debug_enter)(struct fb_info *info);
67418 int (*fb_debug_leave)(struct fb_info *info);
67419-};
67420+} __do_const;
67421
67422 #ifdef CONFIG_FB_TILEBLITTING
67423 #define FB_TILE_CURSOR_NONE 0
67424diff --git a/include/linux/filter.h b/include/linux/filter.h
67425index c45eabc..baa0be5 100644
67426--- a/include/linux/filter.h
67427+++ b/include/linux/filter.h
67428@@ -20,6 +20,7 @@ struct compat_sock_fprog {
67429
67430 struct sk_buff;
67431 struct sock;
67432+struct bpf_jit_work;
67433
67434 struct sk_filter
67435 {
67436@@ -27,6 +28,9 @@ struct sk_filter
67437 unsigned int len; /* Number of filter blocks */
67438 unsigned int (*bpf_func)(const struct sk_buff *skb,
67439 const struct sock_filter *filter);
67440+#ifdef CONFIG_BPF_JIT
67441+ struct bpf_jit_work *work;
67442+#endif
67443 struct rcu_head rcu;
67444 struct sock_filter insns[0];
67445 };
67446diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
67447index 3044254..9767f41 100644
67448--- a/include/linux/frontswap.h
67449+++ b/include/linux/frontswap.h
67450@@ -11,7 +11,7 @@ struct frontswap_ops {
67451 int (*load)(unsigned, pgoff_t, struct page *);
67452 void (*invalidate_page)(unsigned, pgoff_t);
67453 void (*invalidate_area)(unsigned);
67454-};
67455+} __no_const;
67456
67457 extern bool frontswap_enabled;
67458 extern struct frontswap_ops
67459diff --git a/include/linux/fs.h b/include/linux/fs.h
67460index 7617ee0..b575199 100644
67461--- a/include/linux/fs.h
67462+++ b/include/linux/fs.h
67463@@ -1541,7 +1541,8 @@ struct file_operations {
67464 long (*fallocate)(struct file *file, int mode, loff_t offset,
67465 loff_t len);
67466 int (*show_fdinfo)(struct seq_file *m, struct file *f);
67467-};
67468+} __do_const;
67469+typedef struct file_operations __no_const file_operations_no_const;
67470
67471 struct inode_operations {
67472 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
67473@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
67474 inode->i_flags |= S_NOSEC;
67475 }
67476
67477+static inline bool is_sidechannel_device(const struct inode *inode)
67478+{
67479+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
67480+ umode_t mode = inode->i_mode;
67481+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
67482+#else
67483+ return false;
67484+#endif
67485+}
67486+
67487 #endif /* _LINUX_FS_H */
67488diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
67489index d0ae3a8..0244b34 100644
67490--- a/include/linux/fs_struct.h
67491+++ b/include/linux/fs_struct.h
67492@@ -6,7 +6,7 @@
67493 #include <linux/seqlock.h>
67494
67495 struct fs_struct {
67496- int users;
67497+ atomic_t users;
67498 spinlock_t lock;
67499 seqcount_t seq;
67500 int umask;
67501diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
67502index 5dfa0aa..6acf322 100644
67503--- a/include/linux/fscache-cache.h
67504+++ b/include/linux/fscache-cache.h
67505@@ -112,7 +112,7 @@ struct fscache_operation {
67506 fscache_operation_release_t release;
67507 };
67508
67509-extern atomic_t fscache_op_debug_id;
67510+extern atomic_unchecked_t fscache_op_debug_id;
67511 extern void fscache_op_work_func(struct work_struct *work);
67512
67513 extern void fscache_enqueue_operation(struct fscache_operation *);
67514@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
67515 INIT_WORK(&op->work, fscache_op_work_func);
67516 atomic_set(&op->usage, 1);
67517 op->state = FSCACHE_OP_ST_INITIALISED;
67518- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
67519+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
67520 op->processor = processor;
67521 op->release = release;
67522 INIT_LIST_HEAD(&op->pend_link);
67523diff --git a/include/linux/fscache.h b/include/linux/fscache.h
67524index 7a08623..4c07b0f 100644
67525--- a/include/linux/fscache.h
67526+++ b/include/linux/fscache.h
67527@@ -152,7 +152,7 @@ struct fscache_cookie_def {
67528 * - this is mandatory for any object that may have data
67529 */
67530 void (*now_uncached)(void *cookie_netfs_data);
67531-};
67532+} __do_const;
67533
67534 /*
67535 * fscache cached network filesystem type
67536diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
67537index 0fbfb46..508eb0d 100644
67538--- a/include/linux/fsnotify.h
67539+++ b/include/linux/fsnotify.h
67540@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
67541 struct inode *inode = path->dentry->d_inode;
67542 __u32 mask = FS_ACCESS;
67543
67544+ if (is_sidechannel_device(inode))
67545+ return;
67546+
67547 if (S_ISDIR(inode->i_mode))
67548 mask |= FS_ISDIR;
67549
67550@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
67551 struct inode *inode = path->dentry->d_inode;
67552 __u32 mask = FS_MODIFY;
67553
67554+ if (is_sidechannel_device(inode))
67555+ return;
67556+
67557 if (S_ISDIR(inode->i_mode))
67558 mask |= FS_ISDIR;
67559
67560@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
67561 */
67562 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
67563 {
67564- return kstrdup(name, GFP_KERNEL);
67565+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
67566 }
67567
67568 /*
67569diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
67570index a3d4895..ddd2a50 100644
67571--- a/include/linux/ftrace_event.h
67572+++ b/include/linux/ftrace_event.h
67573@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
67574 extern int trace_add_event_call(struct ftrace_event_call *call);
67575 extern void trace_remove_event_call(struct ftrace_event_call *call);
67576
67577-#define is_signed_type(type) (((type)(-1)) < 0)
67578+#define is_signed_type(type) (((type)(-1)) < (type)1)
67579
67580 int trace_set_clr_event(const char *system, const char *event, int set);
67581
67582diff --git a/include/linux/genhd.h b/include/linux/genhd.h
67583index 79b8bba..86b539e 100644
67584--- a/include/linux/genhd.h
67585+++ b/include/linux/genhd.h
67586@@ -194,7 +194,7 @@ struct gendisk {
67587 struct kobject *slave_dir;
67588
67589 struct timer_rand_state *random;
67590- atomic_t sync_io; /* RAID */
67591+ atomic_unchecked_t sync_io; /* RAID */
67592 struct disk_events *ev;
67593 #ifdef CONFIG_BLK_DEV_INTEGRITY
67594 struct blk_integrity *integrity;
67595diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
67596index 023bc34..b02b46a 100644
67597--- a/include/linux/genl_magic_func.h
67598+++ b/include/linux/genl_magic_func.h
67599@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
67600 },
67601
67602 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
67603-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
67604+static struct genl_ops ZZZ_genl_ops[] = {
67605 #include GENL_MAGIC_INCLUDE_FILE
67606 };
67607
67608diff --git a/include/linux/gfp.h b/include/linux/gfp.h
67609index 0f615eb..5c3832f 100644
67610--- a/include/linux/gfp.h
67611+++ b/include/linux/gfp.h
67612@@ -35,6 +35,13 @@ struct vm_area_struct;
67613 #define ___GFP_NO_KSWAPD 0x400000u
67614 #define ___GFP_OTHER_NODE 0x800000u
67615 #define ___GFP_WRITE 0x1000000u
67616+
67617+#ifdef CONFIG_PAX_USERCOPY_SLABS
67618+#define ___GFP_USERCOPY 0x2000000u
67619+#else
67620+#define ___GFP_USERCOPY 0
67621+#endif
67622+
67623 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
67624
67625 /*
67626@@ -92,6 +99,7 @@ struct vm_area_struct;
67627 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
67628 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
67629 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
67630+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
67631
67632 /*
67633 * This may seem redundant, but it's a way of annotating false positives vs.
67634@@ -99,7 +107,7 @@ struct vm_area_struct;
67635 */
67636 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
67637
67638-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
67639+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
67640 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
67641
67642 /* This equals 0, but use constants in case they ever change */
67643@@ -153,6 +161,8 @@ struct vm_area_struct;
67644 /* 4GB DMA on some platforms */
67645 #define GFP_DMA32 __GFP_DMA32
67646
67647+#define GFP_USERCOPY __GFP_USERCOPY
67648+
67649 /* Convert GFP flags to their corresponding migrate type */
67650 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
67651 {
67652diff --git a/include/linux/gracl.h b/include/linux/gracl.h
67653new file mode 100644
67654index 0000000..ebe6d72
67655--- /dev/null
67656+++ b/include/linux/gracl.h
67657@@ -0,0 +1,319 @@
67658+#ifndef GR_ACL_H
67659+#define GR_ACL_H
67660+
67661+#include <linux/grdefs.h>
67662+#include <linux/resource.h>
67663+#include <linux/capability.h>
67664+#include <linux/dcache.h>
67665+#include <asm/resource.h>
67666+
67667+/* Major status information */
67668+
67669+#define GR_VERSION "grsecurity 2.9.1"
67670+#define GRSECURITY_VERSION 0x2901
67671+
67672+enum {
67673+ GR_SHUTDOWN = 0,
67674+ GR_ENABLE = 1,
67675+ GR_SPROLE = 2,
67676+ GR_RELOAD = 3,
67677+ GR_SEGVMOD = 4,
67678+ GR_STATUS = 5,
67679+ GR_UNSPROLE = 6,
67680+ GR_PASSSET = 7,
67681+ GR_SPROLEPAM = 8,
67682+};
67683+
67684+/* Password setup definitions
67685+ * kernel/grhash.c */
67686+enum {
67687+ GR_PW_LEN = 128,
67688+ GR_SALT_LEN = 16,
67689+ GR_SHA_LEN = 32,
67690+};
67691+
67692+enum {
67693+ GR_SPROLE_LEN = 64,
67694+};
67695+
67696+enum {
67697+ GR_NO_GLOB = 0,
67698+ GR_REG_GLOB,
67699+ GR_CREATE_GLOB
67700+};
67701+
67702+#define GR_NLIMITS 32
67703+
67704+/* Begin Data Structures */
67705+
67706+struct sprole_pw {
67707+ unsigned char *rolename;
67708+ unsigned char salt[GR_SALT_LEN];
67709+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
67710+};
67711+
67712+struct name_entry {
67713+ __u32 key;
67714+ ino_t inode;
67715+ dev_t device;
67716+ char *name;
67717+ __u16 len;
67718+ __u8 deleted;
67719+ struct name_entry *prev;
67720+ struct name_entry *next;
67721+};
67722+
67723+struct inodev_entry {
67724+ struct name_entry *nentry;
67725+ struct inodev_entry *prev;
67726+ struct inodev_entry *next;
67727+};
67728+
67729+struct acl_role_db {
67730+ struct acl_role_label **r_hash;
67731+ __u32 r_size;
67732+};
67733+
67734+struct inodev_db {
67735+ struct inodev_entry **i_hash;
67736+ __u32 i_size;
67737+};
67738+
67739+struct name_db {
67740+ struct name_entry **n_hash;
67741+ __u32 n_size;
67742+};
67743+
67744+struct crash_uid {
67745+ uid_t uid;
67746+ unsigned long expires;
67747+};
67748+
67749+struct gr_hash_struct {
67750+ void **table;
67751+ void **nametable;
67752+ void *first;
67753+ __u32 table_size;
67754+ __u32 used_size;
67755+ int type;
67756+};
67757+
67758+/* Userspace Grsecurity ACL data structures */
67759+
67760+struct acl_subject_label {
67761+ char *filename;
67762+ ino_t inode;
67763+ dev_t device;
67764+ __u32 mode;
67765+ kernel_cap_t cap_mask;
67766+ kernel_cap_t cap_lower;
67767+ kernel_cap_t cap_invert_audit;
67768+
67769+ struct rlimit res[GR_NLIMITS];
67770+ __u32 resmask;
67771+
67772+ __u8 user_trans_type;
67773+ __u8 group_trans_type;
67774+ uid_t *user_transitions;
67775+ gid_t *group_transitions;
67776+ __u16 user_trans_num;
67777+ __u16 group_trans_num;
67778+
67779+ __u32 sock_families[2];
67780+ __u32 ip_proto[8];
67781+ __u32 ip_type;
67782+ struct acl_ip_label **ips;
67783+ __u32 ip_num;
67784+ __u32 inaddr_any_override;
67785+
67786+ __u32 crashes;
67787+ unsigned long expires;
67788+
67789+ struct acl_subject_label *parent_subject;
67790+ struct gr_hash_struct *hash;
67791+ struct acl_subject_label *prev;
67792+ struct acl_subject_label *next;
67793+
67794+ struct acl_object_label **obj_hash;
67795+ __u32 obj_hash_size;
67796+ __u16 pax_flags;
67797+};
67798+
67799+struct role_allowed_ip {
67800+ __u32 addr;
67801+ __u32 netmask;
67802+
67803+ struct role_allowed_ip *prev;
67804+ struct role_allowed_ip *next;
67805+};
67806+
67807+struct role_transition {
67808+ char *rolename;
67809+
67810+ struct role_transition *prev;
67811+ struct role_transition *next;
67812+};
67813+
67814+struct acl_role_label {
67815+ char *rolename;
67816+ uid_t uidgid;
67817+ __u16 roletype;
67818+
67819+ __u16 auth_attempts;
67820+ unsigned long expires;
67821+
67822+ struct acl_subject_label *root_label;
67823+ struct gr_hash_struct *hash;
67824+
67825+ struct acl_role_label *prev;
67826+ struct acl_role_label *next;
67827+
67828+ struct role_transition *transitions;
67829+ struct role_allowed_ip *allowed_ips;
67830+ uid_t *domain_children;
67831+ __u16 domain_child_num;
67832+
67833+ umode_t umask;
67834+
67835+ struct acl_subject_label **subj_hash;
67836+ __u32 subj_hash_size;
67837+};
67838+
67839+struct user_acl_role_db {
67840+ struct acl_role_label **r_table;
67841+ __u32 num_pointers; /* Number of allocations to track */
67842+ __u32 num_roles; /* Number of roles */
67843+ __u32 num_domain_children; /* Number of domain children */
67844+ __u32 num_subjects; /* Number of subjects */
67845+ __u32 num_objects; /* Number of objects */
67846+};
67847+
67848+struct acl_object_label {
67849+ char *filename;
67850+ ino_t inode;
67851+ dev_t device;
67852+ __u32 mode;
67853+
67854+ struct acl_subject_label *nested;
67855+ struct acl_object_label *globbed;
67856+
67857+ /* next two structures not used */
67858+
67859+ struct acl_object_label *prev;
67860+ struct acl_object_label *next;
67861+};
67862+
67863+struct acl_ip_label {
67864+ char *iface;
67865+ __u32 addr;
67866+ __u32 netmask;
67867+ __u16 low, high;
67868+ __u8 mode;
67869+ __u32 type;
67870+ __u32 proto[8];
67871+
67872+ /* next two structures not used */
67873+
67874+ struct acl_ip_label *prev;
67875+ struct acl_ip_label *next;
67876+};
67877+
67878+struct gr_arg {
67879+ struct user_acl_role_db role_db;
67880+ unsigned char pw[GR_PW_LEN];
67881+ unsigned char salt[GR_SALT_LEN];
67882+ unsigned char sum[GR_SHA_LEN];
67883+ unsigned char sp_role[GR_SPROLE_LEN];
67884+ struct sprole_pw *sprole_pws;
67885+ dev_t segv_device;
67886+ ino_t segv_inode;
67887+ uid_t segv_uid;
67888+ __u16 num_sprole_pws;
67889+ __u16 mode;
67890+};
67891+
67892+struct gr_arg_wrapper {
67893+ struct gr_arg *arg;
67894+ __u32 version;
67895+ __u32 size;
67896+};
67897+
67898+struct subject_map {
67899+ struct acl_subject_label *user;
67900+ struct acl_subject_label *kernel;
67901+ struct subject_map *prev;
67902+ struct subject_map *next;
67903+};
67904+
67905+struct acl_subj_map_db {
67906+ struct subject_map **s_hash;
67907+ __u32 s_size;
67908+};
67909+
67910+/* End Data Structures Section */
67911+
67912+/* Hash functions generated by empirical testing by Brad Spengler
67913+ Makes good use of the low bits of the inode. Generally 0-1 times
67914+ in loop for successful match. 0-3 for unsuccessful match.
67915+ Shift/add algorithm with modulus of table size and an XOR*/
67916+
67917+static __inline__ unsigned int
67918+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
67919+{
67920+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
67921+}
67922+
67923+ static __inline__ unsigned int
67924+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
67925+{
67926+ return ((const unsigned long)userp % sz);
67927+}
67928+
67929+static __inline__ unsigned int
67930+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
67931+{
67932+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
67933+}
67934+
67935+static __inline__ unsigned int
67936+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
67937+{
67938+ return full_name_hash((const unsigned char *)name, len) % sz;
67939+}
67940+
67941+#define FOR_EACH_ROLE_START(role) \
67942+ role = role_list; \
67943+ while (role) {
67944+
67945+#define FOR_EACH_ROLE_END(role) \
67946+ role = role->prev; \
67947+ }
67948+
67949+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
67950+ subj = NULL; \
67951+ iter = 0; \
67952+ while (iter < role->subj_hash_size) { \
67953+ if (subj == NULL) \
67954+ subj = role->subj_hash[iter]; \
67955+ if (subj == NULL) { \
67956+ iter++; \
67957+ continue; \
67958+ }
67959+
67960+#define FOR_EACH_SUBJECT_END(subj,iter) \
67961+ subj = subj->next; \
67962+ if (subj == NULL) \
67963+ iter++; \
67964+ }
67965+
67966+
67967+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
67968+ subj = role->hash->first; \
67969+ while (subj != NULL) {
67970+
67971+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
67972+ subj = subj->next; \
67973+ }
67974+
67975+#endif
67976+
67977diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
67978new file mode 100644
67979index 0000000..323ecf2
67980--- /dev/null
67981+++ b/include/linux/gralloc.h
67982@@ -0,0 +1,9 @@
67983+#ifndef __GRALLOC_H
67984+#define __GRALLOC_H
67985+
67986+void acl_free_all(void);
67987+int acl_alloc_stack_init(unsigned long size);
67988+void *acl_alloc(unsigned long len);
67989+void *acl_alloc_num(unsigned long num, unsigned long len);
67990+
67991+#endif
67992diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
67993new file mode 100644
67994index 0000000..be66033
67995--- /dev/null
67996+++ b/include/linux/grdefs.h
67997@@ -0,0 +1,140 @@
67998+#ifndef GRDEFS_H
67999+#define GRDEFS_H
68000+
68001+/* Begin grsecurity status declarations */
68002+
68003+enum {
68004+ GR_READY = 0x01,
68005+ GR_STATUS_INIT = 0x00 // disabled state
68006+};
68007+
68008+/* Begin ACL declarations */
68009+
68010+/* Role flags */
68011+
68012+enum {
68013+ GR_ROLE_USER = 0x0001,
68014+ GR_ROLE_GROUP = 0x0002,
68015+ GR_ROLE_DEFAULT = 0x0004,
68016+ GR_ROLE_SPECIAL = 0x0008,
68017+ GR_ROLE_AUTH = 0x0010,
68018+ GR_ROLE_NOPW = 0x0020,
68019+ GR_ROLE_GOD = 0x0040,
68020+ GR_ROLE_LEARN = 0x0080,
68021+ GR_ROLE_TPE = 0x0100,
68022+ GR_ROLE_DOMAIN = 0x0200,
68023+ GR_ROLE_PAM = 0x0400,
68024+ GR_ROLE_PERSIST = 0x0800
68025+};
68026+
68027+/* ACL Subject and Object mode flags */
68028+enum {
68029+ GR_DELETED = 0x80000000
68030+};
68031+
68032+/* ACL Object-only mode flags */
68033+enum {
68034+ GR_READ = 0x00000001,
68035+ GR_APPEND = 0x00000002,
68036+ GR_WRITE = 0x00000004,
68037+ GR_EXEC = 0x00000008,
68038+ GR_FIND = 0x00000010,
68039+ GR_INHERIT = 0x00000020,
68040+ GR_SETID = 0x00000040,
68041+ GR_CREATE = 0x00000080,
68042+ GR_DELETE = 0x00000100,
68043+ GR_LINK = 0x00000200,
68044+ GR_AUDIT_READ = 0x00000400,
68045+ GR_AUDIT_APPEND = 0x00000800,
68046+ GR_AUDIT_WRITE = 0x00001000,
68047+ GR_AUDIT_EXEC = 0x00002000,
68048+ GR_AUDIT_FIND = 0x00004000,
68049+ GR_AUDIT_INHERIT= 0x00008000,
68050+ GR_AUDIT_SETID = 0x00010000,
68051+ GR_AUDIT_CREATE = 0x00020000,
68052+ GR_AUDIT_DELETE = 0x00040000,
68053+ GR_AUDIT_LINK = 0x00080000,
68054+ GR_PTRACERD = 0x00100000,
68055+ GR_NOPTRACE = 0x00200000,
68056+ GR_SUPPRESS = 0x00400000,
68057+ GR_NOLEARN = 0x00800000,
68058+ GR_INIT_TRANSFER= 0x01000000
68059+};
68060+
68061+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
68062+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
68063+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
68064+
68065+/* ACL subject-only mode flags */
68066+enum {
68067+ GR_KILL = 0x00000001,
68068+ GR_VIEW = 0x00000002,
68069+ GR_PROTECTED = 0x00000004,
68070+ GR_LEARN = 0x00000008,
68071+ GR_OVERRIDE = 0x00000010,
68072+ /* just a placeholder, this mode is only used in userspace */
68073+ GR_DUMMY = 0x00000020,
68074+ GR_PROTSHM = 0x00000040,
68075+ GR_KILLPROC = 0x00000080,
68076+ GR_KILLIPPROC = 0x00000100,
68077+ /* just a placeholder, this mode is only used in userspace */
68078+ GR_NOTROJAN = 0x00000200,
68079+ GR_PROTPROCFD = 0x00000400,
68080+ GR_PROCACCT = 0x00000800,
68081+ GR_RELAXPTRACE = 0x00001000,
68082+ //GR_NESTED = 0x00002000,
68083+ GR_INHERITLEARN = 0x00004000,
68084+ GR_PROCFIND = 0x00008000,
68085+ GR_POVERRIDE = 0x00010000,
68086+ GR_KERNELAUTH = 0x00020000,
68087+ GR_ATSECURE = 0x00040000,
68088+ GR_SHMEXEC = 0x00080000
68089+};
68090+
68091+enum {
68092+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
68093+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
68094+ GR_PAX_ENABLE_MPROTECT = 0x0004,
68095+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
68096+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
68097+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
68098+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
68099+ GR_PAX_DISABLE_MPROTECT = 0x0400,
68100+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
68101+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
68102+};
68103+
68104+enum {
68105+ GR_ID_USER = 0x01,
68106+ GR_ID_GROUP = 0x02,
68107+};
68108+
68109+enum {
68110+ GR_ID_ALLOW = 0x01,
68111+ GR_ID_DENY = 0x02,
68112+};
68113+
68114+#define GR_CRASH_RES 31
68115+#define GR_UIDTABLE_MAX 500
68116+
68117+/* begin resource learning section */
68118+enum {
68119+ GR_RLIM_CPU_BUMP = 60,
68120+ GR_RLIM_FSIZE_BUMP = 50000,
68121+ GR_RLIM_DATA_BUMP = 10000,
68122+ GR_RLIM_STACK_BUMP = 1000,
68123+ GR_RLIM_CORE_BUMP = 10000,
68124+ GR_RLIM_RSS_BUMP = 500000,
68125+ GR_RLIM_NPROC_BUMP = 1,
68126+ GR_RLIM_NOFILE_BUMP = 5,
68127+ GR_RLIM_MEMLOCK_BUMP = 50000,
68128+ GR_RLIM_AS_BUMP = 500000,
68129+ GR_RLIM_LOCKS_BUMP = 2,
68130+ GR_RLIM_SIGPENDING_BUMP = 5,
68131+ GR_RLIM_MSGQUEUE_BUMP = 10000,
68132+ GR_RLIM_NICE_BUMP = 1,
68133+ GR_RLIM_RTPRIO_BUMP = 1,
68134+ GR_RLIM_RTTIME_BUMP = 1000000
68135+};
68136+
68137+#endif
68138diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
68139new file mode 100644
68140index 0000000..9bb6662
68141--- /dev/null
68142+++ b/include/linux/grinternal.h
68143@@ -0,0 +1,215 @@
68144+#ifndef __GRINTERNAL_H
68145+#define __GRINTERNAL_H
68146+
68147+#ifdef CONFIG_GRKERNSEC
68148+
68149+#include <linux/fs.h>
68150+#include <linux/mnt_namespace.h>
68151+#include <linux/nsproxy.h>
68152+#include <linux/gracl.h>
68153+#include <linux/grdefs.h>
68154+#include <linux/grmsg.h>
68155+
68156+void gr_add_learn_entry(const char *fmt, ...)
68157+ __attribute__ ((format (printf, 1, 2)));
68158+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
68159+ const struct vfsmount *mnt);
68160+__u32 gr_check_create(const struct dentry *new_dentry,
68161+ const struct dentry *parent,
68162+ const struct vfsmount *mnt, const __u32 mode);
68163+int gr_check_protected_task(const struct task_struct *task);
68164+__u32 to_gr_audit(const __u32 reqmode);
68165+int gr_set_acls(const int type);
68166+int gr_apply_subject_to_task(struct task_struct *task);
68167+int gr_acl_is_enabled(void);
68168+char gr_roletype_to_char(void);
68169+
68170+void gr_handle_alertkill(struct task_struct *task);
68171+char *gr_to_filename(const struct dentry *dentry,
68172+ const struct vfsmount *mnt);
68173+char *gr_to_filename1(const struct dentry *dentry,
68174+ const struct vfsmount *mnt);
68175+char *gr_to_filename2(const struct dentry *dentry,
68176+ const struct vfsmount *mnt);
68177+char *gr_to_filename3(const struct dentry *dentry,
68178+ const struct vfsmount *mnt);
68179+
68180+extern int grsec_enable_ptrace_readexec;
68181+extern int grsec_enable_harden_ptrace;
68182+extern int grsec_enable_link;
68183+extern int grsec_enable_fifo;
68184+extern int grsec_enable_execve;
68185+extern int grsec_enable_shm;
68186+extern int grsec_enable_execlog;
68187+extern int grsec_enable_signal;
68188+extern int grsec_enable_audit_ptrace;
68189+extern int grsec_enable_forkfail;
68190+extern int grsec_enable_time;
68191+extern int grsec_enable_rofs;
68192+extern int grsec_enable_chroot_shmat;
68193+extern int grsec_enable_chroot_mount;
68194+extern int grsec_enable_chroot_double;
68195+extern int grsec_enable_chroot_pivot;
68196+extern int grsec_enable_chroot_chdir;
68197+extern int grsec_enable_chroot_chmod;
68198+extern int grsec_enable_chroot_mknod;
68199+extern int grsec_enable_chroot_fchdir;
68200+extern int grsec_enable_chroot_nice;
68201+extern int grsec_enable_chroot_execlog;
68202+extern int grsec_enable_chroot_caps;
68203+extern int grsec_enable_chroot_sysctl;
68204+extern int grsec_enable_chroot_unix;
68205+extern int grsec_enable_symlinkown;
68206+extern kgid_t grsec_symlinkown_gid;
68207+extern int grsec_enable_tpe;
68208+extern kgid_t grsec_tpe_gid;
68209+extern int grsec_enable_tpe_all;
68210+extern int grsec_enable_tpe_invert;
68211+extern int grsec_enable_socket_all;
68212+extern kgid_t grsec_socket_all_gid;
68213+extern int grsec_enable_socket_client;
68214+extern kgid_t grsec_socket_client_gid;
68215+extern int grsec_enable_socket_server;
68216+extern kgid_t grsec_socket_server_gid;
68217+extern kgid_t grsec_audit_gid;
68218+extern int grsec_enable_group;
68219+extern int grsec_enable_audit_textrel;
68220+extern int grsec_enable_log_rwxmaps;
68221+extern int grsec_enable_mount;
68222+extern int grsec_enable_chdir;
68223+extern int grsec_resource_logging;
68224+extern int grsec_enable_blackhole;
68225+extern int grsec_lastack_retries;
68226+extern int grsec_enable_brute;
68227+extern int grsec_lock;
68228+
68229+extern spinlock_t grsec_alert_lock;
68230+extern unsigned long grsec_alert_wtime;
68231+extern unsigned long grsec_alert_fyet;
68232+
68233+extern spinlock_t grsec_audit_lock;
68234+
68235+extern rwlock_t grsec_exec_file_lock;
68236+
68237+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
68238+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
68239+ (tsk)->exec_file->f_vfsmnt) : "/")
68240+
68241+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
68242+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
68243+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
68244+
68245+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
68246+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
68247+ (tsk)->exec_file->f_vfsmnt) : "/")
68248+
68249+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
68250+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
68251+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
68252+
68253+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
68254+
68255+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
68256+
68257+#define GR_CHROOT_CAPS {{ \
68258+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
68259+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
68260+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
68261+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
68262+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
68263+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
68264+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
68265+
68266+#define security_learn(normal_msg,args...) \
68267+({ \
68268+ read_lock(&grsec_exec_file_lock); \
68269+ gr_add_learn_entry(normal_msg "\n", ## args); \
68270+ read_unlock(&grsec_exec_file_lock); \
68271+})
68272+
68273+enum {
68274+ GR_DO_AUDIT,
68275+ GR_DONT_AUDIT,
68276+ /* used for non-audit messages that we shouldn't kill the task on */
68277+ GR_DONT_AUDIT_GOOD
68278+};
68279+
68280+enum {
68281+ GR_TTYSNIFF,
68282+ GR_RBAC,
68283+ GR_RBAC_STR,
68284+ GR_STR_RBAC,
68285+ GR_RBAC_MODE2,
68286+ GR_RBAC_MODE3,
68287+ GR_FILENAME,
68288+ GR_SYSCTL_HIDDEN,
68289+ GR_NOARGS,
68290+ GR_ONE_INT,
68291+ GR_ONE_INT_TWO_STR,
68292+ GR_ONE_STR,
68293+ GR_STR_INT,
68294+ GR_TWO_STR_INT,
68295+ GR_TWO_INT,
68296+ GR_TWO_U64,
68297+ GR_THREE_INT,
68298+ GR_FIVE_INT_TWO_STR,
68299+ GR_TWO_STR,
68300+ GR_THREE_STR,
68301+ GR_FOUR_STR,
68302+ GR_STR_FILENAME,
68303+ GR_FILENAME_STR,
68304+ GR_FILENAME_TWO_INT,
68305+ GR_FILENAME_TWO_INT_STR,
68306+ GR_TEXTREL,
68307+ GR_PTRACE,
68308+ GR_RESOURCE,
68309+ GR_CAP,
68310+ GR_SIG,
68311+ GR_SIG2,
68312+ GR_CRASH1,
68313+ GR_CRASH2,
68314+ GR_PSACCT,
68315+ GR_RWXMAP
68316+};
68317+
68318+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
68319+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
68320+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
68321+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
68322+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
68323+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
68324+#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)
68325+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
68326+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
68327+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
68328+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
68329+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
68330+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
68331+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
68332+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
68333+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
68334+#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)
68335+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
68336+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
68337+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
68338+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
68339+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
68340+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
68341+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
68342+#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)
68343+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
68344+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
68345+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
68346+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
68347+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
68348+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
68349+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
68350+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
68351+#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)
68352+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
68353+
68354+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
68355+
68356+#endif
68357+
68358+#endif
68359diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
68360new file mode 100644
68361index 0000000..2bd4c8d
68362--- /dev/null
68363+++ b/include/linux/grmsg.h
68364@@ -0,0 +1,111 @@
68365+#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"
68366+#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"
68367+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
68368+#define GR_STOPMOD_MSG "denied modification of module state by "
68369+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
68370+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
68371+#define GR_IOPERM_MSG "denied use of ioperm() by "
68372+#define GR_IOPL_MSG "denied use of iopl() by "
68373+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
68374+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
68375+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
68376+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
68377+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
68378+#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"
68379+#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"
68380+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
68381+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
68382+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
68383+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
68384+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
68385+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
68386+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
68387+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
68388+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
68389+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
68390+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
68391+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
68392+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
68393+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
68394+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
68395+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
68396+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
68397+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
68398+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
68399+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
68400+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
68401+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
68402+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
68403+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
68404+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
68405+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
68406+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
68407+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
68408+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
68409+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
68410+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
68411+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
68412+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
68413+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
68414+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
68415+#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"
68416+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
68417+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
68418+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
68419+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
68420+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
68421+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
68422+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
68423+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
68424+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
68425+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
68426+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
68427+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
68428+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
68429+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
68430+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
68431+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
68432+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
68433+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
68434+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
68435+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
68436+#define GR_FAILFORK_MSG "failed fork with errno %s by "
68437+#define GR_NICE_CHROOT_MSG "denied priority change by "
68438+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
68439+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
68440+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
68441+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
68442+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
68443+#define GR_TIME_MSG "time set by "
68444+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
68445+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
68446+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
68447+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
68448+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
68449+#define GR_BIND_MSG "denied bind() by "
68450+#define GR_CONNECT_MSG "denied connect() by "
68451+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
68452+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
68453+#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"
68454+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
68455+#define GR_CAP_ACL_MSG "use of %s denied for "
68456+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
68457+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
68458+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
68459+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
68460+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
68461+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
68462+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
68463+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
68464+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
68465+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
68466+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
68467+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
68468+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
68469+#define GR_VM86_MSG "denied use of vm86 by "
68470+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
68471+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
68472+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
68473+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
68474+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
68475+#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 "
68476diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
68477new file mode 100644
68478index 0000000..8da63a4
68479--- /dev/null
68480+++ b/include/linux/grsecurity.h
68481@@ -0,0 +1,242 @@
68482+#ifndef GR_SECURITY_H
68483+#define GR_SECURITY_H
68484+#include <linux/fs.h>
68485+#include <linux/fs_struct.h>
68486+#include <linux/binfmts.h>
68487+#include <linux/gracl.h>
68488+
68489+/* notify of brain-dead configs */
68490+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68491+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
68492+#endif
68493+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
68494+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
68495+#endif
68496+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
68497+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
68498+#endif
68499+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
68500+#error "CONFIG_PAX enabled, but no PaX options are enabled."
68501+#endif
68502+
68503+void gr_handle_brute_attach(unsigned long mm_flags);
68504+void gr_handle_brute_check(void);
68505+void gr_handle_kernel_exploit(void);
68506+int gr_process_user_ban(void);
68507+
68508+char gr_roletype_to_char(void);
68509+
68510+int gr_acl_enable_at_secure(void);
68511+
68512+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
68513+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
68514+
68515+void gr_del_task_from_ip_table(struct task_struct *p);
68516+
68517+int gr_pid_is_chrooted(struct task_struct *p);
68518+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
68519+int gr_handle_chroot_nice(void);
68520+int gr_handle_chroot_sysctl(const int op);
68521+int gr_handle_chroot_setpriority(struct task_struct *p,
68522+ const int niceval);
68523+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
68524+int gr_handle_chroot_chroot(const struct dentry *dentry,
68525+ const struct vfsmount *mnt);
68526+void gr_handle_chroot_chdir(struct path *path);
68527+int gr_handle_chroot_chmod(const struct dentry *dentry,
68528+ const struct vfsmount *mnt, const int mode);
68529+int gr_handle_chroot_mknod(const struct dentry *dentry,
68530+ const struct vfsmount *mnt, const int mode);
68531+int gr_handle_chroot_mount(const struct dentry *dentry,
68532+ const struct vfsmount *mnt,
68533+ const char *dev_name);
68534+int gr_handle_chroot_pivot(void);
68535+int gr_handle_chroot_unix(const pid_t pid);
68536+
68537+int gr_handle_rawio(const struct inode *inode);
68538+
68539+void gr_handle_ioperm(void);
68540+void gr_handle_iopl(void);
68541+
68542+umode_t gr_acl_umask(void);
68543+
68544+int gr_tpe_allow(const struct file *file);
68545+
68546+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
68547+void gr_clear_chroot_entries(struct task_struct *task);
68548+
68549+void gr_log_forkfail(const int retval);
68550+void gr_log_timechange(void);
68551+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
68552+void gr_log_chdir(const struct dentry *dentry,
68553+ const struct vfsmount *mnt);
68554+void gr_log_chroot_exec(const struct dentry *dentry,
68555+ const struct vfsmount *mnt);
68556+void gr_log_remount(const char *devname, const int retval);
68557+void gr_log_unmount(const char *devname, const int retval);
68558+void gr_log_mount(const char *from, const char *to, const int retval);
68559+void gr_log_textrel(struct vm_area_struct *vma);
68560+void gr_log_rwxmmap(struct file *file);
68561+void gr_log_rwxmprotect(struct file *file);
68562+
68563+int gr_handle_follow_link(const struct inode *parent,
68564+ const struct inode *inode,
68565+ const struct dentry *dentry,
68566+ const struct vfsmount *mnt);
68567+int gr_handle_fifo(const struct dentry *dentry,
68568+ const struct vfsmount *mnt,
68569+ const struct dentry *dir, const int flag,
68570+ const int acc_mode);
68571+int gr_handle_hardlink(const struct dentry *dentry,
68572+ const struct vfsmount *mnt,
68573+ struct inode *inode,
68574+ const int mode, const struct filename *to);
68575+
68576+int gr_is_capable(const int cap);
68577+int gr_is_capable_nolog(const int cap);
68578+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
68579+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
68580+
68581+void gr_copy_label(struct task_struct *tsk);
68582+void gr_handle_crash(struct task_struct *task, const int sig);
68583+int gr_handle_signal(const struct task_struct *p, const int sig);
68584+int gr_check_crash_uid(const kuid_t uid);
68585+int gr_check_protected_task(const struct task_struct *task);
68586+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
68587+int gr_acl_handle_mmap(const struct file *file,
68588+ const unsigned long prot);
68589+int gr_acl_handle_mprotect(const struct file *file,
68590+ const unsigned long prot);
68591+int gr_check_hidden_task(const struct task_struct *tsk);
68592+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
68593+ const struct vfsmount *mnt);
68594+__u32 gr_acl_handle_utime(const struct dentry *dentry,
68595+ const struct vfsmount *mnt);
68596+__u32 gr_acl_handle_access(const struct dentry *dentry,
68597+ const struct vfsmount *mnt, const int fmode);
68598+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
68599+ const struct vfsmount *mnt, umode_t *mode);
68600+__u32 gr_acl_handle_chown(const struct dentry *dentry,
68601+ const struct vfsmount *mnt);
68602+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
68603+ const struct vfsmount *mnt);
68604+int gr_handle_ptrace(struct task_struct *task, const long request);
68605+int gr_handle_proc_ptrace(struct task_struct *task);
68606+__u32 gr_acl_handle_execve(const struct dentry *dentry,
68607+ const struct vfsmount *mnt);
68608+int gr_check_crash_exec(const struct file *filp);
68609+int gr_acl_is_enabled(void);
68610+void gr_set_kernel_label(struct task_struct *task);
68611+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
68612+ const kgid_t gid);
68613+int gr_set_proc_label(const struct dentry *dentry,
68614+ const struct vfsmount *mnt,
68615+ const int unsafe_flags);
68616+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
68617+ const struct vfsmount *mnt);
68618+__u32 gr_acl_handle_open(const struct dentry *dentry,
68619+ const struct vfsmount *mnt, int acc_mode);
68620+__u32 gr_acl_handle_creat(const struct dentry *dentry,
68621+ const struct dentry *p_dentry,
68622+ const struct vfsmount *p_mnt,
68623+ int open_flags, int acc_mode, const int imode);
68624+void gr_handle_create(const struct dentry *dentry,
68625+ const struct vfsmount *mnt);
68626+void gr_handle_proc_create(const struct dentry *dentry,
68627+ const struct inode *inode);
68628+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
68629+ const struct dentry *parent_dentry,
68630+ const struct vfsmount *parent_mnt,
68631+ const int mode);
68632+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
68633+ const struct dentry *parent_dentry,
68634+ const struct vfsmount *parent_mnt);
68635+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
68636+ const struct vfsmount *mnt);
68637+void gr_handle_delete(const ino_t ino, const dev_t dev);
68638+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
68639+ const struct vfsmount *mnt);
68640+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
68641+ const struct dentry *parent_dentry,
68642+ const struct vfsmount *parent_mnt,
68643+ const struct filename *from);
68644+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
68645+ const struct dentry *parent_dentry,
68646+ const struct vfsmount *parent_mnt,
68647+ const struct dentry *old_dentry,
68648+ const struct vfsmount *old_mnt, const struct filename *to);
68649+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
68650+int gr_acl_handle_rename(struct dentry *new_dentry,
68651+ struct dentry *parent_dentry,
68652+ const struct vfsmount *parent_mnt,
68653+ struct dentry *old_dentry,
68654+ struct inode *old_parent_inode,
68655+ struct vfsmount *old_mnt, const struct filename *newname);
68656+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68657+ struct dentry *old_dentry,
68658+ struct dentry *new_dentry,
68659+ struct vfsmount *mnt, const __u8 replace);
68660+__u32 gr_check_link(const struct dentry *new_dentry,
68661+ const struct dentry *parent_dentry,
68662+ const struct vfsmount *parent_mnt,
68663+ const struct dentry *old_dentry,
68664+ const struct vfsmount *old_mnt);
68665+int gr_acl_handle_filldir(const struct file *file, const char *name,
68666+ const unsigned int namelen, const ino_t ino);
68667+
68668+__u32 gr_acl_handle_unix(const struct dentry *dentry,
68669+ const struct vfsmount *mnt);
68670+void gr_acl_handle_exit(void);
68671+void gr_acl_handle_psacct(struct task_struct *task, const long code);
68672+int gr_acl_handle_procpidmem(const struct task_struct *task);
68673+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
68674+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
68675+void gr_audit_ptrace(struct task_struct *task);
68676+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
68677+void gr_put_exec_file(struct task_struct *task);
68678+
68679+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
68680+
68681+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
68682+extern void gr_learn_resource(const struct task_struct *task, const int res,
68683+ const unsigned long wanted, const int gt);
68684+#else
68685+static inline void gr_learn_resource(const struct task_struct *task, const int res,
68686+ const unsigned long wanted, const int gt)
68687+{
68688+}
68689+#endif
68690+
68691+#ifdef CONFIG_GRKERNSEC_RESLOG
68692+extern void gr_log_resource(const struct task_struct *task, const int res,
68693+ const unsigned long wanted, const int gt);
68694+#else
68695+static inline void gr_log_resource(const struct task_struct *task, const int res,
68696+ const unsigned long wanted, const int gt)
68697+{
68698+}
68699+#endif
68700+
68701+#ifdef CONFIG_GRKERNSEC
68702+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
68703+void gr_handle_vm86(void);
68704+void gr_handle_mem_readwrite(u64 from, u64 to);
68705+
68706+void gr_log_badprocpid(const char *entry);
68707+
68708+extern int grsec_enable_dmesg;
68709+extern int grsec_disable_privio;
68710+
68711+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68712+extern kgid_t grsec_proc_gid;
68713+#endif
68714+
68715+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68716+extern int grsec_enable_chroot_findtask;
68717+#endif
68718+#ifdef CONFIG_GRKERNSEC_SETXID
68719+extern int grsec_enable_setxid;
68720+#endif
68721+#endif
68722+
68723+#endif
68724diff --git a/include/linux/grsock.h b/include/linux/grsock.h
68725new file mode 100644
68726index 0000000..e7ffaaf
68727--- /dev/null
68728+++ b/include/linux/grsock.h
68729@@ -0,0 +1,19 @@
68730+#ifndef __GRSOCK_H
68731+#define __GRSOCK_H
68732+
68733+extern void gr_attach_curr_ip(const struct sock *sk);
68734+extern int gr_handle_sock_all(const int family, const int type,
68735+ const int protocol);
68736+extern int gr_handle_sock_server(const struct sockaddr *sck);
68737+extern int gr_handle_sock_server_other(const struct sock *sck);
68738+extern int gr_handle_sock_client(const struct sockaddr *sck);
68739+extern int gr_search_connect(struct socket * sock,
68740+ struct sockaddr_in * addr);
68741+extern int gr_search_bind(struct socket * sock,
68742+ struct sockaddr_in * addr);
68743+extern int gr_search_listen(struct socket * sock);
68744+extern int gr_search_accept(struct socket * sock);
68745+extern int gr_search_socket(const int domain, const int type,
68746+ const int protocol);
68747+
68748+#endif
68749diff --git a/include/linux/highmem.h b/include/linux/highmem.h
68750index ef788b5..ac41b7b 100644
68751--- a/include/linux/highmem.h
68752+++ b/include/linux/highmem.h
68753@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
68754 kunmap_atomic(kaddr);
68755 }
68756
68757+static inline void sanitize_highpage(struct page *page)
68758+{
68759+ void *kaddr;
68760+ unsigned long flags;
68761+
68762+ local_irq_save(flags);
68763+ kaddr = kmap_atomic(page);
68764+ clear_page(kaddr);
68765+ kunmap_atomic(kaddr);
68766+ local_irq_restore(flags);
68767+}
68768+
68769 static inline void zero_user_segments(struct page *page,
68770 unsigned start1, unsigned end1,
68771 unsigned start2, unsigned end2)
68772diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
68773index 1c7b89a..7f52502 100644
68774--- a/include/linux/hwmon-sysfs.h
68775+++ b/include/linux/hwmon-sysfs.h
68776@@ -25,7 +25,8 @@
68777 struct sensor_device_attribute{
68778 struct device_attribute dev_attr;
68779 int index;
68780-};
68781+} __do_const;
68782+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
68783 #define to_sensor_dev_attr(_dev_attr) \
68784 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
68785
68786@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
68787 struct device_attribute dev_attr;
68788 u8 index;
68789 u8 nr;
68790-};
68791+} __do_const;
68792 #define to_sensor_dev_attr_2(_dev_attr) \
68793 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
68794
68795diff --git a/include/linux/i2c.h b/include/linux/i2c.h
68796index d0c4db7..61b3577 100644
68797--- a/include/linux/i2c.h
68798+++ b/include/linux/i2c.h
68799@@ -369,6 +369,7 @@ struct i2c_algorithm {
68800 /* To determine what the adapter supports */
68801 u32 (*functionality) (struct i2c_adapter *);
68802 };
68803+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
68804
68805 /*
68806 * i2c_adapter is the structure used to identify a physical i2c bus along
68807diff --git a/include/linux/i2o.h b/include/linux/i2o.h
68808index d23c3c2..eb63c81 100644
68809--- a/include/linux/i2o.h
68810+++ b/include/linux/i2o.h
68811@@ -565,7 +565,7 @@ struct i2o_controller {
68812 struct i2o_device *exec; /* Executive */
68813 #if BITS_PER_LONG == 64
68814 spinlock_t context_list_lock; /* lock for context_list */
68815- atomic_t context_list_counter; /* needed for unique contexts */
68816+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
68817 struct list_head context_list; /* list of context id's
68818 and pointers */
68819 #endif
68820diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
68821index aff7ad8..3942bbd 100644
68822--- a/include/linux/if_pppox.h
68823+++ b/include/linux/if_pppox.h
68824@@ -76,7 +76,7 @@ struct pppox_proto {
68825 int (*ioctl)(struct socket *sock, unsigned int cmd,
68826 unsigned long arg);
68827 struct module *owner;
68828-};
68829+} __do_const;
68830
68831 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
68832 extern void unregister_pppox_proto(int proto_num);
68833diff --git a/include/linux/init.h b/include/linux/init.h
68834index 10ed4f4..8e8490d 100644
68835--- a/include/linux/init.h
68836+++ b/include/linux/init.h
68837@@ -39,9 +39,36 @@
68838 * Also note, that this data cannot be "const".
68839 */
68840
68841+#ifdef MODULE
68842+#define add_init_latent_entropy
68843+#define add_devinit_latent_entropy
68844+#define add_cpuinit_latent_entropy
68845+#define add_meminit_latent_entropy
68846+#else
68847+#define add_init_latent_entropy __latent_entropy
68848+
68849+#ifdef CONFIG_HOTPLUG
68850+#define add_devinit_latent_entropy
68851+#else
68852+#define add_devinit_latent_entropy __latent_entropy
68853+#endif
68854+
68855+#ifdef CONFIG_HOTPLUG_CPU
68856+#define add_cpuinit_latent_entropy
68857+#else
68858+#define add_cpuinit_latent_entropy __latent_entropy
68859+#endif
68860+
68861+#ifdef CONFIG_MEMORY_HOTPLUG
68862+#define add_meminit_latent_entropy
68863+#else
68864+#define add_meminit_latent_entropy __latent_entropy
68865+#endif
68866+#endif
68867+
68868 /* These are for everybody (although not all archs will actually
68869 discard it in modules) */
68870-#define __init __section(.init.text) __cold notrace
68871+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
68872 #define __initdata __section(.init.data)
68873 #define __initconst __constsection(.init.rodata)
68874 #define __exitdata __section(.exit.data)
68875@@ -94,7 +121,7 @@
68876 #define __exit __section(.exit.text) __exitused __cold notrace
68877
68878 /* Used for HOTPLUG_CPU */
68879-#define __cpuinit __section(.cpuinit.text) __cold notrace
68880+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
68881 #define __cpuinitdata __section(.cpuinit.data)
68882 #define __cpuinitconst __constsection(.cpuinit.rodata)
68883 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
68884@@ -102,7 +129,7 @@
68885 #define __cpuexitconst __constsection(.cpuexit.rodata)
68886
68887 /* Used for MEMORY_HOTPLUG */
68888-#define __meminit __section(.meminit.text) __cold notrace
68889+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
68890 #define __meminitdata __section(.meminit.data)
68891 #define __meminitconst __constsection(.meminit.rodata)
68892 #define __memexit __section(.memexit.text) __exitused __cold notrace
68893diff --git a/include/linux/init_task.h b/include/linux/init_task.h
68894index 6d087c5..401cab8 100644
68895--- a/include/linux/init_task.h
68896+++ b/include/linux/init_task.h
68897@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
68898
68899 #define INIT_TASK_COMM "swapper"
68900
68901+#ifdef CONFIG_X86
68902+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
68903+#else
68904+#define INIT_TASK_THREAD_INFO
68905+#endif
68906+
68907 /*
68908 * INIT_TASK is used to set up the first task table, touch at
68909 * your own risk!. Base=0, limit=0x1fffff (=2MB)
68910@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
68911 RCU_POINTER_INITIALIZER(cred, &init_cred), \
68912 .comm = INIT_TASK_COMM, \
68913 .thread = INIT_THREAD, \
68914+ INIT_TASK_THREAD_INFO \
68915 .fs = &init_fs, \
68916 .files = &init_files, \
68917 .signal = &init_signals, \
68918diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
68919index 5fa5afe..ac55b25 100644
68920--- a/include/linux/interrupt.h
68921+++ b/include/linux/interrupt.h
68922@@ -430,7 +430,7 @@ enum
68923 /* map softirq index to softirq name. update 'softirq_to_name' in
68924 * kernel/softirq.c when adding a new softirq.
68925 */
68926-extern char *softirq_to_name[NR_SOFTIRQS];
68927+extern const char * const softirq_to_name[NR_SOFTIRQS];
68928
68929 /* softirq mask and active fields moved to irq_cpustat_t in
68930 * asm/hardirq.h to get better cache usage. KAO
68931@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
68932
68933 struct softirq_action
68934 {
68935- void (*action)(struct softirq_action *);
68936-};
68937+ void (*action)(void);
68938+} __no_const;
68939
68940 asmlinkage void do_softirq(void);
68941 asmlinkage void __do_softirq(void);
68942-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
68943+extern void open_softirq(int nr, void (*action)(void));
68944 extern void softirq_init(void);
68945 extern void __raise_softirq_irqoff(unsigned int nr);
68946
68947diff --git a/include/linux/iommu.h b/include/linux/iommu.h
68948index f3b99e1..9b73cee 100644
68949--- a/include/linux/iommu.h
68950+++ b/include/linux/iommu.h
68951@@ -101,7 +101,7 @@ struct iommu_ops {
68952 int (*domain_set_attr)(struct iommu_domain *domain,
68953 enum iommu_attr attr, void *data);
68954 unsigned long pgsize_bitmap;
68955-};
68956+} __do_const;
68957
68958 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
68959 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
68960diff --git a/include/linux/irq.h b/include/linux/irq.h
68961index fdf2c4a..5332486 100644
68962--- a/include/linux/irq.h
68963+++ b/include/linux/irq.h
68964@@ -328,7 +328,8 @@ struct irq_chip {
68965 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
68966
68967 unsigned long flags;
68968-};
68969+} __do_const;
68970+typedef struct irq_chip __no_const irq_chip_no_const;
68971
68972 /*
68973 * irq_chip specific flags
68974diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
68975index 6883e19..06992b1 100644
68976--- a/include/linux/kallsyms.h
68977+++ b/include/linux/kallsyms.h
68978@@ -15,7 +15,8 @@
68979
68980 struct module;
68981
68982-#ifdef CONFIG_KALLSYMS
68983+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
68984+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68985 /* Lookup the address for a symbol. Returns 0 if not found. */
68986 unsigned long kallsyms_lookup_name(const char *name);
68987
68988@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
68989 /* Stupid that this does nothing, but I didn't create this mess. */
68990 #define __print_symbol(fmt, addr)
68991 #endif /*CONFIG_KALLSYMS*/
68992+#else /* when included by kallsyms.c, vsnprintf.c, or
68993+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
68994+extern void __print_symbol(const char *fmt, unsigned long address);
68995+extern int sprint_backtrace(char *buffer, unsigned long address);
68996+extern int sprint_symbol(char *buffer, unsigned long address);
68997+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
68998+const char *kallsyms_lookup(unsigned long addr,
68999+ unsigned long *symbolsize,
69000+ unsigned long *offset,
69001+ char **modname, char *namebuf);
69002+#endif
69003
69004 /* This macro allows us to keep printk typechecking */
69005 static __printf(1, 2)
69006diff --git a/include/linux/key-type.h b/include/linux/key-type.h
69007index 518a53a..5e28358 100644
69008--- a/include/linux/key-type.h
69009+++ b/include/linux/key-type.h
69010@@ -125,7 +125,7 @@ struct key_type {
69011 /* internal fields */
69012 struct list_head link; /* link in types list */
69013 struct lock_class_key lock_class; /* key->sem lock class */
69014-};
69015+} __do_const;
69016
69017 extern struct key_type key_type_keyring;
69018
69019diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
69020index 4dff0c6..1ca9b72 100644
69021--- a/include/linux/kgdb.h
69022+++ b/include/linux/kgdb.h
69023@@ -53,7 +53,7 @@ extern int kgdb_connected;
69024 extern int kgdb_io_module_registered;
69025
69026 extern atomic_t kgdb_setting_breakpoint;
69027-extern atomic_t kgdb_cpu_doing_single_step;
69028+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
69029
69030 extern struct task_struct *kgdb_usethread;
69031 extern struct task_struct *kgdb_contthread;
69032@@ -255,7 +255,7 @@ struct kgdb_arch {
69033 void (*correct_hw_break)(void);
69034
69035 void (*enable_nmi)(bool on);
69036-};
69037+} __do_const;
69038
69039 /**
69040 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
69041@@ -280,7 +280,7 @@ struct kgdb_io {
69042 void (*pre_exception) (void);
69043 void (*post_exception) (void);
69044 int is_console;
69045-};
69046+} __do_const;
69047
69048 extern struct kgdb_arch arch_kgdb_ops;
69049
69050diff --git a/include/linux/kmod.h b/include/linux/kmod.h
69051index 5398d58..5883a34 100644
69052--- a/include/linux/kmod.h
69053+++ b/include/linux/kmod.h
69054@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
69055 * usually useless though. */
69056 extern __printf(2, 3)
69057 int __request_module(bool wait, const char *name, ...);
69058+extern __printf(3, 4)
69059+int ___request_module(bool wait, char *param_name, const char *name, ...);
69060 #define request_module(mod...) __request_module(true, mod)
69061 #define request_module_nowait(mod...) __request_module(false, mod)
69062 #define try_then_request_module(x, mod...) \
69063diff --git a/include/linux/kobject.h b/include/linux/kobject.h
69064index 939b112..ed6ed51 100644
69065--- a/include/linux/kobject.h
69066+++ b/include/linux/kobject.h
69067@@ -111,7 +111,7 @@ struct kobj_type {
69068 struct attribute **default_attrs;
69069 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
69070 const void *(*namespace)(struct kobject *kobj);
69071-};
69072+} __do_const;
69073
69074 struct kobj_uevent_env {
69075 char *envp[UEVENT_NUM_ENVP];
69076@@ -134,6 +134,7 @@ struct kobj_attribute {
69077 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
69078 const char *buf, size_t count);
69079 };
69080+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
69081
69082 extern const struct sysfs_ops kobj_sysfs_ops;
69083
69084diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
69085index f66b065..c2c29b4 100644
69086--- a/include/linux/kobject_ns.h
69087+++ b/include/linux/kobject_ns.h
69088@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
69089 const void *(*netlink_ns)(struct sock *sk);
69090 const void *(*initial_ns)(void);
69091 void (*drop_ns)(void *);
69092-};
69093+} __do_const;
69094
69095 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
69096 int kobj_ns_type_registered(enum kobj_ns_type type);
69097diff --git a/include/linux/kref.h b/include/linux/kref.h
69098index 4972e6e..de4d19b 100644
69099--- a/include/linux/kref.h
69100+++ b/include/linux/kref.h
69101@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
69102 static inline int kref_sub(struct kref *kref, unsigned int count,
69103 void (*release)(struct kref *kref))
69104 {
69105- WARN_ON(release == NULL);
69106+ BUG_ON(release == NULL);
69107
69108 if (atomic_sub_and_test((int) count, &kref->refcount)) {
69109 release(kref);
69110diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
69111index 2c497ab..afe32f5 100644
69112--- a/include/linux/kvm_host.h
69113+++ b/include/linux/kvm_host.h
69114@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
69115 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
69116 void vcpu_put(struct kvm_vcpu *vcpu);
69117
69118-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69119+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69120 struct module *module);
69121 void kvm_exit(void);
69122
69123@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
69124 struct kvm_guest_debug *dbg);
69125 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
69126
69127-int kvm_arch_init(void *opaque);
69128+int kvm_arch_init(const void *opaque);
69129 void kvm_arch_exit(void);
69130
69131 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
69132diff --git a/include/linux/libata.h b/include/linux/libata.h
69133index 649e5f8..ead5194 100644
69134--- a/include/linux/libata.h
69135+++ b/include/linux/libata.h
69136@@ -915,7 +915,7 @@ struct ata_port_operations {
69137 * fields must be pointers.
69138 */
69139 const struct ata_port_operations *inherits;
69140-};
69141+} __do_const;
69142
69143 struct ata_port_info {
69144 unsigned long flags;
69145diff --git a/include/linux/list.h b/include/linux/list.h
69146index cc6d2aa..c10ee83 100644
69147--- a/include/linux/list.h
69148+++ b/include/linux/list.h
69149@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
69150 extern void list_del(struct list_head *entry);
69151 #endif
69152
69153+extern void __pax_list_add(struct list_head *new,
69154+ struct list_head *prev,
69155+ struct list_head *next);
69156+static inline void pax_list_add(struct list_head *new, struct list_head *head)
69157+{
69158+ __pax_list_add(new, head, head->next);
69159+}
69160+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
69161+{
69162+ __pax_list_add(new, head->prev, head);
69163+}
69164+extern void pax_list_del(struct list_head *entry);
69165+
69166 /**
69167 * list_replace - replace old entry by new one
69168 * @old : the element to be replaced
69169@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
69170 INIT_LIST_HEAD(entry);
69171 }
69172
69173+extern void pax_list_del_init(struct list_head *entry);
69174+
69175 /**
69176 * list_move - delete from one list and add as another's head
69177 * @list: the entry to move
69178diff --git a/include/linux/math64.h b/include/linux/math64.h
69179index b8ba855..0148090 100644
69180--- a/include/linux/math64.h
69181+++ b/include/linux/math64.h
69182@@ -14,7 +14,7 @@
69183 * This is commonly provided by 32bit archs to provide an optimized 64bit
69184 * divide.
69185 */
69186-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69187+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69188 {
69189 *remainder = dividend % divisor;
69190 return dividend / divisor;
69191@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
69192 #define div64_long(x,y) div_s64((x),(y))
69193
69194 #ifndef div_u64_rem
69195-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69196+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69197 {
69198 *remainder = do_div(dividend, divisor);
69199 return dividend;
69200@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
69201 * divide.
69202 */
69203 #ifndef div_u64
69204-static inline u64 div_u64(u64 dividend, u32 divisor)
69205+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
69206 {
69207 u32 remainder;
69208 return div_u64_rem(dividend, divisor, &remainder);
69209diff --git a/include/linux/mm.h b/include/linux/mm.h
69210index 66e2f7c..ea88001 100644
69211--- a/include/linux/mm.h
69212+++ b/include/linux/mm.h
69213@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
69214 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
69215 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
69216 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
69217+
69218+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69219+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
69220+#endif
69221+
69222 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
69223
69224 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
69225@@ -231,6 +236,7 @@ struct vm_operations_struct {
69226 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
69227 unsigned long size, pgoff_t pgoff);
69228 };
69229+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
69230
69231 struct mmu_gather;
69232 struct inode;
69233@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
69234 int set_page_dirty_lock(struct page *page);
69235 int clear_page_dirty_for_io(struct page *page);
69236
69237-/* Is the vma a continuation of the stack vma above it? */
69238-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
69239-{
69240- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
69241-}
69242-
69243-static inline int stack_guard_page_start(struct vm_area_struct *vma,
69244- unsigned long addr)
69245-{
69246- return (vma->vm_flags & VM_GROWSDOWN) &&
69247- (vma->vm_start == addr) &&
69248- !vma_growsdown(vma->vm_prev, addr);
69249-}
69250-
69251-/* Is the vma a continuation of the stack vma below it? */
69252-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
69253-{
69254- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
69255-}
69256-
69257-static inline int stack_guard_page_end(struct vm_area_struct *vma,
69258- unsigned long addr)
69259-{
69260- return (vma->vm_flags & VM_GROWSUP) &&
69261- (vma->vm_end == addr) &&
69262- !vma_growsup(vma->vm_next, addr);
69263-}
69264-
69265 extern pid_t
69266 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
69267
69268@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
69269 }
69270 #endif
69271
69272+#ifdef CONFIG_MMU
69273+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
69274+#else
69275+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
69276+{
69277+ return __pgprot(0);
69278+}
69279+#endif
69280+
69281 int vma_wants_writenotify(struct vm_area_struct *vma);
69282
69283 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
69284@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
69285 {
69286 return 0;
69287 }
69288+
69289+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
69290+ unsigned long address)
69291+{
69292+ return 0;
69293+}
69294 #else
69295 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69296+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69297 #endif
69298
69299 #ifdef __PAGETABLE_PMD_FOLDED
69300@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
69301 {
69302 return 0;
69303 }
69304+
69305+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
69306+ unsigned long address)
69307+{
69308+ return 0;
69309+}
69310 #else
69311 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
69312+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
69313 #endif
69314
69315 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
69316@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
69317 NULL: pud_offset(pgd, address);
69318 }
69319
69320+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
69321+{
69322+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
69323+ NULL: pud_offset(pgd, address);
69324+}
69325+
69326 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
69327 {
69328 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
69329 NULL: pmd_offset(pud, address);
69330 }
69331+
69332+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
69333+{
69334+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
69335+ NULL: pmd_offset(pud, address);
69336+}
69337 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
69338
69339 #if USE_SPLIT_PTLOCKS
69340@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
69341 unsigned long, unsigned long,
69342 unsigned long, unsigned long);
69343 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
69344+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
69345
69346 /* These take the mm semaphore themselves */
69347 extern unsigned long vm_brk(unsigned long, unsigned long);
69348@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
69349 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
69350 struct vm_area_struct **pprev);
69351
69352+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
69353+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
69354+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
69355+
69356 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
69357 NULL if none. Assume start_addr < end_addr. */
69358 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
69359@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
69360 return vma;
69361 }
69362
69363-#ifdef CONFIG_MMU
69364-pgprot_t vm_get_page_prot(unsigned long vm_flags);
69365-#else
69366-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
69367-{
69368- return __pgprot(0);
69369-}
69370-#endif
69371-
69372 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
69373 unsigned long change_prot_numa(struct vm_area_struct *vma,
69374 unsigned long start, unsigned long end);
69375@@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
69376 extern int sysctl_memory_failure_early_kill;
69377 extern int sysctl_memory_failure_recovery;
69378 extern void shake_page(struct page *p, int access);
69379-extern atomic_long_t mce_bad_pages;
69380+extern atomic_long_unchecked_t mce_bad_pages;
69381 extern int soft_offline_page(struct page *page, int flags);
69382
69383 extern void dump_page(struct page *page);
69384@@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
69385 static inline bool page_is_guard(struct page *page) { return false; }
69386 #endif /* CONFIG_DEBUG_PAGEALLOC */
69387
69388+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
69389+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
69390+#else
69391+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
69392+#endif
69393+
69394 #endif /* __KERNEL__ */
69395 #endif /* _LINUX_MM_H */
69396diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
69397index f8f5162..a039af9 100644
69398--- a/include/linux/mm_types.h
69399+++ b/include/linux/mm_types.h
69400@@ -288,6 +288,8 @@ struct vm_area_struct {
69401 #ifdef CONFIG_NUMA
69402 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
69403 #endif
69404+
69405+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
69406 };
69407
69408 struct core_thread {
69409@@ -362,7 +364,7 @@ struct mm_struct {
69410 unsigned long def_flags;
69411 unsigned long nr_ptes; /* Page table pages */
69412 unsigned long start_code, end_code, start_data, end_data;
69413- unsigned long start_brk, brk, start_stack;
69414+ unsigned long aslr_gap, start_brk, brk, start_stack;
69415 unsigned long arg_start, arg_end, env_start, env_end;
69416
69417 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
69418@@ -436,6 +438,24 @@ struct mm_struct {
69419 int first_nid;
69420 #endif
69421 struct uprobes_state uprobes_state;
69422+
69423+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69424+ unsigned long pax_flags;
69425+#endif
69426+
69427+#ifdef CONFIG_PAX_DLRESOLVE
69428+ unsigned long call_dl_resolve;
69429+#endif
69430+
69431+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
69432+ unsigned long call_syscall;
69433+#endif
69434+
69435+#ifdef CONFIG_PAX_ASLR
69436+ unsigned long delta_mmap; /* randomized offset */
69437+ unsigned long delta_stack; /* randomized offset */
69438+#endif
69439+
69440 };
69441
69442 /* first nid will either be a valid NID or one of these values */
69443diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
69444index c5d5278..f0b68c8 100644
69445--- a/include/linux/mmiotrace.h
69446+++ b/include/linux/mmiotrace.h
69447@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
69448 /* Called from ioremap.c */
69449 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
69450 void __iomem *addr);
69451-extern void mmiotrace_iounmap(volatile void __iomem *addr);
69452+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
69453
69454 /* For anyone to insert markers. Remember trailing newline. */
69455 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
69456@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
69457 {
69458 }
69459
69460-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
69461+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
69462 {
69463 }
69464
69465diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
69466index 73b64a3..6562925 100644
69467--- a/include/linux/mmzone.h
69468+++ b/include/linux/mmzone.h
69469@@ -412,7 +412,7 @@ struct zone {
69470 unsigned long flags; /* zone flags, see below */
69471
69472 /* Zone statistics */
69473- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69474+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69475
69476 /*
69477 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
69478diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
69479index fed3def..c933f99 100644
69480--- a/include/linux/mod_devicetable.h
69481+++ b/include/linux/mod_devicetable.h
69482@@ -12,7 +12,7 @@
69483 typedef unsigned long kernel_ulong_t;
69484 #endif
69485
69486-#define PCI_ANY_ID (~0)
69487+#define PCI_ANY_ID ((__u16)~0)
69488
69489 struct pci_device_id {
69490 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
69491@@ -139,7 +139,7 @@ struct usb_device_id {
69492 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
69493 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
69494
69495-#define HID_ANY_ID (~0)
69496+#define HID_ANY_ID (~0U)
69497 #define HID_BUS_ANY 0xffff
69498 #define HID_GROUP_ANY 0x0000
69499
69500@@ -498,7 +498,7 @@ struct dmi_system_id {
69501 const char *ident;
69502 struct dmi_strmatch matches[4];
69503 void *driver_data;
69504-};
69505+} __do_const;
69506 /*
69507 * struct dmi_device_id appears during expansion of
69508 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
69509diff --git a/include/linux/module.h b/include/linux/module.h
69510index 1375ee3..ced8177 100644
69511--- a/include/linux/module.h
69512+++ b/include/linux/module.h
69513@@ -17,9 +17,11 @@
69514 #include <linux/moduleparam.h>
69515 #include <linux/tracepoint.h>
69516 #include <linux/export.h>
69517+#include <linux/fs.h>
69518
69519 #include <linux/percpu.h>
69520 #include <asm/module.h>
69521+#include <asm/pgtable.h>
69522
69523 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
69524 #define MODULE_SIG_STRING "~Module signature appended~\n"
69525@@ -54,12 +56,13 @@ struct module_attribute {
69526 int (*test)(struct module *);
69527 void (*free)(struct module *);
69528 };
69529+typedef struct module_attribute __no_const module_attribute_no_const;
69530
69531 struct module_version_attribute {
69532 struct module_attribute mattr;
69533 const char *module_name;
69534 const char *version;
69535-} __attribute__ ((__aligned__(sizeof(void *))));
69536+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
69537
69538 extern ssize_t __modver_version_show(struct module_attribute *,
69539 struct module_kobject *, char *);
69540@@ -232,7 +235,7 @@ struct module
69541
69542 /* Sysfs stuff. */
69543 struct module_kobject mkobj;
69544- struct module_attribute *modinfo_attrs;
69545+ module_attribute_no_const *modinfo_attrs;
69546 const char *version;
69547 const char *srcversion;
69548 struct kobject *holders_dir;
69549@@ -281,19 +284,16 @@ struct module
69550 int (*init)(void);
69551
69552 /* If this is non-NULL, vfree after init() returns */
69553- void *module_init;
69554+ void *module_init_rx, *module_init_rw;
69555
69556 /* Here is the actual code + data, vfree'd on unload. */
69557- void *module_core;
69558+ void *module_core_rx, *module_core_rw;
69559
69560 /* Here are the sizes of the init and core sections */
69561- unsigned int init_size, core_size;
69562+ unsigned int init_size_rw, core_size_rw;
69563
69564 /* The size of the executable code in each section. */
69565- unsigned int init_text_size, core_text_size;
69566-
69567- /* Size of RO sections of the module (text+rodata) */
69568- unsigned int init_ro_size, core_ro_size;
69569+ unsigned int init_size_rx, core_size_rx;
69570
69571 /* Arch-specific module values */
69572 struct mod_arch_specific arch;
69573@@ -349,6 +349,10 @@ struct module
69574 #ifdef CONFIG_EVENT_TRACING
69575 struct ftrace_event_call **trace_events;
69576 unsigned int num_trace_events;
69577+ struct file_operations trace_id;
69578+ struct file_operations trace_enable;
69579+ struct file_operations trace_format;
69580+ struct file_operations trace_filter;
69581 #endif
69582 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
69583 unsigned int num_ftrace_callsites;
69584@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
69585 bool is_module_percpu_address(unsigned long addr);
69586 bool is_module_text_address(unsigned long addr);
69587
69588+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
69589+{
69590+
69591+#ifdef CONFIG_PAX_KERNEXEC
69592+ if (ktla_ktva(addr) >= (unsigned long)start &&
69593+ ktla_ktva(addr) < (unsigned long)start + size)
69594+ return 1;
69595+#endif
69596+
69597+ return ((void *)addr >= start && (void *)addr < start + size);
69598+}
69599+
69600+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
69601+{
69602+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
69603+}
69604+
69605+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
69606+{
69607+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
69608+}
69609+
69610+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
69611+{
69612+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
69613+}
69614+
69615+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
69616+{
69617+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
69618+}
69619+
69620 static inline int within_module_core(unsigned long addr, struct module *mod)
69621 {
69622- return (unsigned long)mod->module_core <= addr &&
69623- addr < (unsigned long)mod->module_core + mod->core_size;
69624+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
69625 }
69626
69627 static inline int within_module_init(unsigned long addr, struct module *mod)
69628 {
69629- return (unsigned long)mod->module_init <= addr &&
69630- addr < (unsigned long)mod->module_init + mod->init_size;
69631+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
69632 }
69633
69634 /* Search for module by name: must hold module_mutex. */
69635diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
69636index 560ca53..5ee8d73 100644
69637--- a/include/linux/moduleloader.h
69638+++ b/include/linux/moduleloader.h
69639@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
69640
69641 /* Allocator used for allocating struct module, core sections and init
69642 sections. Returns NULL on failure. */
69643-void *module_alloc(unsigned long size);
69644+void *module_alloc(unsigned long size) __size_overflow(1);
69645+
69646+#ifdef CONFIG_PAX_KERNEXEC
69647+void *module_alloc_exec(unsigned long size) __size_overflow(1);
69648+#else
69649+#define module_alloc_exec(x) module_alloc(x)
69650+#endif
69651
69652 /* Free memory returned from module_alloc. */
69653 void module_free(struct module *mod, void *module_region);
69654
69655+#ifdef CONFIG_PAX_KERNEXEC
69656+void module_free_exec(struct module *mod, void *module_region);
69657+#else
69658+#define module_free_exec(x, y) module_free((x), (y))
69659+#endif
69660+
69661 /*
69662 * Apply the given relocation to the (simplified) ELF. Return -error
69663 * or 0.
69664@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
69665 unsigned int relsec,
69666 struct module *me)
69667 {
69668+#ifdef CONFIG_MODULES
69669 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69670+#endif
69671 return -ENOEXEC;
69672 }
69673 #endif
69674@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
69675 unsigned int relsec,
69676 struct module *me)
69677 {
69678+#ifdef CONFIG_MODULES
69679 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69680+#endif
69681 return -ENOEXEC;
69682 }
69683 #endif
69684diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
69685index 137b419..fe663ec 100644
69686--- a/include/linux/moduleparam.h
69687+++ b/include/linux/moduleparam.h
69688@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
69689 * @len is usually just sizeof(string).
69690 */
69691 #define module_param_string(name, string, len, perm) \
69692- static const struct kparam_string __param_string_##name \
69693+ static const struct kparam_string __param_string_##name __used \
69694 = { len, string }; \
69695 __module_param_call(MODULE_PARAM_PREFIX, name, \
69696 &param_ops_string, \
69697@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
69698 */
69699 #define module_param_array_named(name, array, type, nump, perm) \
69700 param_check_##type(name, &(array)[0]); \
69701- static const struct kparam_array __param_arr_##name \
69702+ static const struct kparam_array __param_arr_##name __used \
69703 = { .max = ARRAY_SIZE(array), .num = nump, \
69704 .ops = &param_ops_##type, \
69705 .elemsize = sizeof(array[0]), .elem = array }; \
69706diff --git a/include/linux/namei.h b/include/linux/namei.h
69707index 5a5ff57..5ae5070 100644
69708--- a/include/linux/namei.h
69709+++ b/include/linux/namei.h
69710@@ -19,7 +19,7 @@ struct nameidata {
69711 unsigned seq;
69712 int last_type;
69713 unsigned depth;
69714- char *saved_names[MAX_NESTED_LINKS + 1];
69715+ const char *saved_names[MAX_NESTED_LINKS + 1];
69716 };
69717
69718 /*
69719@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
69720
69721 extern void nd_jump_link(struct nameidata *nd, struct path *path);
69722
69723-static inline void nd_set_link(struct nameidata *nd, char *path)
69724+static inline void nd_set_link(struct nameidata *nd, const char *path)
69725 {
69726 nd->saved_names[nd->depth] = path;
69727 }
69728
69729-static inline char *nd_get_link(struct nameidata *nd)
69730+static inline const char *nd_get_link(const struct nameidata *nd)
69731 {
69732 return nd->saved_names[nd->depth];
69733 }
69734diff --git a/include/linux/net.h b/include/linux/net.h
69735index aa16731..514b875 100644
69736--- a/include/linux/net.h
69737+++ b/include/linux/net.h
69738@@ -183,7 +183,7 @@ struct net_proto_family {
69739 int (*create)(struct net *net, struct socket *sock,
69740 int protocol, int kern);
69741 struct module *owner;
69742-};
69743+} __do_const;
69744
69745 struct iovec;
69746 struct kvec;
69747diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
69748index 9ef07d0..130a5d9 100644
69749--- a/include/linux/netdevice.h
69750+++ b/include/linux/netdevice.h
69751@@ -1012,6 +1012,7 @@ struct net_device_ops {
69752 u32 pid, u32 seq,
69753 struct net_device *dev);
69754 };
69755+typedef struct net_device_ops __no_const net_device_ops_no_const;
69756
69757 /*
69758 * The DEVICE structure.
69759@@ -1078,7 +1079,7 @@ struct net_device {
69760 int iflink;
69761
69762 struct net_device_stats stats;
69763- atomic_long_t rx_dropped; /* dropped packets by core network
69764+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
69765 * Do not use this in drivers.
69766 */
69767
69768diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
69769index ee14284..bc65d63 100644
69770--- a/include/linux/netfilter.h
69771+++ b/include/linux/netfilter.h
69772@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
69773 #endif
69774 /* Use the module struct to lock set/get code in place */
69775 struct module *owner;
69776-};
69777+} __do_const;
69778
69779 /* Function to register/unregister hook points. */
69780 int nf_register_hook(struct nf_hook_ops *reg);
69781diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
69782index 7958e84..ed74d7a 100644
69783--- a/include/linux/netfilter/ipset/ip_set.h
69784+++ b/include/linux/netfilter/ipset/ip_set.h
69785@@ -98,7 +98,7 @@ struct ip_set_type_variant {
69786 /* Return true if "b" set is the same as "a"
69787 * according to the create set parameters */
69788 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
69789-};
69790+} __do_const;
69791
69792 /* The core set type structure */
69793 struct ip_set_type {
69794diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
69795index 4966dde..7d8ce06 100644
69796--- a/include/linux/netfilter/nfnetlink.h
69797+++ b/include/linux/netfilter/nfnetlink.h
69798@@ -16,7 +16,7 @@ struct nfnl_callback {
69799 const struct nlattr * const cda[]);
69800 const struct nla_policy *policy; /* netlink attribute policy */
69801 const u_int16_t attr_count; /* number of nlattr's */
69802-};
69803+} __do_const;
69804
69805 struct nfnetlink_subsystem {
69806 const char *name;
69807diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
69808new file mode 100644
69809index 0000000..33f4af8
69810--- /dev/null
69811+++ b/include/linux/netfilter/xt_gradm.h
69812@@ -0,0 +1,9 @@
69813+#ifndef _LINUX_NETFILTER_XT_GRADM_H
69814+#define _LINUX_NETFILTER_XT_GRADM_H 1
69815+
69816+struct xt_gradm_mtinfo {
69817+ __u16 flags;
69818+ __u16 invflags;
69819+};
69820+
69821+#endif
69822diff --git a/include/linux/nls.h b/include/linux/nls.h
69823index 5dc635f..35f5e11 100644
69824--- a/include/linux/nls.h
69825+++ b/include/linux/nls.h
69826@@ -31,7 +31,7 @@ struct nls_table {
69827 const unsigned char *charset2upper;
69828 struct module *owner;
69829 struct nls_table *next;
69830-};
69831+} __do_const;
69832
69833 /* this value hold the maximum octet of charset */
69834 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
69835diff --git a/include/linux/notifier.h b/include/linux/notifier.h
69836index d65746e..62e72c2 100644
69837--- a/include/linux/notifier.h
69838+++ b/include/linux/notifier.h
69839@@ -51,7 +51,8 @@ struct notifier_block {
69840 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
69841 struct notifier_block __rcu *next;
69842 int priority;
69843-};
69844+} __do_const;
69845+typedef struct notifier_block __no_const notifier_block_no_const;
69846
69847 struct atomic_notifier_head {
69848 spinlock_t lock;
69849diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
69850index a4c5624..79d6d88 100644
69851--- a/include/linux/oprofile.h
69852+++ b/include/linux/oprofile.h
69853@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
69854 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
69855 char const * name, ulong * val);
69856
69857-/** Create a file for read-only access to an atomic_t. */
69858+/** Create a file for read-only access to an atomic_unchecked_t. */
69859 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
69860- char const * name, atomic_t * val);
69861+ char const * name, atomic_unchecked_t * val);
69862
69863 /** create a directory */
69864 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
69865diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
69866index 45fc162..01a4068 100644
69867--- a/include/linux/pci_hotplug.h
69868+++ b/include/linux/pci_hotplug.h
69869@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
69870 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
69871 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
69872 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
69873-};
69874+} __do_const;
69875+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
69876
69877 /**
69878 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
69879diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
69880index 6bfb2faa..e5bc5e5 100644
69881--- a/include/linux/perf_event.h
69882+++ b/include/linux/perf_event.h
69883@@ -328,8 +328,8 @@ struct perf_event {
69884
69885 enum perf_event_active_state state;
69886 unsigned int attach_state;
69887- local64_t count;
69888- atomic64_t child_count;
69889+ local64_t count; /* PaX: fix it one day */
69890+ atomic64_unchecked_t child_count;
69891
69892 /*
69893 * These are the total time in nanoseconds that the event
69894@@ -380,8 +380,8 @@ struct perf_event {
69895 * These accumulate total time (in nanoseconds) that children
69896 * events have been enabled and running, respectively.
69897 */
69898- atomic64_t child_total_time_enabled;
69899- atomic64_t child_total_time_running;
69900+ atomic64_unchecked_t child_total_time_enabled;
69901+ atomic64_unchecked_t child_total_time_running;
69902
69903 /*
69904 * Protect attach/detach and child_list:
69905@@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
69906 */
69907 #define perf_cpu_notifier(fn) \
69908 do { \
69909- static struct notifier_block fn##_nb __cpuinitdata = \
69910+ static struct notifier_block fn##_nb = \
69911 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
69912 unsigned long cpu = smp_processor_id(); \
69913 unsigned long flags; \
69914diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
69915index ad1a427..6419649 100644
69916--- a/include/linux/pipe_fs_i.h
69917+++ b/include/linux/pipe_fs_i.h
69918@@ -45,9 +45,9 @@ struct pipe_buffer {
69919 struct pipe_inode_info {
69920 wait_queue_head_t wait;
69921 unsigned int nrbufs, curbuf, buffers;
69922- unsigned int readers;
69923- unsigned int writers;
69924- unsigned int waiting_writers;
69925+ atomic_t readers;
69926+ atomic_t writers;
69927+ atomic_t waiting_writers;
69928 unsigned int r_counter;
69929 unsigned int w_counter;
69930 struct page *tmp_page;
69931diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
69932index 5f28cae..3d23723 100644
69933--- a/include/linux/platform_data/usb-ehci-s5p.h
69934+++ b/include/linux/platform_data/usb-ehci-s5p.h
69935@@ -14,7 +14,7 @@
69936 struct s5p_ehci_platdata {
69937 int (*phy_init)(struct platform_device *pdev, int type);
69938 int (*phy_exit)(struct platform_device *pdev, int type);
69939-};
69940+} __no_const;
69941
69942 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
69943
69944diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
69945index c256c59..8ea94c7 100644
69946--- a/include/linux/platform_data/usb-exynos.h
69947+++ b/include/linux/platform_data/usb-exynos.h
69948@@ -14,7 +14,7 @@
69949 struct exynos4_ohci_platdata {
69950 int (*phy_init)(struct platform_device *pdev, int type);
69951 int (*phy_exit)(struct platform_device *pdev, int type);
69952-};
69953+} __no_const;
69954
69955 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
69956
69957diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
69958index 7c1d252..c5c773e 100644
69959--- a/include/linux/pm_domain.h
69960+++ b/include/linux/pm_domain.h
69961@@ -48,7 +48,7 @@ struct gpd_dev_ops {
69962
69963 struct gpd_cpu_data {
69964 unsigned int saved_exit_latency;
69965- struct cpuidle_state *idle_state;
69966+ cpuidle_state_no_const *idle_state;
69967 };
69968
69969 struct generic_pm_domain {
69970diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
69971index f271860..6b3bec5 100644
69972--- a/include/linux/pm_runtime.h
69973+++ b/include/linux/pm_runtime.h
69974@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
69975
69976 static inline void pm_runtime_mark_last_busy(struct device *dev)
69977 {
69978- ACCESS_ONCE(dev->power.last_busy) = jiffies;
69979+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
69980 }
69981
69982 #else /* !CONFIG_PM_RUNTIME */
69983diff --git a/include/linux/pnp.h b/include/linux/pnp.h
69984index 195aafc..49a7bc2 100644
69985--- a/include/linux/pnp.h
69986+++ b/include/linux/pnp.h
69987@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
69988 struct pnp_fixup {
69989 char id[7];
69990 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
69991-};
69992+} __do_const;
69993
69994 /* config parameters */
69995 #define PNP_CONFIG_NORMAL 0x0001
69996diff --git a/include/linux/poison.h b/include/linux/poison.h
69997index 2110a81..13a11bb 100644
69998--- a/include/linux/poison.h
69999+++ b/include/linux/poison.h
70000@@ -19,8 +19,8 @@
70001 * under normal circumstances, used to verify that nobody uses
70002 * non-initialized list entries.
70003 */
70004-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
70005-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
70006+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
70007+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
70008
70009 /********** include/linux/timer.h **********/
70010 /*
70011diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
70012index c0f44c2..1572583 100644
70013--- a/include/linux/power/smartreflex.h
70014+++ b/include/linux/power/smartreflex.h
70015@@ -238,7 +238,7 @@ struct omap_sr_class_data {
70016 int (*notify)(struct omap_sr *sr, u32 status);
70017 u8 notify_flags;
70018 u8 class_type;
70019-};
70020+} __do_const;
70021
70022 /**
70023 * struct omap_sr_nvalue_table - Smartreflex n-target value info
70024diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
70025index 4ea1d37..80f4b33 100644
70026--- a/include/linux/ppp-comp.h
70027+++ b/include/linux/ppp-comp.h
70028@@ -84,7 +84,7 @@ struct compressor {
70029 struct module *owner;
70030 /* Extra skb space needed by the compressor algorithm */
70031 unsigned int comp_extra;
70032-};
70033+} __do_const;
70034
70035 /*
70036 * The return value from decompress routine is the length of the
70037diff --git a/include/linux/printk.h b/include/linux/printk.h
70038index 9afc01e..92c32e8 100644
70039--- a/include/linux/printk.h
70040+++ b/include/linux/printk.h
70041@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
70042 extern int printk_needs_cpu(int cpu);
70043 extern void printk_tick(void);
70044
70045+extern int kptr_restrict;
70046+
70047 #ifdef CONFIG_PRINTK
70048 asmlinkage __printf(5, 0)
70049 int vprintk_emit(int facility, int level,
70050@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
70051
70052 extern int printk_delay_msec;
70053 extern int dmesg_restrict;
70054-extern int kptr_restrict;
70055
70056 void log_buf_kexec_setup(void);
70057 void __init setup_log_buf(int early);
70058diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
70059index 32676b3..8f7a182 100644
70060--- a/include/linux/proc_fs.h
70061+++ b/include/linux/proc_fs.h
70062@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
70063 return proc_create_data(name, mode, parent, proc_fops, NULL);
70064 }
70065
70066+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
70067+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
70068+{
70069+#ifdef CONFIG_GRKERNSEC_PROC_USER
70070+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
70071+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70072+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
70073+#else
70074+ return proc_create_data(name, mode, parent, proc_fops, NULL);
70075+#endif
70076+}
70077+
70078 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
70079 umode_t mode, struct proc_dir_entry *base,
70080 read_proc_t *read_proc, void * data)
70081diff --git a/include/linux/random.h b/include/linux/random.h
70082index d984608..d6f0042 100644
70083--- a/include/linux/random.h
70084+++ b/include/linux/random.h
70085@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
70086 u32 prandom_u32_state(struct rnd_state *);
70087 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
70088
70089+static inline unsigned long pax_get_random_long(void)
70090+{
70091+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
70092+}
70093+
70094 /*
70095 * Handle minimum values for seeds
70096 */
70097diff --git a/include/linux/rculist.h b/include/linux/rculist.h
70098index c92dd28..08f4eab 100644
70099--- a/include/linux/rculist.h
70100+++ b/include/linux/rculist.h
70101@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
70102 struct list_head *prev, struct list_head *next);
70103 #endif
70104
70105+extern void __pax_list_add_rcu(struct list_head *new,
70106+ struct list_head *prev, struct list_head *next);
70107+
70108 /**
70109 * list_add_rcu - add a new entry to rcu-protected list
70110 * @new: new entry to be added
70111@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
70112 __list_add_rcu(new, head, head->next);
70113 }
70114
70115+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
70116+{
70117+ __pax_list_add_rcu(new, head, head->next);
70118+}
70119+
70120 /**
70121 * list_add_tail_rcu - add a new entry to rcu-protected list
70122 * @new: new entry to be added
70123@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
70124 __list_add_rcu(new, head->prev, head);
70125 }
70126
70127+static inline void pax_list_add_tail_rcu(struct list_head *new,
70128+ struct list_head *head)
70129+{
70130+ __pax_list_add_rcu(new, head->prev, head);
70131+}
70132+
70133 /**
70134 * list_del_rcu - deletes entry from list without re-initialization
70135 * @entry: the element to delete from the list.
70136@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
70137 entry->prev = LIST_POISON2;
70138 }
70139
70140+extern void pax_list_del_rcu(struct list_head *entry);
70141+
70142 /**
70143 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
70144 * @n: the element to delete from the hash list.
70145diff --git a/include/linux/reboot.h b/include/linux/reboot.h
70146index 23b3630..e1bc12b 100644
70147--- a/include/linux/reboot.h
70148+++ b/include/linux/reboot.h
70149@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
70150 * Architecture-specific implementations of sys_reboot commands.
70151 */
70152
70153-extern void machine_restart(char *cmd);
70154-extern void machine_halt(void);
70155-extern void machine_power_off(void);
70156+extern void machine_restart(char *cmd) __noreturn;
70157+extern void machine_halt(void) __noreturn;
70158+extern void machine_power_off(void) __noreturn;
70159
70160 extern void machine_shutdown(void);
70161 struct pt_regs;
70162@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
70163 */
70164
70165 extern void kernel_restart_prepare(char *cmd);
70166-extern void kernel_restart(char *cmd);
70167-extern void kernel_halt(void);
70168-extern void kernel_power_off(void);
70169+extern void kernel_restart(char *cmd) __noreturn;
70170+extern void kernel_halt(void) __noreturn;
70171+extern void kernel_power_off(void) __noreturn;
70172
70173 extern int C_A_D; /* for sysctl */
70174 void ctrl_alt_del(void);
70175@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
70176 * Emergency restart, callable from an interrupt handler.
70177 */
70178
70179-extern void emergency_restart(void);
70180+extern void emergency_restart(void) __noreturn;
70181 #include <asm/emergency-restart.h>
70182
70183 #endif /* _LINUX_REBOOT_H */
70184diff --git a/include/linux/regset.h b/include/linux/regset.h
70185index 8e0c9fe..ac4d221 100644
70186--- a/include/linux/regset.h
70187+++ b/include/linux/regset.h
70188@@ -161,7 +161,8 @@ struct user_regset {
70189 unsigned int align;
70190 unsigned int bias;
70191 unsigned int core_note_type;
70192-};
70193+} __do_const;
70194+typedef struct user_regset __no_const user_regset_no_const;
70195
70196 /**
70197 * struct user_regset_view - available regsets
70198diff --git a/include/linux/relay.h b/include/linux/relay.h
70199index 91cacc3..b55ff74 100644
70200--- a/include/linux/relay.h
70201+++ b/include/linux/relay.h
70202@@ -160,7 +160,7 @@ struct rchan_callbacks
70203 * The callback should return 0 if successful, negative if not.
70204 */
70205 int (*remove_buf_file)(struct dentry *dentry);
70206-};
70207+} __no_const;
70208
70209 /*
70210 * CONFIG_RELAY kernel API, kernel/relay.c
70211diff --git a/include/linux/rio.h b/include/linux/rio.h
70212index a3e7842..d973ca6 100644
70213--- a/include/linux/rio.h
70214+++ b/include/linux/rio.h
70215@@ -339,7 +339,7 @@ struct rio_ops {
70216 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
70217 u64 rstart, u32 size, u32 flags);
70218 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
70219-};
70220+} __no_const;
70221
70222 #define RIO_RESOURCE_MEM 0x00000100
70223 #define RIO_RESOURCE_DOORBELL 0x00000200
70224diff --git a/include/linux/rmap.h b/include/linux/rmap.h
70225index c20635c..2f5def4 100644
70226--- a/include/linux/rmap.h
70227+++ b/include/linux/rmap.h
70228@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
70229 void anon_vma_init(void); /* create anon_vma_cachep */
70230 int anon_vma_prepare(struct vm_area_struct *);
70231 void unlink_anon_vmas(struct vm_area_struct *);
70232-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
70233-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
70234+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
70235+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
70236
70237 static inline void anon_vma_merge(struct vm_area_struct *vma,
70238 struct vm_area_struct *next)
70239diff --git a/include/linux/sched.h b/include/linux/sched.h
70240index d211247..eac6c2c 100644
70241--- a/include/linux/sched.h
70242+++ b/include/linux/sched.h
70243@@ -61,6 +61,7 @@ struct bio_list;
70244 struct fs_struct;
70245 struct perf_event_context;
70246 struct blk_plug;
70247+struct linux_binprm;
70248
70249 /*
70250 * List of flags we want to share for kernel threads,
70251@@ -327,7 +328,7 @@ extern char __sched_text_start[], __sched_text_end[];
70252 extern int in_sched_functions(unsigned long addr);
70253
70254 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
70255-extern signed long schedule_timeout(signed long timeout);
70256+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
70257 extern signed long schedule_timeout_interruptible(signed long timeout);
70258 extern signed long schedule_timeout_killable(signed long timeout);
70259 extern signed long schedule_timeout_uninterruptible(signed long timeout);
70260@@ -354,10 +355,23 @@ struct user_namespace;
70261 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
70262
70263 extern int sysctl_max_map_count;
70264+extern unsigned long sysctl_heap_stack_gap;
70265
70266 #include <linux/aio.h>
70267
70268 #ifdef CONFIG_MMU
70269+
70270+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
70271+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
70272+#else
70273+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
70274+{
70275+ return 0;
70276+}
70277+#endif
70278+
70279+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
70280+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
70281 extern void arch_pick_mmap_layout(struct mm_struct *mm);
70282 extern unsigned long
70283 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
70284@@ -639,6 +653,17 @@ struct signal_struct {
70285 #ifdef CONFIG_TASKSTATS
70286 struct taskstats *stats;
70287 #endif
70288+
70289+#ifdef CONFIG_GRKERNSEC
70290+ u32 curr_ip;
70291+ u32 saved_ip;
70292+ u32 gr_saddr;
70293+ u32 gr_daddr;
70294+ u16 gr_sport;
70295+ u16 gr_dport;
70296+ u8 used_accept:1;
70297+#endif
70298+
70299 #ifdef CONFIG_AUDIT
70300 unsigned audit_tty;
70301 struct tty_audit_buf *tty_audit_buf;
70302@@ -717,6 +742,11 @@ struct user_struct {
70303 struct key *session_keyring; /* UID's default session keyring */
70304 #endif
70305
70306+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
70307+ unsigned int banned;
70308+ unsigned long ban_expires;
70309+#endif
70310+
70311 /* Hash table maintenance information */
70312 struct hlist_node uidhash_node;
70313 kuid_t uid;
70314@@ -1116,7 +1146,7 @@ struct sched_class {
70315 #ifdef CONFIG_FAIR_GROUP_SCHED
70316 void (*task_move_group) (struct task_struct *p, int on_rq);
70317 #endif
70318-};
70319+} __do_const;
70320
70321 struct load_weight {
70322 unsigned long weight, inv_weight;
70323@@ -1360,8 +1390,8 @@ struct task_struct {
70324 struct list_head thread_group;
70325
70326 struct completion *vfork_done; /* for vfork() */
70327- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
70328- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70329+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
70330+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70331
70332 cputime_t utime, stime, utimescaled, stimescaled;
70333 cputime_t gtime;
70334@@ -1377,11 +1407,6 @@ struct task_struct {
70335 struct task_cputime cputime_expires;
70336 struct list_head cpu_timers[3];
70337
70338-/* process credentials */
70339- const struct cred __rcu *real_cred; /* objective and real subjective task
70340- * credentials (COW) */
70341- const struct cred __rcu *cred; /* effective (overridable) subjective task
70342- * credentials (COW) */
70343 char comm[TASK_COMM_LEN]; /* executable name excluding path
70344 - access with [gs]et_task_comm (which lock
70345 it with task_lock())
70346@@ -1398,6 +1423,10 @@ struct task_struct {
70347 #endif
70348 /* CPU-specific state of this task */
70349 struct thread_struct thread;
70350+/* thread_info moved to task_struct */
70351+#ifdef CONFIG_X86
70352+ struct thread_info tinfo;
70353+#endif
70354 /* filesystem information */
70355 struct fs_struct *fs;
70356 /* open file information */
70357@@ -1471,6 +1500,10 @@ struct task_struct {
70358 gfp_t lockdep_reclaim_gfp;
70359 #endif
70360
70361+/* process credentials */
70362+ const struct cred __rcu *real_cred; /* objective and real subjective task
70363+ * credentials (COW) */
70364+
70365 /* journalling filesystem info */
70366 void *journal_info;
70367
70368@@ -1509,6 +1542,10 @@ struct task_struct {
70369 /* cg_list protected by css_set_lock and tsk->alloc_lock */
70370 struct list_head cg_list;
70371 #endif
70372+
70373+ const struct cred __rcu *cred; /* effective (overridable) subjective task
70374+ * credentials (COW) */
70375+
70376 #ifdef CONFIG_FUTEX
70377 struct robust_list_head __user *robust_list;
70378 #ifdef CONFIG_COMPAT
70379@@ -1605,8 +1642,74 @@ struct task_struct {
70380 #ifdef CONFIG_UPROBES
70381 struct uprobe_task *utask;
70382 #endif
70383+
70384+#ifdef CONFIG_GRKERNSEC
70385+ /* grsecurity */
70386+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70387+ u64 exec_id;
70388+#endif
70389+#ifdef CONFIG_GRKERNSEC_SETXID
70390+ const struct cred *delayed_cred;
70391+#endif
70392+ struct dentry *gr_chroot_dentry;
70393+ struct acl_subject_label *acl;
70394+ struct acl_role_label *role;
70395+ struct file *exec_file;
70396+ unsigned long brute_expires;
70397+ u16 acl_role_id;
70398+ /* is this the task that authenticated to the special role */
70399+ u8 acl_sp_role;
70400+ u8 is_writable;
70401+ u8 brute;
70402+ u8 gr_is_chrooted;
70403+#endif
70404+
70405 };
70406
70407+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
70408+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
70409+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
70410+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
70411+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
70412+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
70413+
70414+#ifdef CONFIG_PAX_SOFTMODE
70415+extern int pax_softmode;
70416+#endif
70417+
70418+extern int pax_check_flags(unsigned long *);
70419+
70420+/* if tsk != current then task_lock must be held on it */
70421+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70422+static inline unsigned long pax_get_flags(struct task_struct *tsk)
70423+{
70424+ if (likely(tsk->mm))
70425+ return tsk->mm->pax_flags;
70426+ else
70427+ return 0UL;
70428+}
70429+
70430+/* if tsk != current then task_lock must be held on it */
70431+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
70432+{
70433+ if (likely(tsk->mm)) {
70434+ tsk->mm->pax_flags = flags;
70435+ return 0;
70436+ }
70437+ return -EINVAL;
70438+}
70439+#endif
70440+
70441+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
70442+extern void pax_set_initial_flags(struct linux_binprm *bprm);
70443+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
70444+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
70445+#endif
70446+
70447+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
70448+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
70449+extern void pax_report_refcount_overflow(struct pt_regs *regs);
70450+
70451 /* Future-safe accessor for struct task_struct's cpus_allowed. */
70452 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
70453
70454@@ -1696,7 +1799,7 @@ struct pid_namespace;
70455 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
70456 struct pid_namespace *ns);
70457
70458-static inline pid_t task_pid_nr(struct task_struct *tsk)
70459+static inline pid_t task_pid_nr(const struct task_struct *tsk)
70460 {
70461 return tsk->pid;
70462 }
70463@@ -2155,7 +2258,9 @@ void yield(void);
70464 extern struct exec_domain default_exec_domain;
70465
70466 union thread_union {
70467+#ifndef CONFIG_X86
70468 struct thread_info thread_info;
70469+#endif
70470 unsigned long stack[THREAD_SIZE/sizeof(long)];
70471 };
70472
70473@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
70474 */
70475
70476 extern struct task_struct *find_task_by_vpid(pid_t nr);
70477+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
70478 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
70479 struct pid_namespace *ns);
70480
70481@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
70482 extern void exit_itimers(struct signal_struct *);
70483 extern void flush_itimer_signals(void);
70484
70485-extern void do_group_exit(int);
70486+extern __noreturn void do_group_exit(int);
70487
70488 extern int allow_signal(int);
70489 extern int disallow_signal(int);
70490@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
70491
70492 #endif
70493
70494-static inline int object_is_on_stack(void *obj)
70495+static inline int object_starts_on_stack(void *obj)
70496 {
70497- void *stack = task_stack_page(current);
70498+ const void *stack = task_stack_page(current);
70499
70500 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
70501 }
70502diff --git a/include/linux/security.h b/include/linux/security.h
70503index eee7478..290f7ba 100644
70504--- a/include/linux/security.h
70505+++ b/include/linux/security.h
70506@@ -26,6 +26,7 @@
70507 #include <linux/capability.h>
70508 #include <linux/slab.h>
70509 #include <linux/err.h>
70510+#include <linux/grsecurity.h>
70511
70512 struct linux_binprm;
70513 struct cred;
70514diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
70515index 68a04a3..866e6a1 100644
70516--- a/include/linux/seq_file.h
70517+++ b/include/linux/seq_file.h
70518@@ -26,6 +26,9 @@ struct seq_file {
70519 struct mutex lock;
70520 const struct seq_operations *op;
70521 int poll_event;
70522+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70523+ u64 exec_id;
70524+#endif
70525 #ifdef CONFIG_USER_NS
70526 struct user_namespace *user_ns;
70527 #endif
70528@@ -38,6 +41,7 @@ struct seq_operations {
70529 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
70530 int (*show) (struct seq_file *m, void *v);
70531 };
70532+typedef struct seq_operations __no_const seq_operations_no_const;
70533
70534 #define SEQ_SKIP 1
70535
70536diff --git a/include/linux/shm.h b/include/linux/shm.h
70537index 429c199..4d42e38 100644
70538--- a/include/linux/shm.h
70539+++ b/include/linux/shm.h
70540@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
70541
70542 /* The task created the shm object. NULL if the task is dead. */
70543 struct task_struct *shm_creator;
70544+#ifdef CONFIG_GRKERNSEC
70545+ time_t shm_createtime;
70546+ pid_t shm_lapid;
70547+#endif
70548 };
70549
70550 /* shm_mode upper byte flags */
70551diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
70552index 320e976..fd52553 100644
70553--- a/include/linux/skbuff.h
70554+++ b/include/linux/skbuff.h
70555@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
70556 extern struct sk_buff *__alloc_skb(unsigned int size,
70557 gfp_t priority, int flags, int node);
70558 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
70559-static inline struct sk_buff *alloc_skb(unsigned int size,
70560+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
70561 gfp_t priority)
70562 {
70563 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
70564@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
70565 */
70566 static inline int skb_queue_empty(const struct sk_buff_head *list)
70567 {
70568- return list->next == (struct sk_buff *)list;
70569+ return list->next == (const struct sk_buff *)list;
70570 }
70571
70572 /**
70573@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
70574 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70575 const struct sk_buff *skb)
70576 {
70577- return skb->next == (struct sk_buff *)list;
70578+ return skb->next == (const struct sk_buff *)list;
70579 }
70580
70581 /**
70582@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70583 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
70584 const struct sk_buff *skb)
70585 {
70586- return skb->prev == (struct sk_buff *)list;
70587+ return skb->prev == (const struct sk_buff *)list;
70588 }
70589
70590 /**
70591@@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
70592 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
70593 */
70594 #ifndef NET_SKB_PAD
70595-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
70596+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
70597 #endif
70598
70599 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
70600@@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
70601 int noblock, int *err);
70602 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
70603 struct poll_table_struct *wait);
70604-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
70605+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
70606 int offset, struct iovec *to,
70607 int size);
70608 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
70609diff --git a/include/linux/slab.h b/include/linux/slab.h
70610index 5d168d7..720bff3 100644
70611--- a/include/linux/slab.h
70612+++ b/include/linux/slab.h
70613@@ -12,13 +12,20 @@
70614 #include <linux/gfp.h>
70615 #include <linux/types.h>
70616 #include <linux/workqueue.h>
70617-
70618+#include <linux/err.h>
70619
70620 /*
70621 * Flags to pass to kmem_cache_create().
70622 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
70623 */
70624 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
70625+
70626+#ifdef CONFIG_PAX_USERCOPY_SLABS
70627+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
70628+#else
70629+#define SLAB_USERCOPY 0x00000000UL
70630+#endif
70631+
70632 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
70633 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
70634 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
70635@@ -89,10 +96,13 @@
70636 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
70637 * Both make kfree a no-op.
70638 */
70639-#define ZERO_SIZE_PTR ((void *)16)
70640+#define ZERO_SIZE_PTR \
70641+({ \
70642+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
70643+ (void *)(-MAX_ERRNO-1L); \
70644+})
70645
70646-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
70647- (unsigned long)ZERO_SIZE_PTR)
70648+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
70649
70650 /*
70651 * Common fields provided in kmem_cache by all slab allocators
70652@@ -112,7 +122,7 @@ struct kmem_cache {
70653 unsigned int align; /* Alignment as calculated */
70654 unsigned long flags; /* Active flags on the slab */
70655 const char *name; /* Slab name for sysfs */
70656- int refcount; /* Use counter */
70657+ atomic_t refcount; /* Use counter */
70658 void (*ctor)(void *); /* Called on object slot creation */
70659 struct list_head list; /* List of all slab caches on the system */
70660 };
70661@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
70662 void kfree(const void *);
70663 void kzfree(const void *);
70664 size_t ksize(const void *);
70665+const char *check_heap_object(const void *ptr, unsigned long n);
70666+bool is_usercopy_object(const void *ptr);
70667
70668 /*
70669 * Allocator specific definitions. These are mainly used to establish optimized
70670@@ -311,6 +323,7 @@ size_t ksize(const void *);
70671 * for general use, and so are not documented here. For a full list of
70672 * potential flags, always refer to linux/gfp.h.
70673 */
70674+
70675 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
70676 {
70677 if (size != 0 && n > SIZE_MAX / size)
70678@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
70679 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70680 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70681 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70682-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70683+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
70684 #define kmalloc_track_caller(size, flags) \
70685 __kmalloc_track_caller(size, flags, _RET_IP_)
70686 #else
70687@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70688 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70689 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70690 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70691-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
70692+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
70693 #define kmalloc_node_track_caller(size, flags, node) \
70694 __kmalloc_node_track_caller(size, flags, node, \
70695 _RET_IP_)
70696diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
70697index 8bb6e0e..8eb0dbe 100644
70698--- a/include/linux/slab_def.h
70699+++ b/include/linux/slab_def.h
70700@@ -52,7 +52,7 @@ struct kmem_cache {
70701 /* 4) cache creation/removal */
70702 const char *name;
70703 struct list_head list;
70704- int refcount;
70705+ atomic_t refcount;
70706 int object_size;
70707 int align;
70708
70709@@ -68,10 +68,10 @@ struct kmem_cache {
70710 unsigned long node_allocs;
70711 unsigned long node_frees;
70712 unsigned long node_overflow;
70713- atomic_t allochit;
70714- atomic_t allocmiss;
70715- atomic_t freehit;
70716- atomic_t freemiss;
70717+ atomic_unchecked_t allochit;
70718+ atomic_unchecked_t allocmiss;
70719+ atomic_unchecked_t freehit;
70720+ atomic_unchecked_t freemiss;
70721
70722 /*
70723 * If debugging is enabled, then the allocator can add additional
70724@@ -111,11 +111,16 @@ struct cache_sizes {
70725 #ifdef CONFIG_ZONE_DMA
70726 struct kmem_cache *cs_dmacachep;
70727 #endif
70728+
70729+#ifdef CONFIG_PAX_USERCOPY_SLABS
70730+ struct kmem_cache *cs_usercopycachep;
70731+#endif
70732+
70733 };
70734 extern struct cache_sizes malloc_sizes[];
70735
70736 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70737-void *__kmalloc(size_t size, gfp_t flags);
70738+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
70739
70740 #ifdef CONFIG_TRACING
70741 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
70742@@ -152,6 +157,13 @@ found:
70743 cachep = malloc_sizes[i].cs_dmacachep;
70744 else
70745 #endif
70746+
70747+#ifdef CONFIG_PAX_USERCOPY_SLABS
70748+ if (flags & GFP_USERCOPY)
70749+ cachep = malloc_sizes[i].cs_usercopycachep;
70750+ else
70751+#endif
70752+
70753 cachep = malloc_sizes[i].cs_cachep;
70754
70755 ret = kmem_cache_alloc_trace(cachep, flags, size);
70756@@ -162,7 +174,7 @@ found:
70757 }
70758
70759 #ifdef CONFIG_NUMA
70760-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
70761+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70762 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70763
70764 #ifdef CONFIG_TRACING
70765@@ -205,6 +217,13 @@ found:
70766 cachep = malloc_sizes[i].cs_dmacachep;
70767 else
70768 #endif
70769+
70770+#ifdef CONFIG_PAX_USERCOPY_SLABS
70771+ if (flags & GFP_USERCOPY)
70772+ cachep = malloc_sizes[i].cs_usercopycachep;
70773+ else
70774+#endif
70775+
70776 cachep = malloc_sizes[i].cs_cachep;
70777
70778 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
70779diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
70780index f28e14a..7831211 100644
70781--- a/include/linux/slob_def.h
70782+++ b/include/linux/slob_def.h
70783@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
70784 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
70785 }
70786
70787-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70788+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70789
70790 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
70791 {
70792@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70793 return __kmalloc_node(size, flags, NUMA_NO_NODE);
70794 }
70795
70796-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
70797+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
70798 {
70799 return kmalloc(size, flags);
70800 }
70801diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
70802index 9db4825..ed42fb5 100644
70803--- a/include/linux/slub_def.h
70804+++ b/include/linux/slub_def.h
70805@@ -91,7 +91,7 @@ struct kmem_cache {
70806 struct kmem_cache_order_objects max;
70807 struct kmem_cache_order_objects min;
70808 gfp_t allocflags; /* gfp flags to use on each alloc */
70809- int refcount; /* Refcount for slab cache destroy */
70810+ atomic_t refcount; /* Refcount for slab cache destroy */
70811 void (*ctor)(void *);
70812 int inuse; /* Offset to metadata */
70813 int align; /* Alignment */
70814@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
70815 * Sorry that the following has to be that ugly but some versions of GCC
70816 * have trouble with constant propagation and loops.
70817 */
70818-static __always_inline int kmalloc_index(size_t size)
70819+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
70820 {
70821 if (!size)
70822 return 0;
70823@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
70824 }
70825
70826 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70827-void *__kmalloc(size_t size, gfp_t flags);
70828+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
70829
70830 static __always_inline void *
70831 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
70832@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
70833 }
70834 #endif
70835
70836-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
70837+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
70838 {
70839 unsigned int order = get_order(size);
70840 return kmalloc_order_trace(size, flags, order);
70841@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70842 }
70843
70844 #ifdef CONFIG_NUMA
70845-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70846+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70847 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70848
70849 #ifdef CONFIG_TRACING
70850diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
70851index e8d702e..0a56eb4 100644
70852--- a/include/linux/sock_diag.h
70853+++ b/include/linux/sock_diag.h
70854@@ -10,7 +10,7 @@ struct sock;
70855 struct sock_diag_handler {
70856 __u8 family;
70857 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
70858-};
70859+} __do_const;
70860
70861 int sock_diag_register(const struct sock_diag_handler *h);
70862 void sock_diag_unregister(const struct sock_diag_handler *h);
70863diff --git a/include/linux/sonet.h b/include/linux/sonet.h
70864index 680f9a3..f13aeb0 100644
70865--- a/include/linux/sonet.h
70866+++ b/include/linux/sonet.h
70867@@ -7,7 +7,7 @@
70868 #include <uapi/linux/sonet.h>
70869
70870 struct k_sonet_stats {
70871-#define __HANDLE_ITEM(i) atomic_t i
70872+#define __HANDLE_ITEM(i) atomic_unchecked_t i
70873 __SONET_ITEMS
70874 #undef __HANDLE_ITEM
70875 };
70876diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
70877index 34206b8..3db7f1c 100644
70878--- a/include/linux/sunrpc/clnt.h
70879+++ b/include/linux/sunrpc/clnt.h
70880@@ -96,7 +96,7 @@ struct rpc_procinfo {
70881 unsigned int p_timer; /* Which RTT timer to use */
70882 u32 p_statidx; /* Which procedure to account */
70883 const char * p_name; /* name of procedure */
70884-};
70885+} __do_const;
70886
70887 #ifdef __KERNEL__
70888
70889@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
70890 {
70891 switch (sap->sa_family) {
70892 case AF_INET:
70893- return ntohs(((struct sockaddr_in *)sap)->sin_port);
70894+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
70895 case AF_INET6:
70896- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
70897+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
70898 }
70899 return 0;
70900 }
70901@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
70902 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
70903 const struct sockaddr *src)
70904 {
70905- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
70906+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
70907 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
70908
70909 dsin->sin_family = ssin->sin_family;
70910@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
70911 if (sa->sa_family != AF_INET6)
70912 return 0;
70913
70914- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
70915+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
70916 }
70917
70918 #endif /* __KERNEL__ */
70919diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
70920index 676ddf5..4c519a1 100644
70921--- a/include/linux/sunrpc/svc.h
70922+++ b/include/linux/sunrpc/svc.h
70923@@ -410,7 +410,7 @@ struct svc_procedure {
70924 unsigned int pc_count; /* call count */
70925 unsigned int pc_cachetype; /* cache info (NFS) */
70926 unsigned int pc_xdrressize; /* maximum size of XDR reply */
70927-};
70928+} __do_const;
70929
70930 /*
70931 * Function prototypes.
70932diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
70933index 0b8e3e6..33e0a01 100644
70934--- a/include/linux/sunrpc/svc_rdma.h
70935+++ b/include/linux/sunrpc/svc_rdma.h
70936@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
70937 extern unsigned int svcrdma_max_requests;
70938 extern unsigned int svcrdma_max_req_size;
70939
70940-extern atomic_t rdma_stat_recv;
70941-extern atomic_t rdma_stat_read;
70942-extern atomic_t rdma_stat_write;
70943-extern atomic_t rdma_stat_sq_starve;
70944-extern atomic_t rdma_stat_rq_starve;
70945-extern atomic_t rdma_stat_rq_poll;
70946-extern atomic_t rdma_stat_rq_prod;
70947-extern atomic_t rdma_stat_sq_poll;
70948-extern atomic_t rdma_stat_sq_prod;
70949+extern atomic_unchecked_t rdma_stat_recv;
70950+extern atomic_unchecked_t rdma_stat_read;
70951+extern atomic_unchecked_t rdma_stat_write;
70952+extern atomic_unchecked_t rdma_stat_sq_starve;
70953+extern atomic_unchecked_t rdma_stat_rq_starve;
70954+extern atomic_unchecked_t rdma_stat_rq_poll;
70955+extern atomic_unchecked_t rdma_stat_rq_prod;
70956+extern atomic_unchecked_t rdma_stat_sq_poll;
70957+extern atomic_unchecked_t rdma_stat_sq_prod;
70958
70959 #define RPCRDMA_VERSION 1
70960
70961diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
70962index dd74084a..7f509d5 100644
70963--- a/include/linux/sunrpc/svcauth.h
70964+++ b/include/linux/sunrpc/svcauth.h
70965@@ -109,7 +109,7 @@ struct auth_ops {
70966 int (*release)(struct svc_rqst *rq);
70967 void (*domain_release)(struct auth_domain *);
70968 int (*set_client)(struct svc_rqst *rq);
70969-};
70970+} __do_const;
70971
70972 #define SVC_GARBAGE 1
70973 #define SVC_SYSERR 2
70974diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
70975index 071d62c..4ccc7ac 100644
70976--- a/include/linux/swiotlb.h
70977+++ b/include/linux/swiotlb.h
70978@@ -59,7 +59,8 @@ extern void
70979
70980 extern void
70981 swiotlb_free_coherent(struct device *hwdev, size_t size,
70982- void *vaddr, dma_addr_t dma_handle);
70983+ void *vaddr, dma_addr_t dma_handle,
70984+ struct dma_attrs *attrs);
70985
70986 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
70987 unsigned long offset, size_t size,
70988diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
70989index 27b3b0b..e093dd9 100644
70990--- a/include/linux/syscore_ops.h
70991+++ b/include/linux/syscore_ops.h
70992@@ -16,7 +16,7 @@ struct syscore_ops {
70993 int (*suspend)(void);
70994 void (*resume)(void);
70995 void (*shutdown)(void);
70996-};
70997+} __do_const;
70998
70999 extern void register_syscore_ops(struct syscore_ops *ops);
71000 extern void unregister_syscore_ops(struct syscore_ops *ops);
71001diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
71002index 14a8ff2..af52bad 100644
71003--- a/include/linux/sysctl.h
71004+++ b/include/linux/sysctl.h
71005@@ -34,13 +34,13 @@ struct ctl_table_root;
71006 struct ctl_table_header;
71007 struct ctl_dir;
71008
71009-typedef struct ctl_table ctl_table;
71010-
71011 typedef int proc_handler (struct ctl_table *ctl, int write,
71012 void __user *buffer, size_t *lenp, loff_t *ppos);
71013
71014 extern int proc_dostring(struct ctl_table *, int,
71015 void __user *, size_t *, loff_t *);
71016+extern int proc_dostring_modpriv(struct ctl_table *, int,
71017+ void __user *, size_t *, loff_t *);
71018 extern int proc_dointvec(struct ctl_table *, int,
71019 void __user *, size_t *, loff_t *);
71020 extern int proc_dointvec_minmax(struct ctl_table *, int,
71021@@ -115,7 +115,9 @@ struct ctl_table
71022 struct ctl_table_poll *poll;
71023 void *extra1;
71024 void *extra2;
71025-};
71026+} __do_const;
71027+typedef struct ctl_table __no_const ctl_table_no_const;
71028+typedef struct ctl_table ctl_table;
71029
71030 struct ctl_node {
71031 struct rb_node node;
71032diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
71033index 381f06d..dc16cc7 100644
71034--- a/include/linux/sysfs.h
71035+++ b/include/linux/sysfs.h
71036@@ -31,7 +31,8 @@ struct attribute {
71037 struct lock_class_key *key;
71038 struct lock_class_key skey;
71039 #endif
71040-};
71041+} __do_const;
71042+typedef struct attribute __no_const attribute_no_const;
71043
71044 /**
71045 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
71046@@ -59,8 +60,8 @@ struct attribute_group {
71047 umode_t (*is_visible)(struct kobject *,
71048 struct attribute *, int);
71049 struct attribute **attrs;
71050-};
71051-
71052+} __do_const;
71053+typedef struct attribute_group __no_const attribute_group_no_const;
71054
71055
71056 /**
71057@@ -107,7 +108,8 @@ struct bin_attribute {
71058 char *, loff_t, size_t);
71059 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
71060 struct vm_area_struct *vma);
71061-};
71062+} __do_const;
71063+typedef struct bin_attribute __no_const bin_attribute_no_const;
71064
71065 /**
71066 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
71067diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
71068index 7faf933..4657127 100644
71069--- a/include/linux/sysrq.h
71070+++ b/include/linux/sysrq.h
71071@@ -15,7 +15,9 @@
71072 #define _LINUX_SYSRQ_H
71073
71074 #include <linux/errno.h>
71075+#include <linux/compiler.h>
71076 #include <linux/types.h>
71077+#include <linux/compiler.h>
71078
71079 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
71080 #define SYSRQ_DEFAULT_ENABLE 1
71081@@ -36,7 +38,7 @@ struct sysrq_key_op {
71082 char *help_msg;
71083 char *action_msg;
71084 int enable_mask;
71085-};
71086+} __do_const;
71087
71088 #ifdef CONFIG_MAGIC_SYSRQ
71089
71090diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
71091index e7e0473..39b7b52 100644
71092--- a/include/linux/thread_info.h
71093+++ b/include/linux/thread_info.h
71094@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
71095 #error "no set_restore_sigmask() provided and default one won't work"
71096 #endif
71097
71098+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
71099+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
71100+{
71101+#ifndef CONFIG_PAX_USERCOPY_DEBUG
71102+ if (!__builtin_constant_p(n))
71103+#endif
71104+ __check_object_size(ptr, n, to);
71105+}
71106+
71107 #endif /* __KERNEL__ */
71108
71109 #endif /* _LINUX_THREAD_INFO_H */
71110diff --git a/include/linux/tty.h b/include/linux/tty.h
71111index 8db1b56..c16a040 100644
71112--- a/include/linux/tty.h
71113+++ b/include/linux/tty.h
71114@@ -194,7 +194,7 @@ struct tty_port {
71115 const struct tty_port_operations *ops; /* Port operations */
71116 spinlock_t lock; /* Lock protecting tty field */
71117 int blocked_open; /* Waiting to open */
71118- int count; /* Usage count */
71119+ atomic_t count; /* Usage count */
71120 wait_queue_head_t open_wait; /* Open waiters */
71121 wait_queue_head_t close_wait; /* Close waiters */
71122 wait_queue_head_t delta_msr_wait; /* Modem status change */
71123@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
71124 struct tty_struct *tty, struct file *filp);
71125 static inline int tty_port_users(struct tty_port *port)
71126 {
71127- return port->count + port->blocked_open;
71128+ return atomic_read(&port->count) + port->blocked_open;
71129 }
71130
71131 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
71132diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
71133index dd976cf..e272742 100644
71134--- a/include/linux/tty_driver.h
71135+++ b/include/linux/tty_driver.h
71136@@ -284,7 +284,7 @@ struct tty_operations {
71137 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
71138 #endif
71139 const struct file_operations *proc_fops;
71140-};
71141+} __do_const;
71142
71143 struct tty_driver {
71144 int magic; /* magic number for this structure */
71145diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
71146index fb79dd8d..07d4773 100644
71147--- a/include/linux/tty_ldisc.h
71148+++ b/include/linux/tty_ldisc.h
71149@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
71150
71151 struct module *owner;
71152
71153- int refcount;
71154+ atomic_t refcount;
71155 };
71156
71157 struct tty_ldisc {
71158diff --git a/include/linux/types.h b/include/linux/types.h
71159index 4d118ba..c3ee9bf 100644
71160--- a/include/linux/types.h
71161+++ b/include/linux/types.h
71162@@ -176,10 +176,26 @@ typedef struct {
71163 int counter;
71164 } atomic_t;
71165
71166+#ifdef CONFIG_PAX_REFCOUNT
71167+typedef struct {
71168+ int counter;
71169+} atomic_unchecked_t;
71170+#else
71171+typedef atomic_t atomic_unchecked_t;
71172+#endif
71173+
71174 #ifdef CONFIG_64BIT
71175 typedef struct {
71176 long counter;
71177 } atomic64_t;
71178+
71179+#ifdef CONFIG_PAX_REFCOUNT
71180+typedef struct {
71181+ long counter;
71182+} atomic64_unchecked_t;
71183+#else
71184+typedef atomic64_t atomic64_unchecked_t;
71185+#endif
71186 #endif
71187
71188 struct list_head {
71189diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
71190index 5ca0951..ab496a5 100644
71191--- a/include/linux/uaccess.h
71192+++ b/include/linux/uaccess.h
71193@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
71194 long ret; \
71195 mm_segment_t old_fs = get_fs(); \
71196 \
71197- set_fs(KERNEL_DS); \
71198 pagefault_disable(); \
71199- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
71200- pagefault_enable(); \
71201+ set_fs(KERNEL_DS); \
71202+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
71203 set_fs(old_fs); \
71204+ pagefault_enable(); \
71205 ret; \
71206 })
71207
71208diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
71209index 8e522cbc..aa8572d 100644
71210--- a/include/linux/uidgid.h
71211+++ b/include/linux/uidgid.h
71212@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
71213
71214 #endif /* CONFIG_USER_NS */
71215
71216+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
71217+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
71218+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
71219+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
71220+
71221 #endif /* _LINUX_UIDGID_H */
71222diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
71223index 99c1b4d..562e6f3 100644
71224--- a/include/linux/unaligned/access_ok.h
71225+++ b/include/linux/unaligned/access_ok.h
71226@@ -4,34 +4,34 @@
71227 #include <linux/kernel.h>
71228 #include <asm/byteorder.h>
71229
71230-static inline u16 get_unaligned_le16(const void *p)
71231+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
71232 {
71233- return le16_to_cpup((__le16 *)p);
71234+ return le16_to_cpup((const __le16 *)p);
71235 }
71236
71237-static inline u32 get_unaligned_le32(const void *p)
71238+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
71239 {
71240- return le32_to_cpup((__le32 *)p);
71241+ return le32_to_cpup((const __le32 *)p);
71242 }
71243
71244-static inline u64 get_unaligned_le64(const void *p)
71245+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
71246 {
71247- return le64_to_cpup((__le64 *)p);
71248+ return le64_to_cpup((const __le64 *)p);
71249 }
71250
71251-static inline u16 get_unaligned_be16(const void *p)
71252+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
71253 {
71254- return be16_to_cpup((__be16 *)p);
71255+ return be16_to_cpup((const __be16 *)p);
71256 }
71257
71258-static inline u32 get_unaligned_be32(const void *p)
71259+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
71260 {
71261- return be32_to_cpup((__be32 *)p);
71262+ return be32_to_cpup((const __be32 *)p);
71263 }
71264
71265-static inline u64 get_unaligned_be64(const void *p)
71266+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
71267 {
71268- return be64_to_cpup((__be64 *)p);
71269+ return be64_to_cpup((const __be64 *)p);
71270 }
71271
71272 static inline void put_unaligned_le16(u16 val, void *p)
71273diff --git a/include/linux/usb.h b/include/linux/usb.h
71274index 4d22d0f..8d0e8f8 100644
71275--- a/include/linux/usb.h
71276+++ b/include/linux/usb.h
71277@@ -554,7 +554,7 @@ struct usb_device {
71278 int maxchild;
71279
71280 u32 quirks;
71281- atomic_t urbnum;
71282+ atomic_unchecked_t urbnum;
71283
71284 unsigned long active_duration;
71285
71286@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
71287
71288 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
71289 __u8 request, __u8 requesttype, __u16 value, __u16 index,
71290- void *data, __u16 size, int timeout);
71291+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
71292 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
71293 void *data, int len, int *actual_length, int timeout);
71294 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
71295diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
71296index c5d36c6..108f4f9 100644
71297--- a/include/linux/usb/renesas_usbhs.h
71298+++ b/include/linux/usb/renesas_usbhs.h
71299@@ -39,7 +39,7 @@ enum {
71300 */
71301 struct renesas_usbhs_driver_callback {
71302 int (*notify_hotplug)(struct platform_device *pdev);
71303-};
71304+} __no_const;
71305
71306 /*
71307 * callback functions for platform
71308diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
71309index b9bd2e6..4ce0093 100644
71310--- a/include/linux/user_namespace.h
71311+++ b/include/linux/user_namespace.h
71312@@ -21,7 +21,7 @@ struct user_namespace {
71313 struct uid_gid_map uid_map;
71314 struct uid_gid_map gid_map;
71315 struct uid_gid_map projid_map;
71316- struct kref kref;
71317+ atomic_t count;
71318 struct user_namespace *parent;
71319 kuid_t owner;
71320 kgid_t group;
71321@@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
71322 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
71323 {
71324 if (ns)
71325- kref_get(&ns->kref);
71326+ atomic_inc(&ns->count);
71327 return ns;
71328 }
71329
71330 extern int create_user_ns(struct cred *new);
71331 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
71332-extern void free_user_ns(struct kref *kref);
71333+extern void free_user_ns(struct user_namespace *ns);
71334
71335 static inline void put_user_ns(struct user_namespace *ns)
71336 {
71337- if (ns)
71338- kref_put(&ns->kref, free_user_ns);
71339+ if (ns && atomic_dec_and_test(&ns->count))
71340+ free_user_ns(ns);
71341 }
71342
71343 struct seq_operations;
71344diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
71345index 6f8fbcf..8259001 100644
71346--- a/include/linux/vermagic.h
71347+++ b/include/linux/vermagic.h
71348@@ -25,9 +25,35 @@
71349 #define MODULE_ARCH_VERMAGIC ""
71350 #endif
71351
71352+#ifdef CONFIG_PAX_REFCOUNT
71353+#define MODULE_PAX_REFCOUNT "REFCOUNT "
71354+#else
71355+#define MODULE_PAX_REFCOUNT ""
71356+#endif
71357+
71358+#ifdef CONSTIFY_PLUGIN
71359+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
71360+#else
71361+#define MODULE_CONSTIFY_PLUGIN ""
71362+#endif
71363+
71364+#ifdef STACKLEAK_PLUGIN
71365+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
71366+#else
71367+#define MODULE_STACKLEAK_PLUGIN ""
71368+#endif
71369+
71370+#ifdef CONFIG_GRKERNSEC
71371+#define MODULE_GRSEC "GRSEC "
71372+#else
71373+#define MODULE_GRSEC ""
71374+#endif
71375+
71376 #define VERMAGIC_STRING \
71377 UTS_RELEASE " " \
71378 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
71379 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
71380- MODULE_ARCH_VERMAGIC
71381+ MODULE_ARCH_VERMAGIC \
71382+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
71383+ MODULE_GRSEC
71384
71385diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
71386index 6071e91..ca6a489 100644
71387--- a/include/linux/vmalloc.h
71388+++ b/include/linux/vmalloc.h
71389@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
71390 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
71391 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
71392 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
71393+
71394+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71395+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
71396+#endif
71397+
71398 /* bits [20..32] reserved for arch specific ioremap internals */
71399
71400 /*
71401@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
71402 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
71403 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
71404 unsigned long start, unsigned long end, gfp_t gfp_mask,
71405- pgprot_t prot, int node, const void *caller);
71406+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
71407 extern void vfree(const void *addr);
71408
71409 extern void *vmap(struct page **pages, unsigned int count,
71410@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
71411 extern void free_vm_area(struct vm_struct *area);
71412
71413 /* for /dev/kmem */
71414-extern long vread(char *buf, char *addr, unsigned long count);
71415-extern long vwrite(char *buf, char *addr, unsigned long count);
71416+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
71417+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
71418
71419 /*
71420 * Internals. Dont't use..
71421diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
71422index a13291f..af51fa3 100644
71423--- a/include/linux/vmstat.h
71424+++ b/include/linux/vmstat.h
71425@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
71426 /*
71427 * Zone based page accounting with per cpu differentials.
71428 */
71429-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71430+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71431
71432 static inline void zone_page_state_add(long x, struct zone *zone,
71433 enum zone_stat_item item)
71434 {
71435- atomic_long_add(x, &zone->vm_stat[item]);
71436- atomic_long_add(x, &vm_stat[item]);
71437+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
71438+ atomic_long_add_unchecked(x, &vm_stat[item]);
71439 }
71440
71441 static inline unsigned long global_page_state(enum zone_stat_item item)
71442 {
71443- long x = atomic_long_read(&vm_stat[item]);
71444+ long x = atomic_long_read_unchecked(&vm_stat[item]);
71445 #ifdef CONFIG_SMP
71446 if (x < 0)
71447 x = 0;
71448@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
71449 static inline unsigned long zone_page_state(struct zone *zone,
71450 enum zone_stat_item item)
71451 {
71452- long x = atomic_long_read(&zone->vm_stat[item]);
71453+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
71454 #ifdef CONFIG_SMP
71455 if (x < 0)
71456 x = 0;
71457@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
71458 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
71459 enum zone_stat_item item)
71460 {
71461- long x = atomic_long_read(&zone->vm_stat[item]);
71462+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
71463
71464 #ifdef CONFIG_SMP
71465 int cpu;
71466@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
71467
71468 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
71469 {
71470- atomic_long_inc(&zone->vm_stat[item]);
71471- atomic_long_inc(&vm_stat[item]);
71472+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
71473+ atomic_long_inc_unchecked(&vm_stat[item]);
71474 }
71475
71476 static inline void __inc_zone_page_state(struct page *page,
71477@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
71478
71479 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
71480 {
71481- atomic_long_dec(&zone->vm_stat[item]);
71482- atomic_long_dec(&vm_stat[item]);
71483+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
71484+ atomic_long_dec_unchecked(&vm_stat[item]);
71485 }
71486
71487 static inline void __dec_zone_page_state(struct page *page,
71488diff --git a/include/linux/xattr.h b/include/linux/xattr.h
71489index fdbafc6..b7ffd47 100644
71490--- a/include/linux/xattr.h
71491+++ b/include/linux/xattr.h
71492@@ -28,7 +28,7 @@ struct xattr_handler {
71493 size_t size, int handler_flags);
71494 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
71495 size_t size, int flags, int handler_flags);
71496-};
71497+} __do_const;
71498
71499 struct xattr {
71500 char *name;
71501diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
71502index 95d1c91..6798cca 100644
71503--- a/include/media/v4l2-dev.h
71504+++ b/include/media/v4l2-dev.h
71505@@ -76,7 +76,7 @@ struct v4l2_file_operations {
71506 int (*mmap) (struct file *, struct vm_area_struct *);
71507 int (*open) (struct file *);
71508 int (*release) (struct file *);
71509-};
71510+} __do_const;
71511
71512 /*
71513 * Newer version of video_device, handled by videodev2.c
71514diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
71515index 4118ad1..cb7e25f 100644
71516--- a/include/media/v4l2-ioctl.h
71517+++ b/include/media/v4l2-ioctl.h
71518@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
71519 bool valid_prio, int cmd, void *arg);
71520 };
71521
71522-
71523 /* v4l debugging and diagnostics */
71524
71525 /* Debug bitmask flags to be used on V4L2 */
71526diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
71527index adcbb20..62c2559 100644
71528--- a/include/net/9p/transport.h
71529+++ b/include/net/9p/transport.h
71530@@ -57,7 +57,7 @@ struct p9_trans_module {
71531 int (*cancel) (struct p9_client *, struct p9_req_t *req);
71532 int (*zc_request)(struct p9_client *, struct p9_req_t *,
71533 char *, char *, int , int, int, int);
71534-};
71535+} __do_const;
71536
71537 void v9fs_register_trans(struct p9_trans_module *m);
71538 void v9fs_unregister_trans(struct p9_trans_module *m);
71539diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
71540index 7588ef4..e62d35f 100644
71541--- a/include/net/bluetooth/l2cap.h
71542+++ b/include/net/bluetooth/l2cap.h
71543@@ -552,7 +552,7 @@ struct l2cap_ops {
71544 void (*defer) (struct l2cap_chan *chan);
71545 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
71546 unsigned long len, int nb);
71547-};
71548+} __do_const;
71549
71550 struct l2cap_conn {
71551 struct hci_conn *hcon;
71552diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
71553index 9e5425b..8136ffc 100644
71554--- a/include/net/caif/cfctrl.h
71555+++ b/include/net/caif/cfctrl.h
71556@@ -52,7 +52,7 @@ struct cfctrl_rsp {
71557 void (*radioset_rsp)(void);
71558 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
71559 struct cflayer *client_layer);
71560-};
71561+} __no_const;
71562
71563 /* Link Setup Parameters for CAIF-Links. */
71564 struct cfctrl_link_param {
71565@@ -101,8 +101,8 @@ struct cfctrl_request_info {
71566 struct cfctrl {
71567 struct cfsrvl serv;
71568 struct cfctrl_rsp res;
71569- atomic_t req_seq_no;
71570- atomic_t rsp_seq_no;
71571+ atomic_unchecked_t req_seq_no;
71572+ atomic_unchecked_t rsp_seq_no;
71573 struct list_head list;
71574 /* Protects from simultaneous access to first_req list */
71575 spinlock_t info_list_lock;
71576diff --git a/include/net/flow.h b/include/net/flow.h
71577index 628e11b..4c475df 100644
71578--- a/include/net/flow.h
71579+++ b/include/net/flow.h
71580@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
71581
71582 extern void flow_cache_flush(void);
71583 extern void flow_cache_flush_deferred(void);
71584-extern atomic_t flow_cache_genid;
71585+extern atomic_unchecked_t flow_cache_genid;
71586
71587 #endif
71588diff --git a/include/net/genetlink.h b/include/net/genetlink.h
71589index bdfbe68..4402ebe 100644
71590--- a/include/net/genetlink.h
71591+++ b/include/net/genetlink.h
71592@@ -118,7 +118,7 @@ struct genl_ops {
71593 struct netlink_callback *cb);
71594 int (*done)(struct netlink_callback *cb);
71595 struct list_head ops_list;
71596-};
71597+} __do_const;
71598
71599 extern int genl_register_family(struct genl_family *family);
71600 extern int genl_register_family_with_ops(struct genl_family *family,
71601diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
71602index e5062c9..48a9a4b 100644
71603--- a/include/net/gro_cells.h
71604+++ b/include/net/gro_cells.h
71605@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
71606 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
71607
71608 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
71609- atomic_long_inc(&dev->rx_dropped);
71610+ atomic_long_inc_unchecked(&dev->rx_dropped);
71611 kfree_skb(skb);
71612 return;
71613 }
71614@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
71615 int i;
71616
71617 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
71618- gcells->cells = kcalloc(sizeof(struct gro_cell),
71619- gcells->gro_cells_mask + 1,
71620+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
71621+ sizeof(struct gro_cell),
71622 GFP_KERNEL);
71623 if (!gcells->cells)
71624 return -ENOMEM;
71625diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
71626index 1832927..ce39aea 100644
71627--- a/include/net/inet_connection_sock.h
71628+++ b/include/net/inet_connection_sock.h
71629@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
71630 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
71631 int (*bind_conflict)(const struct sock *sk,
71632 const struct inet_bind_bucket *tb, bool relax);
71633-};
71634+} __do_const;
71635
71636 /** inet_connection_sock - INET connection oriented sock
71637 *
71638diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
71639index 53f464d..ba76aaa 100644
71640--- a/include/net/inetpeer.h
71641+++ b/include/net/inetpeer.h
71642@@ -47,8 +47,8 @@ struct inet_peer {
71643 */
71644 union {
71645 struct {
71646- atomic_t rid; /* Frag reception counter */
71647- atomic_t ip_id_count; /* IP ID for the next packet */
71648+ atomic_unchecked_t rid; /* Frag reception counter */
71649+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
71650 };
71651 struct rcu_head rcu;
71652 struct inet_peer *gc_next;
71653@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
71654 more++;
71655 inet_peer_refcheck(p);
71656 do {
71657- old = atomic_read(&p->ip_id_count);
71658+ old = atomic_read_unchecked(&p->ip_id_count);
71659 new = old + more;
71660 if (!new)
71661 new = 1;
71662- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
71663+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
71664 return new;
71665 }
71666
71667diff --git a/include/net/ip.h b/include/net/ip.h
71668index a68f838..74518ab 100644
71669--- a/include/net/ip.h
71670+++ b/include/net/ip.h
71671@@ -202,7 +202,7 @@ extern struct local_ports {
71672 } sysctl_local_ports;
71673 extern void inet_get_local_port_range(int *low, int *high);
71674
71675-extern unsigned long *sysctl_local_reserved_ports;
71676+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
71677 static inline int inet_is_reserved_local_port(int port)
71678 {
71679 return test_bit(port, sysctl_local_reserved_ports);
71680diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
71681index 9497be1..5a4fafe 100644
71682--- a/include/net/ip_fib.h
71683+++ b/include/net/ip_fib.h
71684@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
71685
71686 #define FIB_RES_SADDR(net, res) \
71687 ((FIB_RES_NH(res).nh_saddr_genid == \
71688- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
71689+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
71690 FIB_RES_NH(res).nh_saddr : \
71691 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
71692 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
71693diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
71694index 68c69d5..bdab192 100644
71695--- a/include/net/ip_vs.h
71696+++ b/include/net/ip_vs.h
71697@@ -599,7 +599,7 @@ struct ip_vs_conn {
71698 struct ip_vs_conn *control; /* Master control connection */
71699 atomic_t n_control; /* Number of controlled ones */
71700 struct ip_vs_dest *dest; /* real server */
71701- atomic_t in_pkts; /* incoming packet counter */
71702+ atomic_unchecked_t in_pkts; /* incoming packet counter */
71703
71704 /* packet transmitter for different forwarding methods. If it
71705 mangles the packet, it must return NF_DROP or better NF_STOLEN,
71706@@ -737,7 +737,7 @@ struct ip_vs_dest {
71707 __be16 port; /* port number of the server */
71708 union nf_inet_addr addr; /* IP address of the server */
71709 volatile unsigned int flags; /* dest status flags */
71710- atomic_t conn_flags; /* flags to copy to conn */
71711+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
71712 atomic_t weight; /* server weight */
71713
71714 atomic_t refcnt; /* reference counter */
71715@@ -980,11 +980,11 @@ struct netns_ipvs {
71716 /* ip_vs_lblc */
71717 int sysctl_lblc_expiration;
71718 struct ctl_table_header *lblc_ctl_header;
71719- struct ctl_table *lblc_ctl_table;
71720+ ctl_table_no_const *lblc_ctl_table;
71721 /* ip_vs_lblcr */
71722 int sysctl_lblcr_expiration;
71723 struct ctl_table_header *lblcr_ctl_header;
71724- struct ctl_table *lblcr_ctl_table;
71725+ ctl_table_no_const *lblcr_ctl_table;
71726 /* ip_vs_est */
71727 struct list_head est_list; /* estimator list */
71728 spinlock_t est_lock;
71729diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
71730index 80ffde3..968b0f4 100644
71731--- a/include/net/irda/ircomm_tty.h
71732+++ b/include/net/irda/ircomm_tty.h
71733@@ -35,6 +35,7 @@
71734 #include <linux/termios.h>
71735 #include <linux/timer.h>
71736 #include <linux/tty.h> /* struct tty_struct */
71737+#include <asm/local.h>
71738
71739 #include <net/irda/irias_object.h>
71740 #include <net/irda/ircomm_core.h>
71741diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
71742index cc7c197..9f2da2a 100644
71743--- a/include/net/iucv/af_iucv.h
71744+++ b/include/net/iucv/af_iucv.h
71745@@ -141,7 +141,7 @@ struct iucv_sock {
71746 struct iucv_sock_list {
71747 struct hlist_head head;
71748 rwlock_t lock;
71749- atomic_t autobind_name;
71750+ atomic_unchecked_t autobind_name;
71751 };
71752
71753 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
71754diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
71755index df83f69..9b640b8 100644
71756--- a/include/net/llc_c_ac.h
71757+++ b/include/net/llc_c_ac.h
71758@@ -87,7 +87,7 @@
71759 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
71760 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
71761
71762-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71763+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71764
71765 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
71766 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
71767diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
71768index 6ca3113..f8026dd 100644
71769--- a/include/net/llc_c_ev.h
71770+++ b/include/net/llc_c_ev.h
71771@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
71772 return (struct llc_conn_state_ev *)skb->cb;
71773 }
71774
71775-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71776-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71777+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71778+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71779
71780 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
71781 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
71782diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
71783index 0e79cfb..f46db31 100644
71784--- a/include/net/llc_c_st.h
71785+++ b/include/net/llc_c_st.h
71786@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
71787 u8 next_state;
71788 llc_conn_ev_qfyr_t *ev_qualifiers;
71789 llc_conn_action_t *ev_actions;
71790-};
71791+} __do_const;
71792
71793 struct llc_conn_state {
71794 u8 current_state;
71795diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
71796index 37a3bbd..55a4241 100644
71797--- a/include/net/llc_s_ac.h
71798+++ b/include/net/llc_s_ac.h
71799@@ -23,7 +23,7 @@
71800 #define SAP_ACT_TEST_IND 9
71801
71802 /* All action functions must look like this */
71803-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71804+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71805
71806 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
71807 struct sk_buff *skb);
71808diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
71809index 567c681..cd73ac0 100644
71810--- a/include/net/llc_s_st.h
71811+++ b/include/net/llc_s_st.h
71812@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
71813 llc_sap_ev_t ev;
71814 u8 next_state;
71815 llc_sap_action_t *ev_actions;
71816-};
71817+} __do_const;
71818
71819 struct llc_sap_state {
71820 u8 curr_state;
71821diff --git a/include/net/mac80211.h b/include/net/mac80211.h
71822index ee50c5e..1bc3b1a 100644
71823--- a/include/net/mac80211.h
71824+++ b/include/net/mac80211.h
71825@@ -3996,7 +3996,7 @@ struct rate_control_ops {
71826 void (*add_sta_debugfs)(void *priv, void *priv_sta,
71827 struct dentry *dir);
71828 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
71829-};
71830+} __do_const;
71831
71832 static inline int rate_supported(struct ieee80211_sta *sta,
71833 enum ieee80211_band band,
71834diff --git a/include/net/neighbour.h b/include/net/neighbour.h
71835index 0dab173..1b76af0 100644
71836--- a/include/net/neighbour.h
71837+++ b/include/net/neighbour.h
71838@@ -123,7 +123,7 @@ struct neigh_ops {
71839 void (*error_report)(struct neighbour *, struct sk_buff *);
71840 int (*output)(struct neighbour *, struct sk_buff *);
71841 int (*connected_output)(struct neighbour *, struct sk_buff *);
71842-};
71843+} __do_const;
71844
71845 struct pneigh_entry {
71846 struct pneigh_entry *next;
71847diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
71848index de644bc..351fd4e 100644
71849--- a/include/net/net_namespace.h
71850+++ b/include/net/net_namespace.h
71851@@ -115,7 +115,7 @@ struct net {
71852 #endif
71853 struct netns_ipvs *ipvs;
71854 struct sock *diag_nlsk;
71855- atomic_t rt_genid;
71856+ atomic_unchecked_t rt_genid;
71857 };
71858
71859 /*
71860@@ -282,7 +282,7 @@ struct pernet_operations {
71861 void (*exit_batch)(struct list_head *net_exit_list);
71862 int *id;
71863 size_t size;
71864-};
71865+} __do_const;
71866
71867 /*
71868 * Use these carefully. If you implement a network device and it
71869@@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
71870
71871 static inline int rt_genid(struct net *net)
71872 {
71873- return atomic_read(&net->rt_genid);
71874+ return atomic_read_unchecked(&net->rt_genid);
71875 }
71876
71877 static inline void rt_genid_bump(struct net *net)
71878 {
71879- atomic_inc(&net->rt_genid);
71880+ atomic_inc_unchecked(&net->rt_genid);
71881 }
71882
71883 #endif /* __NET_NET_NAMESPACE_H */
71884diff --git a/include/net/netdma.h b/include/net/netdma.h
71885index 8ba8ce2..99b7fff 100644
71886--- a/include/net/netdma.h
71887+++ b/include/net/netdma.h
71888@@ -24,7 +24,7 @@
71889 #include <linux/dmaengine.h>
71890 #include <linux/skbuff.h>
71891
71892-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71893+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71894 struct sk_buff *skb, int offset, struct iovec *to,
71895 size_t len, struct dma_pinned_list *pinned_list);
71896
71897diff --git a/include/net/netlink.h b/include/net/netlink.h
71898index 9690b0f..87aded7 100644
71899--- a/include/net/netlink.h
71900+++ b/include/net/netlink.h
71901@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
71902 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
71903 {
71904 if (mark)
71905- skb_trim(skb, (unsigned char *) mark - skb->data);
71906+ skb_trim(skb, (const unsigned char *) mark - skb->data);
71907 }
71908
71909 /**
71910diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
71911index 923cb20..deae816 100644
71912--- a/include/net/netns/conntrack.h
71913+++ b/include/net/netns/conntrack.h
71914@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
71915 struct nf_proto_net {
71916 #ifdef CONFIG_SYSCTL
71917 struct ctl_table_header *ctl_table_header;
71918- struct ctl_table *ctl_table;
71919+ ctl_table_no_const *ctl_table;
71920 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
71921 struct ctl_table_header *ctl_compat_header;
71922- struct ctl_table *ctl_compat_table;
71923+ ctl_table_no_const *ctl_compat_table;
71924 #endif
71925 #endif
71926 unsigned int users;
71927@@ -58,7 +58,7 @@ struct nf_ip_net {
71928 struct nf_icmp_net icmpv6;
71929 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
71930 struct ctl_table_header *ctl_table_header;
71931- struct ctl_table *ctl_table;
71932+ ctl_table_no_const *ctl_table;
71933 #endif
71934 };
71935
71936diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
71937index 2ae2b83..dbdc85e 100644
71938--- a/include/net/netns/ipv4.h
71939+++ b/include/net/netns/ipv4.h
71940@@ -64,7 +64,7 @@ struct netns_ipv4 {
71941 kgid_t sysctl_ping_group_range[2];
71942 long sysctl_tcp_mem[3];
71943
71944- atomic_t dev_addr_genid;
71945+ atomic_unchecked_t dev_addr_genid;
71946
71947 #ifdef CONFIG_IP_MROUTE
71948 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
71949diff --git a/include/net/protocol.h b/include/net/protocol.h
71950index 047c047..b9dad15 100644
71951--- a/include/net/protocol.h
71952+++ b/include/net/protocol.h
71953@@ -44,7 +44,7 @@ struct net_protocol {
71954 void (*err_handler)(struct sk_buff *skb, u32 info);
71955 unsigned int no_policy:1,
71956 netns_ok:1;
71957-};
71958+} __do_const;
71959
71960 #if IS_ENABLED(CONFIG_IPV6)
71961 struct inet6_protocol {
71962@@ -57,7 +57,7 @@ struct inet6_protocol {
71963 u8 type, u8 code, int offset,
71964 __be32 info);
71965 unsigned int flags; /* INET6_PROTO_xxx */
71966-};
71967+} __do_const;
71968
71969 #define INET6_PROTO_NOPOLICY 0x1
71970 #define INET6_PROTO_FINAL 0x2
71971diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
71972index 5a15fab..d799ea7 100644
71973--- a/include/net/rtnetlink.h
71974+++ b/include/net/rtnetlink.h
71975@@ -81,7 +81,7 @@ struct rtnl_link_ops {
71976 const struct net_device *dev);
71977 unsigned int (*get_num_tx_queues)(void);
71978 unsigned int (*get_num_rx_queues)(void);
71979-};
71980+} __do_const;
71981
71982 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
71983 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
71984diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
71985index 7fdf298..197e9f7 100644
71986--- a/include/net/sctp/sctp.h
71987+++ b/include/net/sctp/sctp.h
71988@@ -330,9 +330,9 @@ do { \
71989
71990 #else /* SCTP_DEBUG */
71991
71992-#define SCTP_DEBUG_PRINTK(whatever...)
71993-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
71994-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
71995+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
71996+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
71997+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
71998 #define SCTP_ENABLE_DEBUG
71999 #define SCTP_DISABLE_DEBUG
72000 #define SCTP_ASSERT(expr, str, func)
72001diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
72002index 2a82d13..62a31c2 100644
72003--- a/include/net/sctp/sm.h
72004+++ b/include/net/sctp/sm.h
72005@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
72006 typedef struct {
72007 sctp_state_fn_t *fn;
72008 const char *name;
72009-} sctp_sm_table_entry_t;
72010+} __do_const sctp_sm_table_entry_t;
72011
72012 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
72013 * currently in use.
72014@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
72015 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
72016
72017 /* Extern declarations for major data structures. */
72018-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72019+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72020
72021
72022 /* Get the size of a DATA chunk payload. */
72023diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
72024index fdeb85a..1329d95 100644
72025--- a/include/net/sctp/structs.h
72026+++ b/include/net/sctp/structs.h
72027@@ -517,7 +517,7 @@ struct sctp_pf {
72028 struct sctp_association *asoc);
72029 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
72030 struct sctp_af *af;
72031-};
72032+} __do_const;
72033
72034
72035 /* Structure to track chunk fragments that have been acked, but peer
72036diff --git a/include/net/sock.h b/include/net/sock.h
72037index 25afaa0..8bb0070 100644
72038--- a/include/net/sock.h
72039+++ b/include/net/sock.h
72040@@ -322,7 +322,7 @@ struct sock {
72041 #ifdef CONFIG_RPS
72042 __u32 sk_rxhash;
72043 #endif
72044- atomic_t sk_drops;
72045+ atomic_unchecked_t sk_drops;
72046 int sk_rcvbuf;
72047
72048 struct sk_filter __rcu *sk_filter;
72049@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
72050 }
72051
72052 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
72053- char __user *from, char *to,
72054+ char __user *from, unsigned char *to,
72055 int copy, int offset)
72056 {
72057 if (skb->ip_summed == CHECKSUM_NONE) {
72058@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
72059 }
72060 }
72061
72062-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72063+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72064
72065 /**
72066 * sk_page_frag - return an appropriate page_frag
72067diff --git a/include/net/tcp.h b/include/net/tcp.h
72068index aed42c7..43890c6 100644
72069--- a/include/net/tcp.h
72070+++ b/include/net/tcp.h
72071@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
72072 extern void tcp_xmit_retransmit_queue(struct sock *);
72073 extern void tcp_simple_retransmit(struct sock *);
72074 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
72075-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72076+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72077
72078 extern void tcp_send_probe0(struct sock *);
72079 extern void tcp_send_partial(struct sock *);
72080@@ -701,8 +701,8 @@ struct tcp_skb_cb {
72081 struct inet6_skb_parm h6;
72082 #endif
72083 } header; /* For incoming frames */
72084- __u32 seq; /* Starting sequence number */
72085- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
72086+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
72087+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
72088 __u32 when; /* used to compute rtt's */
72089 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
72090
72091@@ -716,7 +716,7 @@ struct tcp_skb_cb {
72092
72093 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
72094 /* 1 byte hole */
72095- __u32 ack_seq; /* Sequence number ACK'd */
72096+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
72097 };
72098
72099 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
72100diff --git a/include/net/xfrm.h b/include/net/xfrm.h
72101index 63445ed..d6fc34f 100644
72102--- a/include/net/xfrm.h
72103+++ b/include/net/xfrm.h
72104@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
72105 struct net_device *dev,
72106 const struct flowi *fl);
72107 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
72108-};
72109+} __do_const;
72110
72111 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
72112 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
72113@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
72114 struct sk_buff *skb);
72115 int (*transport_finish)(struct sk_buff *skb,
72116 int async);
72117-};
72118+} __do_const;
72119
72120 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
72121 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
72122@@ -423,7 +423,7 @@ struct xfrm_mode {
72123 struct module *owner;
72124 unsigned int encap;
72125 int flags;
72126-};
72127+} __do_const;
72128
72129 /* Flags for xfrm_mode. */
72130 enum {
72131@@ -514,7 +514,7 @@ struct xfrm_policy {
72132 struct timer_list timer;
72133
72134 struct flow_cache_object flo;
72135- atomic_t genid;
72136+ atomic_unchecked_t genid;
72137 u32 priority;
72138 u32 index;
72139 struct xfrm_mark mark;
72140diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
72141index 1a046b1..ee0bef0 100644
72142--- a/include/rdma/iw_cm.h
72143+++ b/include/rdma/iw_cm.h
72144@@ -122,7 +122,7 @@ struct iw_cm_verbs {
72145 int backlog);
72146
72147 int (*destroy_listen)(struct iw_cm_id *cm_id);
72148-};
72149+} __no_const;
72150
72151 /**
72152 * iw_create_cm_id - Create an IW CM identifier.
72153diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
72154index 399162b..b337f1a 100644
72155--- a/include/scsi/libfc.h
72156+++ b/include/scsi/libfc.h
72157@@ -762,6 +762,7 @@ struct libfc_function_template {
72158 */
72159 void (*disc_stop_final) (struct fc_lport *);
72160 };
72161+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
72162
72163 /**
72164 * struct fc_disc - Discovery context
72165@@ -866,7 +867,7 @@ struct fc_lport {
72166 struct fc_vport *vport;
72167
72168 /* Operational Information */
72169- struct libfc_function_template tt;
72170+ libfc_function_template_no_const tt;
72171 u8 link_up;
72172 u8 qfull;
72173 enum fc_lport_state state;
72174diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
72175index e65c62e..aa2e5a2 100644
72176--- a/include/scsi/scsi_device.h
72177+++ b/include/scsi/scsi_device.h
72178@@ -170,9 +170,9 @@ struct scsi_device {
72179 unsigned int max_device_blocked; /* what device_blocked counts down from */
72180 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
72181
72182- atomic_t iorequest_cnt;
72183- atomic_t iodone_cnt;
72184- atomic_t ioerr_cnt;
72185+ atomic_unchecked_t iorequest_cnt;
72186+ atomic_unchecked_t iodone_cnt;
72187+ atomic_unchecked_t ioerr_cnt;
72188
72189 struct device sdev_gendev,
72190 sdev_dev;
72191diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
72192index b797e8f..8e2c3aa 100644
72193--- a/include/scsi/scsi_transport_fc.h
72194+++ b/include/scsi/scsi_transport_fc.h
72195@@ -751,7 +751,8 @@ struct fc_function_template {
72196 unsigned long show_host_system_hostname:1;
72197
72198 unsigned long disable_target_scan:1;
72199-};
72200+} __do_const;
72201+typedef struct fc_function_template __no_const fc_function_template_no_const;
72202
72203
72204 /**
72205diff --git a/include/sound/soc.h b/include/sound/soc.h
72206index bc56738..a4be132 100644
72207--- a/include/sound/soc.h
72208+++ b/include/sound/soc.h
72209@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
72210 /* probe ordering - for components with runtime dependencies */
72211 int probe_order;
72212 int remove_order;
72213-};
72214+} __do_const;
72215
72216 /* SoC platform interface */
72217 struct snd_soc_platform_driver {
72218@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
72219 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
72220 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
72221 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
72222-};
72223+} __do_const;
72224
72225 struct snd_soc_platform {
72226 const char *name;
72227diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
72228index 663e34a..91b306a 100644
72229--- a/include/target/target_core_base.h
72230+++ b/include/target/target_core_base.h
72231@@ -654,7 +654,7 @@ struct se_device {
72232 spinlock_t stats_lock;
72233 /* Active commands on this virtual SE device */
72234 atomic_t simple_cmds;
72235- atomic_t dev_ordered_id;
72236+ atomic_unchecked_t dev_ordered_id;
72237 atomic_t dev_ordered_sync;
72238 atomic_t dev_qf_count;
72239 int export_count;
72240diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
72241new file mode 100644
72242index 0000000..fb634b7
72243--- /dev/null
72244+++ b/include/trace/events/fs.h
72245@@ -0,0 +1,53 @@
72246+#undef TRACE_SYSTEM
72247+#define TRACE_SYSTEM fs
72248+
72249+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
72250+#define _TRACE_FS_H
72251+
72252+#include <linux/fs.h>
72253+#include <linux/tracepoint.h>
72254+
72255+TRACE_EVENT(do_sys_open,
72256+
72257+ TP_PROTO(const char *filename, int flags, int mode),
72258+
72259+ TP_ARGS(filename, flags, mode),
72260+
72261+ TP_STRUCT__entry(
72262+ __string( filename, filename )
72263+ __field( int, flags )
72264+ __field( int, mode )
72265+ ),
72266+
72267+ TP_fast_assign(
72268+ __assign_str(filename, filename);
72269+ __entry->flags = flags;
72270+ __entry->mode = mode;
72271+ ),
72272+
72273+ TP_printk("\"%s\" %x %o",
72274+ __get_str(filename), __entry->flags, __entry->mode)
72275+);
72276+
72277+TRACE_EVENT(open_exec,
72278+
72279+ TP_PROTO(const char *filename),
72280+
72281+ TP_ARGS(filename),
72282+
72283+ TP_STRUCT__entry(
72284+ __string( filename, filename )
72285+ ),
72286+
72287+ TP_fast_assign(
72288+ __assign_str(filename, filename);
72289+ ),
72290+
72291+ TP_printk("\"%s\"",
72292+ __get_str(filename))
72293+);
72294+
72295+#endif /* _TRACE_FS_H */
72296+
72297+/* This part must be outside protection */
72298+#include <trace/define_trace.h>
72299diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
72300index 1c09820..7f5ec79 100644
72301--- a/include/trace/events/irq.h
72302+++ b/include/trace/events/irq.h
72303@@ -36,7 +36,7 @@ struct softirq_action;
72304 */
72305 TRACE_EVENT(irq_handler_entry,
72306
72307- TP_PROTO(int irq, struct irqaction *action),
72308+ TP_PROTO(int irq, const struct irqaction *action),
72309
72310 TP_ARGS(irq, action),
72311
72312@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
72313 */
72314 TRACE_EVENT(irq_handler_exit,
72315
72316- TP_PROTO(int irq, struct irqaction *action, int ret),
72317+ TP_PROTO(int irq, const struct irqaction *action, int ret),
72318
72319 TP_ARGS(irq, action, ret),
72320
72321diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
72322index 7caf44c..23c6f27 100644
72323--- a/include/uapi/linux/a.out.h
72324+++ b/include/uapi/linux/a.out.h
72325@@ -39,6 +39,14 @@ enum machine_type {
72326 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
72327 };
72328
72329+/* Constants for the N_FLAGS field */
72330+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72331+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
72332+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
72333+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
72334+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72335+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72336+
72337 #if !defined (N_MAGIC)
72338 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
72339 #endif
72340diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
72341index d876736..ccce5c0 100644
72342--- a/include/uapi/linux/byteorder/little_endian.h
72343+++ b/include/uapi/linux/byteorder/little_endian.h
72344@@ -42,51 +42,51 @@
72345
72346 static inline __le64 __cpu_to_le64p(const __u64 *p)
72347 {
72348- return (__force __le64)*p;
72349+ return (__force const __le64)*p;
72350 }
72351-static inline __u64 __le64_to_cpup(const __le64 *p)
72352+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
72353 {
72354- return (__force __u64)*p;
72355+ return (__force const __u64)*p;
72356 }
72357 static inline __le32 __cpu_to_le32p(const __u32 *p)
72358 {
72359- return (__force __le32)*p;
72360+ return (__force const __le32)*p;
72361 }
72362 static inline __u32 __le32_to_cpup(const __le32 *p)
72363 {
72364- return (__force __u32)*p;
72365+ return (__force const __u32)*p;
72366 }
72367 static inline __le16 __cpu_to_le16p(const __u16 *p)
72368 {
72369- return (__force __le16)*p;
72370+ return (__force const __le16)*p;
72371 }
72372 static inline __u16 __le16_to_cpup(const __le16 *p)
72373 {
72374- return (__force __u16)*p;
72375+ return (__force const __u16)*p;
72376 }
72377 static inline __be64 __cpu_to_be64p(const __u64 *p)
72378 {
72379- return (__force __be64)__swab64p(p);
72380+ return (__force const __be64)__swab64p(p);
72381 }
72382 static inline __u64 __be64_to_cpup(const __be64 *p)
72383 {
72384- return __swab64p((__u64 *)p);
72385+ return __swab64p((const __u64 *)p);
72386 }
72387 static inline __be32 __cpu_to_be32p(const __u32 *p)
72388 {
72389- return (__force __be32)__swab32p(p);
72390+ return (__force const __be32)__swab32p(p);
72391 }
72392-static inline __u32 __be32_to_cpup(const __be32 *p)
72393+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
72394 {
72395- return __swab32p((__u32 *)p);
72396+ return __swab32p((const __u32 *)p);
72397 }
72398 static inline __be16 __cpu_to_be16p(const __u16 *p)
72399 {
72400- return (__force __be16)__swab16p(p);
72401+ return (__force const __be16)__swab16p(p);
72402 }
72403 static inline __u16 __be16_to_cpup(const __be16 *p)
72404 {
72405- return __swab16p((__u16 *)p);
72406+ return __swab16p((const __u16 *)p);
72407 }
72408 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
72409 #define __le64_to_cpus(x) do { (void)(x); } while (0)
72410diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
72411index 126a817..d522bd1 100644
72412--- a/include/uapi/linux/elf.h
72413+++ b/include/uapi/linux/elf.h
72414@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
72415 #define PT_GNU_EH_FRAME 0x6474e550
72416
72417 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
72418+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
72419+
72420+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
72421+
72422+/* Constants for the e_flags field */
72423+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72424+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
72425+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
72426+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
72427+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72428+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72429
72430 /*
72431 * Extended Numbering
72432@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
72433 #define DT_DEBUG 21
72434 #define DT_TEXTREL 22
72435 #define DT_JMPREL 23
72436+#define DT_FLAGS 30
72437+ #define DF_TEXTREL 0x00000004
72438 #define DT_ENCODING 32
72439 #define OLD_DT_LOOS 0x60000000
72440 #define DT_LOOS 0x6000000d
72441@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
72442 #define PF_W 0x2
72443 #define PF_X 0x1
72444
72445+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
72446+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
72447+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
72448+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
72449+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
72450+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
72451+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
72452+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
72453+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
72454+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
72455+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
72456+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
72457+
72458 typedef struct elf32_phdr{
72459 Elf32_Word p_type;
72460 Elf32_Off p_offset;
72461@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
72462 #define EI_OSABI 7
72463 #define EI_PAD 8
72464
72465+#define EI_PAX 14
72466+
72467 #define ELFMAG0 0x7f /* EI_MAG */
72468 #define ELFMAG1 'E'
72469 #define ELFMAG2 'L'
72470diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
72471index aa169c4..6a2771d 100644
72472--- a/include/uapi/linux/personality.h
72473+++ b/include/uapi/linux/personality.h
72474@@ -30,6 +30,7 @@ enum {
72475 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
72476 ADDR_NO_RANDOMIZE | \
72477 ADDR_COMPAT_LAYOUT | \
72478+ ADDR_LIMIT_3GB | \
72479 MMAP_PAGE_ZERO)
72480
72481 /*
72482diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
72483index 7530e74..e714828 100644
72484--- a/include/uapi/linux/screen_info.h
72485+++ b/include/uapi/linux/screen_info.h
72486@@ -43,7 +43,8 @@ struct screen_info {
72487 __u16 pages; /* 0x32 */
72488 __u16 vesa_attributes; /* 0x34 */
72489 __u32 capabilities; /* 0x36 */
72490- __u8 _reserved[6]; /* 0x3a */
72491+ __u16 vesapm_size; /* 0x3a */
72492+ __u8 _reserved[4]; /* 0x3c */
72493 } __attribute__((packed));
72494
72495 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
72496diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
72497index 0e011eb..82681b1 100644
72498--- a/include/uapi/linux/swab.h
72499+++ b/include/uapi/linux/swab.h
72500@@ -43,7 +43,7 @@
72501 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
72502 */
72503
72504-static inline __attribute_const__ __u16 __fswab16(__u16 val)
72505+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
72506 {
72507 #ifdef __HAVE_BUILTIN_BSWAP16__
72508 return __builtin_bswap16(val);
72509@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
72510 #endif
72511 }
72512
72513-static inline __attribute_const__ __u32 __fswab32(__u32 val)
72514+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
72515 {
72516 #ifdef __HAVE_BUILTIN_BSWAP32__
72517 return __builtin_bswap32(val);
72518@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
72519 #endif
72520 }
72521
72522-static inline __attribute_const__ __u64 __fswab64(__u64 val)
72523+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
72524 {
72525 #ifdef __HAVE_BUILTIN_BSWAP64__
72526 return __builtin_bswap64(val);
72527diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
72528index 6d67213..8dab561 100644
72529--- a/include/uapi/linux/sysctl.h
72530+++ b/include/uapi/linux/sysctl.h
72531@@ -155,7 +155,11 @@ enum
72532 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
72533 };
72534
72535-
72536+#ifdef CONFIG_PAX_SOFTMODE
72537+enum {
72538+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
72539+};
72540+#endif
72541
72542 /* CTL_VM names: */
72543 enum
72544diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
72545index 26607bd..588b65f 100644
72546--- a/include/uapi/linux/xattr.h
72547+++ b/include/uapi/linux/xattr.h
72548@@ -60,5 +60,9 @@
72549 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
72550 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
72551
72552+/* User namespace */
72553+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
72554+#define XATTR_PAX_FLAGS_SUFFIX "flags"
72555+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
72556
72557 #endif /* _UAPI_LINUX_XATTR_H */
72558diff --git a/include/video/udlfb.h b/include/video/udlfb.h
72559index f9466fa..f4e2b81 100644
72560--- a/include/video/udlfb.h
72561+++ b/include/video/udlfb.h
72562@@ -53,10 +53,10 @@ struct dlfb_data {
72563 u32 pseudo_palette[256];
72564 int blank_mode; /*one of FB_BLANK_ */
72565 /* blit-only rendering path metrics, exposed through sysfs */
72566- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
72567- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
72568- atomic_t bytes_sent; /* to usb, after compression including overhead */
72569- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
72570+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
72571+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
72572+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
72573+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
72574 };
72575
72576 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
72577diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
72578index 0993a22..32ba2fe 100644
72579--- a/include/video/uvesafb.h
72580+++ b/include/video/uvesafb.h
72581@@ -177,6 +177,7 @@ struct uvesafb_par {
72582 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
72583 u8 pmi_setpal; /* PMI for palette changes */
72584 u16 *pmi_base; /* protected mode interface location */
72585+ u8 *pmi_code; /* protected mode code location */
72586 void *pmi_start;
72587 void *pmi_pal;
72588 u8 *vbe_state_orig; /*
72589diff --git a/init/Kconfig b/init/Kconfig
72590index be8b7f5..1eeca9b 100644
72591--- a/init/Kconfig
72592+++ b/init/Kconfig
72593@@ -990,6 +990,7 @@ endif # CGROUPS
72594
72595 config CHECKPOINT_RESTORE
72596 bool "Checkpoint/restore support" if EXPERT
72597+ depends on !GRKERNSEC
72598 default n
72599 help
72600 Enables additional kernel features in a sake of checkpoint/restore.
72601@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
72602
72603 config COMPAT_BRK
72604 bool "Disable heap randomization"
72605- default y
72606+ default n
72607 help
72608 Randomizing heap placement makes heap exploits harder, but it
72609 also breaks ancient binaries (including anything libc5 based).
72610@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
72611 config STOP_MACHINE
72612 bool
72613 default y
72614- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
72615+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
72616 help
72617 Need stop_machine() primitive.
72618
72619diff --git a/init/Makefile b/init/Makefile
72620index 7bc47ee..6da2dc7 100644
72621--- a/init/Makefile
72622+++ b/init/Makefile
72623@@ -2,6 +2,9 @@
72624 # Makefile for the linux kernel.
72625 #
72626
72627+ccflags-y := $(GCC_PLUGINS_CFLAGS)
72628+asflags-y := $(GCC_PLUGINS_AFLAGS)
72629+
72630 obj-y := main.o version.o mounts.o
72631 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
72632 obj-y += noinitramfs.o
72633diff --git a/init/do_mounts.c b/init/do_mounts.c
72634index 1d1b634..a1c810f 100644
72635--- a/init/do_mounts.c
72636+++ b/init/do_mounts.c
72637@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
72638 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
72639 {
72640 struct super_block *s;
72641- int err = sys_mount(name, "/root", fs, flags, data);
72642+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
72643 if (err)
72644 return err;
72645
72646- sys_chdir("/root");
72647+ sys_chdir((const char __force_user *)"/root");
72648 s = current->fs->pwd.dentry->d_sb;
72649 ROOT_DEV = s->s_dev;
72650 printk(KERN_INFO
72651@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
72652 va_start(args, fmt);
72653 vsprintf(buf, fmt, args);
72654 va_end(args);
72655- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
72656+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
72657 if (fd >= 0) {
72658 sys_ioctl(fd, FDEJECT, 0);
72659 sys_close(fd);
72660 }
72661 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
72662- fd = sys_open("/dev/console", O_RDWR, 0);
72663+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
72664 if (fd >= 0) {
72665 sys_ioctl(fd, TCGETS, (long)&termios);
72666 termios.c_lflag &= ~ICANON;
72667 sys_ioctl(fd, TCSETSF, (long)&termios);
72668- sys_read(fd, &c, 1);
72669+ sys_read(fd, (char __user *)&c, 1);
72670 termios.c_lflag |= ICANON;
72671 sys_ioctl(fd, TCSETSF, (long)&termios);
72672 sys_close(fd);
72673@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
72674 mount_root();
72675 out:
72676 devtmpfs_mount("dev");
72677- sys_mount(".", "/", NULL, MS_MOVE, NULL);
72678- sys_chroot(".");
72679+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
72680+ sys_chroot((const char __force_user *)".");
72681 }
72682diff --git a/init/do_mounts.h b/init/do_mounts.h
72683index f5b978a..69dbfe8 100644
72684--- a/init/do_mounts.h
72685+++ b/init/do_mounts.h
72686@@ -15,15 +15,15 @@ extern int root_mountflags;
72687
72688 static inline int create_dev(char *name, dev_t dev)
72689 {
72690- sys_unlink(name);
72691- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
72692+ sys_unlink((char __force_user *)name);
72693+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
72694 }
72695
72696 #if BITS_PER_LONG == 32
72697 static inline u32 bstat(char *name)
72698 {
72699 struct stat64 stat;
72700- if (sys_stat64(name, &stat) != 0)
72701+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
72702 return 0;
72703 if (!S_ISBLK(stat.st_mode))
72704 return 0;
72705@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
72706 static inline u32 bstat(char *name)
72707 {
72708 struct stat stat;
72709- if (sys_newstat(name, &stat) != 0)
72710+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
72711 return 0;
72712 if (!S_ISBLK(stat.st_mode))
72713 return 0;
72714diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
72715index f9acf71..1e19144 100644
72716--- a/init/do_mounts_initrd.c
72717+++ b/init/do_mounts_initrd.c
72718@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
72719 create_dev("/dev/root.old", Root_RAM0);
72720 /* mount initrd on rootfs' /root */
72721 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
72722- sys_mkdir("/old", 0700);
72723- sys_chdir("/old");
72724+ sys_mkdir((const char __force_user *)"/old", 0700);
72725+ sys_chdir((const char __force_user *)"/old");
72726
72727 /*
72728 * In case that a resume from disk is carried out by linuxrc or one of
72729@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
72730 current->flags &= ~PF_FREEZER_SKIP;
72731
72732 /* move initrd to rootfs' /old */
72733- sys_mount("..", ".", NULL, MS_MOVE, NULL);
72734+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
72735 /* switch root and cwd back to / of rootfs */
72736- sys_chroot("..");
72737+ sys_chroot((const char __force_user *)"..");
72738
72739 if (new_decode_dev(real_root_dev) == Root_RAM0) {
72740- sys_chdir("/old");
72741+ sys_chdir((const char __force_user *)"/old");
72742 return;
72743 }
72744
72745- sys_chdir("/");
72746+ sys_chdir((const char __force_user *)"/");
72747 ROOT_DEV = new_decode_dev(real_root_dev);
72748 mount_root();
72749
72750 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
72751- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
72752+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
72753 if (!error)
72754 printk("okay\n");
72755 else {
72756- int fd = sys_open("/dev/root.old", O_RDWR, 0);
72757+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
72758 if (error == -ENOENT)
72759 printk("/initrd does not exist. Ignored.\n");
72760 else
72761 printk("failed\n");
72762 printk(KERN_NOTICE "Unmounting old root\n");
72763- sys_umount("/old", MNT_DETACH);
72764+ sys_umount((char __force_user *)"/old", MNT_DETACH);
72765 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
72766 if (fd < 0) {
72767 error = fd;
72768@@ -120,11 +120,11 @@ int __init initrd_load(void)
72769 * mounted in the normal path.
72770 */
72771 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
72772- sys_unlink("/initrd.image");
72773+ sys_unlink((const char __force_user *)"/initrd.image");
72774 handle_initrd();
72775 return 1;
72776 }
72777 }
72778- sys_unlink("/initrd.image");
72779+ sys_unlink((const char __force_user *)"/initrd.image");
72780 return 0;
72781 }
72782diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
72783index 8cb6db5..d729f50 100644
72784--- a/init/do_mounts_md.c
72785+++ b/init/do_mounts_md.c
72786@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
72787 partitioned ? "_d" : "", minor,
72788 md_setup_args[ent].device_names);
72789
72790- fd = sys_open(name, 0, 0);
72791+ fd = sys_open((char __force_user *)name, 0, 0);
72792 if (fd < 0) {
72793 printk(KERN_ERR "md: open failed - cannot start "
72794 "array %s\n", name);
72795@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
72796 * array without it
72797 */
72798 sys_close(fd);
72799- fd = sys_open(name, 0, 0);
72800+ fd = sys_open((char __force_user *)name, 0, 0);
72801 sys_ioctl(fd, BLKRRPART, 0);
72802 }
72803 sys_close(fd);
72804@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
72805
72806 wait_for_device_probe();
72807
72808- fd = sys_open("/dev/md0", 0, 0);
72809+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
72810 if (fd >= 0) {
72811 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
72812 sys_close(fd);
72813diff --git a/init/init_task.c b/init/init_task.c
72814index 8b2f399..f0797c9 100644
72815--- a/init/init_task.c
72816+++ b/init/init_task.c
72817@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
72818 * Initial thread structure. Alignment of this is handled by a special
72819 * linker map entry.
72820 */
72821+#ifdef CONFIG_X86
72822+union thread_union init_thread_union __init_task_data;
72823+#else
72824 union thread_union init_thread_union __init_task_data =
72825 { INIT_THREAD_INFO(init_task) };
72826+#endif
72827diff --git a/init/initramfs.c b/init/initramfs.c
72828index 84c6bf1..8899338 100644
72829--- a/init/initramfs.c
72830+++ b/init/initramfs.c
72831@@ -84,7 +84,7 @@ static void __init free_hash(void)
72832 }
72833 }
72834
72835-static long __init do_utime(char *filename, time_t mtime)
72836+static long __init do_utime(char __force_user *filename, time_t mtime)
72837 {
72838 struct timespec t[2];
72839
72840@@ -119,7 +119,7 @@ static void __init dir_utime(void)
72841 struct dir_entry *de, *tmp;
72842 list_for_each_entry_safe(de, tmp, &dir_list, list) {
72843 list_del(&de->list);
72844- do_utime(de->name, de->mtime);
72845+ do_utime((char __force_user *)de->name, de->mtime);
72846 kfree(de->name);
72847 kfree(de);
72848 }
72849@@ -281,7 +281,7 @@ static int __init maybe_link(void)
72850 if (nlink >= 2) {
72851 char *old = find_link(major, minor, ino, mode, collected);
72852 if (old)
72853- return (sys_link(old, collected) < 0) ? -1 : 1;
72854+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
72855 }
72856 return 0;
72857 }
72858@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
72859 {
72860 struct stat st;
72861
72862- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
72863+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
72864 if (S_ISDIR(st.st_mode))
72865- sys_rmdir(path);
72866+ sys_rmdir((char __force_user *)path);
72867 else
72868- sys_unlink(path);
72869+ sys_unlink((char __force_user *)path);
72870 }
72871 }
72872
72873@@ -315,7 +315,7 @@ static int __init do_name(void)
72874 int openflags = O_WRONLY|O_CREAT;
72875 if (ml != 1)
72876 openflags |= O_TRUNC;
72877- wfd = sys_open(collected, openflags, mode);
72878+ wfd = sys_open((char __force_user *)collected, openflags, mode);
72879
72880 if (wfd >= 0) {
72881 sys_fchown(wfd, uid, gid);
72882@@ -327,17 +327,17 @@ static int __init do_name(void)
72883 }
72884 }
72885 } else if (S_ISDIR(mode)) {
72886- sys_mkdir(collected, mode);
72887- sys_chown(collected, uid, gid);
72888- sys_chmod(collected, mode);
72889+ sys_mkdir((char __force_user *)collected, mode);
72890+ sys_chown((char __force_user *)collected, uid, gid);
72891+ sys_chmod((char __force_user *)collected, mode);
72892 dir_add(collected, mtime);
72893 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
72894 S_ISFIFO(mode) || S_ISSOCK(mode)) {
72895 if (maybe_link() == 0) {
72896- sys_mknod(collected, mode, rdev);
72897- sys_chown(collected, uid, gid);
72898- sys_chmod(collected, mode);
72899- do_utime(collected, mtime);
72900+ sys_mknod((char __force_user *)collected, mode, rdev);
72901+ sys_chown((char __force_user *)collected, uid, gid);
72902+ sys_chmod((char __force_user *)collected, mode);
72903+ do_utime((char __force_user *)collected, mtime);
72904 }
72905 }
72906 return 0;
72907@@ -346,15 +346,15 @@ static int __init do_name(void)
72908 static int __init do_copy(void)
72909 {
72910 if (count >= body_len) {
72911- sys_write(wfd, victim, body_len);
72912+ sys_write(wfd, (char __force_user *)victim, body_len);
72913 sys_close(wfd);
72914- do_utime(vcollected, mtime);
72915+ do_utime((char __force_user *)vcollected, mtime);
72916 kfree(vcollected);
72917 eat(body_len);
72918 state = SkipIt;
72919 return 0;
72920 } else {
72921- sys_write(wfd, victim, count);
72922+ sys_write(wfd, (char __force_user *)victim, count);
72923 body_len -= count;
72924 eat(count);
72925 return 1;
72926@@ -365,9 +365,9 @@ static int __init do_symlink(void)
72927 {
72928 collected[N_ALIGN(name_len) + body_len] = '\0';
72929 clean_path(collected, 0);
72930- sys_symlink(collected + N_ALIGN(name_len), collected);
72931- sys_lchown(collected, uid, gid);
72932- do_utime(collected, mtime);
72933+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
72934+ sys_lchown((char __force_user *)collected, uid, gid);
72935+ do_utime((char __force_user *)collected, mtime);
72936 state = SkipIt;
72937 next_state = Reset;
72938 return 0;
72939diff --git a/init/main.c b/init/main.c
72940index cee4b5c..6a3402b 100644
72941--- a/init/main.c
72942+++ b/init/main.c
72943@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
72944 extern void tc_init(void);
72945 #endif
72946
72947+extern void grsecurity_init(void);
72948+
72949 /*
72950 * Debug helper: via this flag we know that we are in 'early bootup code'
72951 * where only the boot processor is running with IRQ disabled. This means
72952@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
72953
72954 __setup("reset_devices", set_reset_devices);
72955
72956+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
72957+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
72958+static int __init setup_grsec_proc_gid(char *str)
72959+{
72960+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
72961+ return 1;
72962+}
72963+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
72964+#endif
72965+
72966+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
72967+extern char pax_enter_kernel_user[];
72968+extern char pax_exit_kernel_user[];
72969+extern pgdval_t clone_pgd_mask;
72970+#endif
72971+
72972+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
72973+static int __init setup_pax_nouderef(char *str)
72974+{
72975+#ifdef CONFIG_X86_32
72976+ unsigned int cpu;
72977+ struct desc_struct *gdt;
72978+
72979+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
72980+ gdt = get_cpu_gdt_table(cpu);
72981+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
72982+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
72983+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
72984+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
72985+ }
72986+ loadsegment(ds, __KERNEL_DS);
72987+ loadsegment(es, __KERNEL_DS);
72988+ loadsegment(ss, __KERNEL_DS);
72989+#else
72990+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
72991+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
72992+ clone_pgd_mask = ~(pgdval_t)0UL;
72993+#endif
72994+
72995+ return 0;
72996+}
72997+early_param("pax_nouderef", setup_pax_nouderef);
72998+#endif
72999+
73000+#ifdef CONFIG_PAX_SOFTMODE
73001+int pax_softmode;
73002+
73003+static int __init setup_pax_softmode(char *str)
73004+{
73005+ get_option(&str, &pax_softmode);
73006+ return 1;
73007+}
73008+__setup("pax_softmode=", setup_pax_softmode);
73009+#endif
73010+
73011 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
73012 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
73013 static const char *panic_later, *panic_param;
73014@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
73015 {
73016 int count = preempt_count();
73017 int ret;
73018+ const char *msg1 = "", *msg2 = "";
73019
73020 if (initcall_debug)
73021 ret = do_one_initcall_debug(fn);
73022@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
73023 sprintf(msgbuf, "error code %d ", ret);
73024
73025 if (preempt_count() != count) {
73026- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
73027+ msg1 = " preemption imbalance";
73028 preempt_count() = count;
73029 }
73030 if (irqs_disabled()) {
73031- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
73032+ msg2 = " disabled interrupts";
73033 local_irq_enable();
73034 }
73035- if (msgbuf[0]) {
73036- printk("initcall %pF returned with %s\n", fn, msgbuf);
73037+ if (msgbuf[0] || *msg1 || *msg2) {
73038+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
73039 }
73040
73041 return ret;
73042@@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
73043 level, level,
73044 &repair_env_string);
73045
73046- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
73047+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
73048 do_one_initcall(*fn);
73049+
73050+#ifdef CONFIG_PAX_LATENT_ENTROPY
73051+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73052+#endif
73053+
73054+ }
73055 }
73056
73057 static void __init do_initcalls(void)
73058@@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
73059 {
73060 initcall_t *fn;
73061
73062- for (fn = __initcall_start; fn < __initcall0_start; fn++)
73063+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
73064 do_one_initcall(*fn);
73065+
73066+#ifdef CONFIG_PAX_LATENT_ENTROPY
73067+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73068+#endif
73069+
73070+ }
73071 }
73072
73073 static int run_init_process(const char *init_filename)
73074@@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
73075 do_basic_setup();
73076
73077 /* Open the /dev/console on the rootfs, this should never fail */
73078- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
73079+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
73080 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
73081
73082 (void) sys_dup(0);
73083@@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
73084 if (!ramdisk_execute_command)
73085 ramdisk_execute_command = "/init";
73086
73087- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
73088+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
73089 ramdisk_execute_command = NULL;
73090 prepare_namespace();
73091 }
73092
73093+ grsecurity_init();
73094+
73095 /*
73096 * Ok, we have completed the initial bootup, and
73097 * we're essentially up and running. Get rid of the
73098diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
73099index 130dfec..cc88451 100644
73100--- a/ipc/ipc_sysctl.c
73101+++ b/ipc/ipc_sysctl.c
73102@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
73103 static int proc_ipc_dointvec(ctl_table *table, int write,
73104 void __user *buffer, size_t *lenp, loff_t *ppos)
73105 {
73106- struct ctl_table ipc_table;
73107+ ctl_table_no_const ipc_table;
73108
73109 memcpy(&ipc_table, table, sizeof(ipc_table));
73110 ipc_table.data = get_ipc(table);
73111@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
73112 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
73113 void __user *buffer, size_t *lenp, loff_t *ppos)
73114 {
73115- struct ctl_table ipc_table;
73116+ ctl_table_no_const ipc_table;
73117
73118 memcpy(&ipc_table, table, sizeof(ipc_table));
73119 ipc_table.data = get_ipc(table);
73120@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
73121 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73122 void __user *buffer, size_t *lenp, loff_t *ppos)
73123 {
73124- struct ctl_table ipc_table;
73125+ ctl_table_no_const ipc_table;
73126 size_t lenp_bef = *lenp;
73127 int rc;
73128
73129@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73130 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
73131 void __user *buffer, size_t *lenp, loff_t *ppos)
73132 {
73133- struct ctl_table ipc_table;
73134+ ctl_table_no_const ipc_table;
73135 memcpy(&ipc_table, table, sizeof(ipc_table));
73136 ipc_table.data = get_ipc(table);
73137
73138@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
73139 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
73140 void __user *buffer, size_t *lenp, loff_t *ppos)
73141 {
73142- struct ctl_table ipc_table;
73143+ ctl_table_no_const ipc_table;
73144 size_t lenp_bef = *lenp;
73145 int oldval;
73146 int rc;
73147diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
73148index 383d638..943fdbb 100644
73149--- a/ipc/mq_sysctl.c
73150+++ b/ipc/mq_sysctl.c
73151@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
73152 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
73153 void __user *buffer, size_t *lenp, loff_t *ppos)
73154 {
73155- struct ctl_table mq_table;
73156+ ctl_table_no_const mq_table;
73157 memcpy(&mq_table, table, sizeof(mq_table));
73158 mq_table.data = get_mq(table);
73159
73160diff --git a/ipc/mqueue.c b/ipc/mqueue.c
73161index 71a3ca1..cc330ee 100644
73162--- a/ipc/mqueue.c
73163+++ b/ipc/mqueue.c
73164@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
73165 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
73166 info->attr.mq_msgsize);
73167
73168+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
73169 spin_lock(&mq_lock);
73170 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
73171 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
73172diff --git a/ipc/msg.c b/ipc/msg.c
73173index 31cd1bf..362ea07 100644
73174--- a/ipc/msg.c
73175+++ b/ipc/msg.c
73176@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
73177 return security_msg_queue_associate(msq, msgflg);
73178 }
73179
73180+static struct ipc_ops msg_ops = {
73181+ .getnew = newque,
73182+ .associate = msg_security,
73183+ .more_checks = NULL
73184+};
73185+
73186 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
73187 {
73188 struct ipc_namespace *ns;
73189- struct ipc_ops msg_ops;
73190 struct ipc_params msg_params;
73191
73192 ns = current->nsproxy->ipc_ns;
73193
73194- msg_ops.getnew = newque;
73195- msg_ops.associate = msg_security;
73196- msg_ops.more_checks = NULL;
73197-
73198 msg_params.key = key;
73199 msg_params.flg = msgflg;
73200
73201diff --git a/ipc/sem.c b/ipc/sem.c
73202index 58d31f1..cce7a55 100644
73203--- a/ipc/sem.c
73204+++ b/ipc/sem.c
73205@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
73206 return 0;
73207 }
73208
73209+static struct ipc_ops sem_ops = {
73210+ .getnew = newary,
73211+ .associate = sem_security,
73212+ .more_checks = sem_more_checks
73213+};
73214+
73215 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73216 {
73217 struct ipc_namespace *ns;
73218- struct ipc_ops sem_ops;
73219 struct ipc_params sem_params;
73220
73221 ns = current->nsproxy->ipc_ns;
73222@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73223 if (nsems < 0 || nsems > ns->sc_semmsl)
73224 return -EINVAL;
73225
73226- sem_ops.getnew = newary;
73227- sem_ops.associate = sem_security;
73228- sem_ops.more_checks = sem_more_checks;
73229-
73230 sem_params.key = key;
73231 sem_params.flg = semflg;
73232 sem_params.u.nsems = nsems;
73233diff --git a/ipc/shm.c b/ipc/shm.c
73234index 4fa6d8f..55cff14 100644
73235--- a/ipc/shm.c
73236+++ b/ipc/shm.c
73237@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
73238 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
73239 #endif
73240
73241+#ifdef CONFIG_GRKERNSEC
73242+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73243+ const time_t shm_createtime, const kuid_t cuid,
73244+ const int shmid);
73245+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73246+ const time_t shm_createtime);
73247+#endif
73248+
73249 void shm_init_ns(struct ipc_namespace *ns)
73250 {
73251 ns->shm_ctlmax = SHMMAX;
73252@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
73253 shp->shm_lprid = 0;
73254 shp->shm_atim = shp->shm_dtim = 0;
73255 shp->shm_ctim = get_seconds();
73256+#ifdef CONFIG_GRKERNSEC
73257+ {
73258+ struct timespec timeval;
73259+ do_posix_clock_monotonic_gettime(&timeval);
73260+
73261+ shp->shm_createtime = timeval.tv_sec;
73262+ }
73263+#endif
73264 shp->shm_segsz = size;
73265 shp->shm_nattch = 0;
73266 shp->shm_file = file;
73267@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
73268 return 0;
73269 }
73270
73271+static struct ipc_ops shm_ops = {
73272+ .getnew = newseg,
73273+ .associate = shm_security,
73274+ .more_checks = shm_more_checks
73275+};
73276+
73277 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
73278 {
73279 struct ipc_namespace *ns;
73280- struct ipc_ops shm_ops;
73281 struct ipc_params shm_params;
73282
73283 ns = current->nsproxy->ipc_ns;
73284
73285- shm_ops.getnew = newseg;
73286- shm_ops.associate = shm_security;
73287- shm_ops.more_checks = shm_more_checks;
73288-
73289 shm_params.key = key;
73290 shm_params.flg = shmflg;
73291 shm_params.u.size = size;
73292@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73293 f_mode = FMODE_READ | FMODE_WRITE;
73294 }
73295 if (shmflg & SHM_EXEC) {
73296+
73297+#ifdef CONFIG_PAX_MPROTECT
73298+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
73299+ goto out;
73300+#endif
73301+
73302 prot |= PROT_EXEC;
73303 acc_mode |= S_IXUGO;
73304 }
73305@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73306 if (err)
73307 goto out_unlock;
73308
73309+#ifdef CONFIG_GRKERNSEC
73310+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
73311+ shp->shm_perm.cuid, shmid) ||
73312+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
73313+ err = -EACCES;
73314+ goto out_unlock;
73315+ }
73316+#endif
73317+
73318 path = shp->shm_file->f_path;
73319 path_get(&path);
73320 shp->shm_nattch++;
73321+#ifdef CONFIG_GRKERNSEC
73322+ shp->shm_lapid = current->pid;
73323+#endif
73324 size = i_size_read(path.dentry->d_inode);
73325 shm_unlock(shp);
73326
73327diff --git a/kernel/acct.c b/kernel/acct.c
73328index 051e071..15e0920 100644
73329--- a/kernel/acct.c
73330+++ b/kernel/acct.c
73331@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
73332 */
73333 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
73334 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
73335- file->f_op->write(file, (char *)&ac,
73336+ file->f_op->write(file, (char __force_user *)&ac,
73337 sizeof(acct_t), &file->f_pos);
73338 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
73339 set_fs(fs);
73340diff --git a/kernel/audit.c b/kernel/audit.c
73341index d596e53..dbef3c3 100644
73342--- a/kernel/audit.c
73343+++ b/kernel/audit.c
73344@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
73345 3) suppressed due to audit_rate_limit
73346 4) suppressed due to audit_backlog_limit
73347 */
73348-static atomic_t audit_lost = ATOMIC_INIT(0);
73349+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
73350
73351 /* The netlink socket. */
73352 static struct sock *audit_sock;
73353@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
73354 unsigned long now;
73355 int print;
73356
73357- atomic_inc(&audit_lost);
73358+ atomic_inc_unchecked(&audit_lost);
73359
73360 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
73361
73362@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
73363 printk(KERN_WARNING
73364 "audit: audit_lost=%d audit_rate_limit=%d "
73365 "audit_backlog_limit=%d\n",
73366- atomic_read(&audit_lost),
73367+ atomic_read_unchecked(&audit_lost),
73368 audit_rate_limit,
73369 audit_backlog_limit);
73370 audit_panic(message);
73371@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
73372 status_set.pid = audit_pid;
73373 status_set.rate_limit = audit_rate_limit;
73374 status_set.backlog_limit = audit_backlog_limit;
73375- status_set.lost = atomic_read(&audit_lost);
73376+ status_set.lost = atomic_read_unchecked(&audit_lost);
73377 status_set.backlog = skb_queue_len(&audit_skb_queue);
73378 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
73379 &status_set, sizeof(status_set));
73380diff --git a/kernel/auditsc.c b/kernel/auditsc.c
73381index a371f85..da826c1 100644
73382--- a/kernel/auditsc.c
73383+++ b/kernel/auditsc.c
73384@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
73385 }
73386
73387 /* global counter which is incremented every time something logs in */
73388-static atomic_t session_id = ATOMIC_INIT(0);
73389+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
73390
73391 /**
73392 * audit_set_loginuid - set current task's audit_context loginuid
73393@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
73394 return -EPERM;
73395 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
73396
73397- sessionid = atomic_inc_return(&session_id);
73398+ sessionid = atomic_inc_return_unchecked(&session_id);
73399 if (context && context->in_syscall) {
73400 struct audit_buffer *ab;
73401
73402diff --git a/kernel/capability.c b/kernel/capability.c
73403index 493d972..f87dfbd 100644
73404--- a/kernel/capability.c
73405+++ b/kernel/capability.c
73406@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
73407 * before modification is attempted and the application
73408 * fails.
73409 */
73410+ if (tocopy > ARRAY_SIZE(kdata))
73411+ return -EFAULT;
73412+
73413 if (copy_to_user(dataptr, kdata, tocopy
73414 * sizeof(struct __user_cap_data_struct))) {
73415 return -EFAULT;
73416@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
73417 int ret;
73418
73419 rcu_read_lock();
73420- ret = security_capable(__task_cred(t), ns, cap);
73421+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
73422+ gr_task_is_capable(t, __task_cred(t), cap);
73423 rcu_read_unlock();
73424
73425- return (ret == 0);
73426+ return ret;
73427 }
73428
73429 /**
73430@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
73431 int ret;
73432
73433 rcu_read_lock();
73434- ret = security_capable_noaudit(__task_cred(t), ns, cap);
73435+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
73436 rcu_read_unlock();
73437
73438- return (ret == 0);
73439+ return ret;
73440 }
73441
73442 /**
73443@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
73444 BUG();
73445 }
73446
73447- if (security_capable(current_cred(), ns, cap) == 0) {
73448+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
73449 current->flags |= PF_SUPERPRIV;
73450 return true;
73451 }
73452@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
73453 }
73454 EXPORT_SYMBOL(ns_capable);
73455
73456+bool ns_capable_nolog(struct user_namespace *ns, int cap)
73457+{
73458+ if (unlikely(!cap_valid(cap))) {
73459+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
73460+ BUG();
73461+ }
73462+
73463+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
73464+ current->flags |= PF_SUPERPRIV;
73465+ return true;
73466+ }
73467+ return false;
73468+}
73469+EXPORT_SYMBOL(ns_capable_nolog);
73470+
73471 /**
73472 * capable - Determine if the current task has a superior capability in effect
73473 * @cap: The capability to be tested for
73474@@ -408,6 +427,12 @@ bool capable(int cap)
73475 }
73476 EXPORT_SYMBOL(capable);
73477
73478+bool capable_nolog(int cap)
73479+{
73480+ return ns_capable_nolog(&init_user_ns, cap);
73481+}
73482+EXPORT_SYMBOL(capable_nolog);
73483+
73484 /**
73485 * nsown_capable - Check superior capability to one's own user_ns
73486 * @cap: The capability in question
73487@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
73488
73489 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
73490 }
73491+
73492+bool inode_capable_nolog(const struct inode *inode, int cap)
73493+{
73494+ struct user_namespace *ns = current_user_ns();
73495+
73496+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
73497+}
73498diff --git a/kernel/cgroup.c b/kernel/cgroup.c
73499index 1e23664..570a83d 100644
73500--- a/kernel/cgroup.c
73501+++ b/kernel/cgroup.c
73502@@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
73503 struct css_set *cg = link->cg;
73504 struct task_struct *task;
73505 int count = 0;
73506- seq_printf(seq, "css_set %p\n", cg);
73507+ seq_printf(seq, "css_set %pK\n", cg);
73508 list_for_each_entry(task, &cg->tasks, cg_list) {
73509 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
73510 seq_puts(seq, " ...\n");
73511diff --git a/kernel/compat.c b/kernel/compat.c
73512index 36700e9..73d770c 100644
73513--- a/kernel/compat.c
73514+++ b/kernel/compat.c
73515@@ -13,6 +13,7 @@
73516
73517 #include <linux/linkage.h>
73518 #include <linux/compat.h>
73519+#include <linux/module.h>
73520 #include <linux/errno.h>
73521 #include <linux/time.h>
73522 #include <linux/signal.h>
73523@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
73524 mm_segment_t oldfs;
73525 long ret;
73526
73527- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
73528+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
73529 oldfs = get_fs();
73530 set_fs(KERNEL_DS);
73531 ret = hrtimer_nanosleep_restart(restart);
73532@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
73533 oldfs = get_fs();
73534 set_fs(KERNEL_DS);
73535 ret = hrtimer_nanosleep(&tu,
73536- rmtp ? (struct timespec __user *)&rmt : NULL,
73537+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
73538 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
73539 set_fs(oldfs);
73540
73541@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
73542 mm_segment_t old_fs = get_fs();
73543
73544 set_fs(KERNEL_DS);
73545- ret = sys_sigpending((old_sigset_t __user *) &s);
73546+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
73547 set_fs(old_fs);
73548 if (ret == 0)
73549 ret = put_user(s, set);
73550@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
73551 mm_segment_t old_fs = get_fs();
73552
73553 set_fs(KERNEL_DS);
73554- ret = sys_old_getrlimit(resource, &r);
73555+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
73556 set_fs(old_fs);
73557
73558 if (!ret) {
73559@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
73560 mm_segment_t old_fs = get_fs();
73561
73562 set_fs(KERNEL_DS);
73563- ret = sys_getrusage(who, (struct rusage __user *) &r);
73564+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
73565 set_fs(old_fs);
73566
73567 if (ret)
73568@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
73569 set_fs (KERNEL_DS);
73570 ret = sys_wait4(pid,
73571 (stat_addr ?
73572- (unsigned int __user *) &status : NULL),
73573- options, (struct rusage __user *) &r);
73574+ (unsigned int __force_user *) &status : NULL),
73575+ options, (struct rusage __force_user *) &r);
73576 set_fs (old_fs);
73577
73578 if (ret > 0) {
73579@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
73580 memset(&info, 0, sizeof(info));
73581
73582 set_fs(KERNEL_DS);
73583- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
73584- uru ? (struct rusage __user *)&ru : NULL);
73585+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
73586+ uru ? (struct rusage __force_user *)&ru : NULL);
73587 set_fs(old_fs);
73588
73589 if ((ret < 0) || (info.si_signo == 0))
73590@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
73591 oldfs = get_fs();
73592 set_fs(KERNEL_DS);
73593 err = sys_timer_settime(timer_id, flags,
73594- (struct itimerspec __user *) &newts,
73595- (struct itimerspec __user *) &oldts);
73596+ (struct itimerspec __force_user *) &newts,
73597+ (struct itimerspec __force_user *) &oldts);
73598 set_fs(oldfs);
73599 if (!err && old && put_compat_itimerspec(old, &oldts))
73600 return -EFAULT;
73601@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
73602 oldfs = get_fs();
73603 set_fs(KERNEL_DS);
73604 err = sys_timer_gettime(timer_id,
73605- (struct itimerspec __user *) &ts);
73606+ (struct itimerspec __force_user *) &ts);
73607 set_fs(oldfs);
73608 if (!err && put_compat_itimerspec(setting, &ts))
73609 return -EFAULT;
73610@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
73611 oldfs = get_fs();
73612 set_fs(KERNEL_DS);
73613 err = sys_clock_settime(which_clock,
73614- (struct timespec __user *) &ts);
73615+ (struct timespec __force_user *) &ts);
73616 set_fs(oldfs);
73617 return err;
73618 }
73619@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
73620 oldfs = get_fs();
73621 set_fs(KERNEL_DS);
73622 err = sys_clock_gettime(which_clock,
73623- (struct timespec __user *) &ts);
73624+ (struct timespec __force_user *) &ts);
73625 set_fs(oldfs);
73626 if (!err && put_compat_timespec(&ts, tp))
73627 return -EFAULT;
73628@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
73629
73630 oldfs = get_fs();
73631 set_fs(KERNEL_DS);
73632- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
73633+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
73634 set_fs(oldfs);
73635
73636 err = compat_put_timex(utp, &txc);
73637@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
73638 oldfs = get_fs();
73639 set_fs(KERNEL_DS);
73640 err = sys_clock_getres(which_clock,
73641- (struct timespec __user *) &ts);
73642+ (struct timespec __force_user *) &ts);
73643 set_fs(oldfs);
73644 if (!err && tp && put_compat_timespec(&ts, tp))
73645 return -EFAULT;
73646@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
73647 long err;
73648 mm_segment_t oldfs;
73649 struct timespec tu;
73650- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
73651+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
73652
73653- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
73654+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
73655 oldfs = get_fs();
73656 set_fs(KERNEL_DS);
73657 err = clock_nanosleep_restart(restart);
73658@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
73659 oldfs = get_fs();
73660 set_fs(KERNEL_DS);
73661 err = sys_clock_nanosleep(which_clock, flags,
73662- (struct timespec __user *) &in,
73663- (struct timespec __user *) &out);
73664+ (struct timespec __force_user *) &in,
73665+ (struct timespec __force_user *) &out);
73666 set_fs(oldfs);
73667
73668 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
73669diff --git a/kernel/configs.c b/kernel/configs.c
73670index 42e8fa0..9e7406b 100644
73671--- a/kernel/configs.c
73672+++ b/kernel/configs.c
73673@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
73674 struct proc_dir_entry *entry;
73675
73676 /* create the current config file */
73677+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
73678+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
73679+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
73680+ &ikconfig_file_ops);
73681+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73682+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
73683+ &ikconfig_file_ops);
73684+#endif
73685+#else
73686 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
73687 &ikconfig_file_ops);
73688+#endif
73689+
73690 if (!entry)
73691 return -ENOMEM;
73692
73693diff --git a/kernel/cred.c b/kernel/cred.c
73694index e0573a4..3874e41 100644
73695--- a/kernel/cred.c
73696+++ b/kernel/cred.c
73697@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
73698 validate_creds(cred);
73699 alter_cred_subscribers(cred, -1);
73700 put_cred(cred);
73701+
73702+#ifdef CONFIG_GRKERNSEC_SETXID
73703+ cred = (struct cred *) tsk->delayed_cred;
73704+ if (cred != NULL) {
73705+ tsk->delayed_cred = NULL;
73706+ validate_creds(cred);
73707+ alter_cred_subscribers(cred, -1);
73708+ put_cred(cred);
73709+ }
73710+#endif
73711 }
73712
73713 /**
73714@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
73715 * Always returns 0 thus allowing this function to be tail-called at the end
73716 * of, say, sys_setgid().
73717 */
73718-int commit_creds(struct cred *new)
73719+static int __commit_creds(struct cred *new)
73720 {
73721 struct task_struct *task = current;
73722 const struct cred *old = task->real_cred;
73723@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
73724
73725 get_cred(new); /* we will require a ref for the subj creds too */
73726
73727+ gr_set_role_label(task, new->uid, new->gid);
73728+
73729 /* dumpability changes */
73730 if (!uid_eq(old->euid, new->euid) ||
73731 !gid_eq(old->egid, new->egid) ||
73732@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
73733 put_cred(old);
73734 return 0;
73735 }
73736+#ifdef CONFIG_GRKERNSEC_SETXID
73737+extern int set_user(struct cred *new);
73738+
73739+void gr_delayed_cred_worker(void)
73740+{
73741+ const struct cred *new = current->delayed_cred;
73742+ struct cred *ncred;
73743+
73744+ current->delayed_cred = NULL;
73745+
73746+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
73747+ // from doing get_cred on it when queueing this
73748+ put_cred(new);
73749+ return;
73750+ } else if (new == NULL)
73751+ return;
73752+
73753+ ncred = prepare_creds();
73754+ if (!ncred)
73755+ goto die;
73756+ // uids
73757+ ncred->uid = new->uid;
73758+ ncred->euid = new->euid;
73759+ ncred->suid = new->suid;
73760+ ncred->fsuid = new->fsuid;
73761+ // gids
73762+ ncred->gid = new->gid;
73763+ ncred->egid = new->egid;
73764+ ncred->sgid = new->sgid;
73765+ ncred->fsgid = new->fsgid;
73766+ // groups
73767+ if (set_groups(ncred, new->group_info) < 0) {
73768+ abort_creds(ncred);
73769+ goto die;
73770+ }
73771+ // caps
73772+ ncred->securebits = new->securebits;
73773+ ncred->cap_inheritable = new->cap_inheritable;
73774+ ncred->cap_permitted = new->cap_permitted;
73775+ ncred->cap_effective = new->cap_effective;
73776+ ncred->cap_bset = new->cap_bset;
73777+
73778+ if (set_user(ncred)) {
73779+ abort_creds(ncred);
73780+ goto die;
73781+ }
73782+
73783+ // from doing get_cred on it when queueing this
73784+ put_cred(new);
73785+
73786+ __commit_creds(ncred);
73787+ return;
73788+die:
73789+ // from doing get_cred on it when queueing this
73790+ put_cred(new);
73791+ do_group_exit(SIGKILL);
73792+}
73793+#endif
73794+
73795+int commit_creds(struct cred *new)
73796+{
73797+#ifdef CONFIG_GRKERNSEC_SETXID
73798+ int ret;
73799+ int schedule_it = 0;
73800+ struct task_struct *t;
73801+
73802+ /* we won't get called with tasklist_lock held for writing
73803+ and interrupts disabled as the cred struct in that case is
73804+ init_cred
73805+ */
73806+ if (grsec_enable_setxid && !current_is_single_threaded() &&
73807+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
73808+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
73809+ schedule_it = 1;
73810+ }
73811+ ret = __commit_creds(new);
73812+ if (schedule_it) {
73813+ rcu_read_lock();
73814+ read_lock(&tasklist_lock);
73815+ for (t = next_thread(current); t != current;
73816+ t = next_thread(t)) {
73817+ if (t->delayed_cred == NULL) {
73818+ t->delayed_cred = get_cred(new);
73819+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
73820+ set_tsk_need_resched(t);
73821+ }
73822+ }
73823+ read_unlock(&tasklist_lock);
73824+ rcu_read_unlock();
73825+ }
73826+ return ret;
73827+#else
73828+ return __commit_creds(new);
73829+#endif
73830+}
73831+
73832 EXPORT_SYMBOL(commit_creds);
73833
73834 /**
73835diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
73836index 9a61738..c5c8f3a 100644
73837--- a/kernel/debug/debug_core.c
73838+++ b/kernel/debug/debug_core.c
73839@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
73840 */
73841 static atomic_t masters_in_kgdb;
73842 static atomic_t slaves_in_kgdb;
73843-static atomic_t kgdb_break_tasklet_var;
73844+static atomic_unchecked_t kgdb_break_tasklet_var;
73845 atomic_t kgdb_setting_breakpoint;
73846
73847 struct task_struct *kgdb_usethread;
73848@@ -132,7 +132,7 @@ int kgdb_single_step;
73849 static pid_t kgdb_sstep_pid;
73850
73851 /* to keep track of the CPU which is doing the single stepping*/
73852-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73853+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73854
73855 /*
73856 * If you are debugging a problem where roundup (the collection of
73857@@ -540,7 +540,7 @@ return_normal:
73858 * kernel will only try for the value of sstep_tries before
73859 * giving up and continuing on.
73860 */
73861- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
73862+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
73863 (kgdb_info[cpu].task &&
73864 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
73865 atomic_set(&kgdb_active, -1);
73866@@ -634,8 +634,8 @@ cpu_master_loop:
73867 }
73868
73869 kgdb_restore:
73870- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
73871- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
73872+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
73873+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
73874 if (kgdb_info[sstep_cpu].task)
73875 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
73876 else
73877@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
73878 static void kgdb_tasklet_bpt(unsigned long ing)
73879 {
73880 kgdb_breakpoint();
73881- atomic_set(&kgdb_break_tasklet_var, 0);
73882+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
73883 }
73884
73885 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
73886
73887 void kgdb_schedule_breakpoint(void)
73888 {
73889- if (atomic_read(&kgdb_break_tasklet_var) ||
73890+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
73891 atomic_read(&kgdb_active) != -1 ||
73892 atomic_read(&kgdb_setting_breakpoint))
73893 return;
73894- atomic_inc(&kgdb_break_tasklet_var);
73895+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
73896 tasklet_schedule(&kgdb_tasklet_breakpoint);
73897 }
73898 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
73899diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
73900index 8875254..7cf4928 100644
73901--- a/kernel/debug/kdb/kdb_main.c
73902+++ b/kernel/debug/kdb/kdb_main.c
73903@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
73904 continue;
73905
73906 kdb_printf("%-20s%8u 0x%p ", mod->name,
73907- mod->core_size, (void *)mod);
73908+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
73909 #ifdef CONFIG_MODULE_UNLOAD
73910 kdb_printf("%4ld ", module_refcount(mod));
73911 #endif
73912@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
73913 kdb_printf(" (Loading)");
73914 else
73915 kdb_printf(" (Live)");
73916- kdb_printf(" 0x%p", mod->module_core);
73917+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
73918
73919 #ifdef CONFIG_MODULE_UNLOAD
73920 {
73921diff --git a/kernel/events/core.c b/kernel/events/core.c
73922index 7b6646a..3cb1135 100644
73923--- a/kernel/events/core.c
73924+++ b/kernel/events/core.c
73925@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
73926 return 0;
73927 }
73928
73929-static atomic64_t perf_event_id;
73930+static atomic64_unchecked_t perf_event_id;
73931
73932 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
73933 enum event_type_t event_type);
73934@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
73935
73936 static inline u64 perf_event_count(struct perf_event *event)
73937 {
73938- return local64_read(&event->count) + atomic64_read(&event->child_count);
73939+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
73940 }
73941
73942 static u64 perf_event_read(struct perf_event *event)
73943@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
73944 mutex_lock(&event->child_mutex);
73945 total += perf_event_read(event);
73946 *enabled += event->total_time_enabled +
73947- atomic64_read(&event->child_total_time_enabled);
73948+ atomic64_read_unchecked(&event->child_total_time_enabled);
73949 *running += event->total_time_running +
73950- atomic64_read(&event->child_total_time_running);
73951+ atomic64_read_unchecked(&event->child_total_time_running);
73952
73953 list_for_each_entry(child, &event->child_list, child_list) {
73954 total += perf_event_read(child);
73955@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
73956 userpg->offset -= local64_read(&event->hw.prev_count);
73957
73958 userpg->time_enabled = enabled +
73959- atomic64_read(&event->child_total_time_enabled);
73960+ atomic64_read_unchecked(&event->child_total_time_enabled);
73961
73962 userpg->time_running = running +
73963- atomic64_read(&event->child_total_time_running);
73964+ atomic64_read_unchecked(&event->child_total_time_running);
73965
73966 arch_perf_update_userpage(userpg, now);
73967
73968@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
73969 values[n++] = perf_event_count(event);
73970 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
73971 values[n++] = enabled +
73972- atomic64_read(&event->child_total_time_enabled);
73973+ atomic64_read_unchecked(&event->child_total_time_enabled);
73974 }
73975 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
73976 values[n++] = running +
73977- atomic64_read(&event->child_total_time_running);
73978+ atomic64_read_unchecked(&event->child_total_time_running);
73979 }
73980 if (read_format & PERF_FORMAT_ID)
73981 values[n++] = primary_event_id(event);
73982@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
73983 * need to add enough zero bytes after the string to handle
73984 * the 64bit alignment we do later.
73985 */
73986- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
73987+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
73988 if (!buf) {
73989 name = strncpy(tmp, "//enomem", sizeof(tmp));
73990 goto got_name;
73991 }
73992- name = d_path(&file->f_path, buf, PATH_MAX);
73993+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
73994 if (IS_ERR(name)) {
73995 name = strncpy(tmp, "//toolong", sizeof(tmp));
73996 goto got_name;
73997@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
73998 event->parent = parent_event;
73999
74000 event->ns = get_pid_ns(task_active_pid_ns(current));
74001- event->id = atomic64_inc_return(&perf_event_id);
74002+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
74003
74004 event->state = PERF_EVENT_STATE_INACTIVE;
74005
74006@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
74007 /*
74008 * Add back the child's count to the parent's count:
74009 */
74010- atomic64_add(child_val, &parent_event->child_count);
74011- atomic64_add(child_event->total_time_enabled,
74012+ atomic64_add_unchecked(child_val, &parent_event->child_count);
74013+ atomic64_add_unchecked(child_event->total_time_enabled,
74014 &parent_event->child_total_time_enabled);
74015- atomic64_add(child_event->total_time_running,
74016+ atomic64_add_unchecked(child_event->total_time_running,
74017 &parent_event->child_total_time_running);
74018
74019 /*
74020diff --git a/kernel/exit.c b/kernel/exit.c
74021index b4df219..f13c02d 100644
74022--- a/kernel/exit.c
74023+++ b/kernel/exit.c
74024@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
74025 struct task_struct *leader;
74026 int zap_leader;
74027 repeat:
74028+#ifdef CONFIG_NET
74029+ gr_del_task_from_ip_table(p);
74030+#endif
74031+
74032 /* don't need to get the RCU readlock here - the process is dead and
74033 * can't be modifying its own credentials. But shut RCU-lockdep up */
74034 rcu_read_lock();
74035@@ -338,7 +342,7 @@ int allow_signal(int sig)
74036 * know it'll be handled, so that they don't get converted to
74037 * SIGKILL or just silently dropped.
74038 */
74039- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
74040+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
74041 recalc_sigpending();
74042 spin_unlock_irq(&current->sighand->siglock);
74043 return 0;
74044@@ -708,6 +712,8 @@ void do_exit(long code)
74045 struct task_struct *tsk = current;
74046 int group_dead;
74047
74048+ set_fs(USER_DS);
74049+
74050 profile_task_exit(tsk);
74051
74052 WARN_ON(blk_needs_flush_plug(tsk));
74053@@ -724,7 +730,6 @@ void do_exit(long code)
74054 * mm_release()->clear_child_tid() from writing to a user-controlled
74055 * kernel address.
74056 */
74057- set_fs(USER_DS);
74058
74059 ptrace_event(PTRACE_EVENT_EXIT, code);
74060
74061@@ -783,6 +788,9 @@ void do_exit(long code)
74062 tsk->exit_code = code;
74063 taskstats_exit(tsk, group_dead);
74064
74065+ gr_acl_handle_psacct(tsk, code);
74066+ gr_acl_handle_exit();
74067+
74068 exit_mm(tsk);
74069
74070 if (group_dead)
74071@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
74072 * Take down every thread in the group. This is called by fatal signals
74073 * as well as by sys_exit_group (below).
74074 */
74075-void
74076+__noreturn void
74077 do_group_exit(int exit_code)
74078 {
74079 struct signal_struct *sig = current->signal;
74080diff --git a/kernel/fork.c b/kernel/fork.c
74081index 5630e52..0cee608 100644
74082--- a/kernel/fork.c
74083+++ b/kernel/fork.c
74084@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
74085 *stackend = STACK_END_MAGIC; /* for overflow detection */
74086
74087 #ifdef CONFIG_CC_STACKPROTECTOR
74088- tsk->stack_canary = get_random_int();
74089+ tsk->stack_canary = pax_get_random_long();
74090 #endif
74091
74092 /*
74093@@ -344,13 +344,81 @@ free_tsk:
74094 }
74095
74096 #ifdef CONFIG_MMU
74097+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
74098+{
74099+ struct vm_area_struct *tmp;
74100+ unsigned long charge;
74101+ struct mempolicy *pol;
74102+ struct file *file;
74103+
74104+ charge = 0;
74105+ if (mpnt->vm_flags & VM_ACCOUNT) {
74106+ unsigned long len = vma_pages(mpnt);
74107+
74108+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74109+ goto fail_nomem;
74110+ charge = len;
74111+ }
74112+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74113+ if (!tmp)
74114+ goto fail_nomem;
74115+ *tmp = *mpnt;
74116+ tmp->vm_mm = mm;
74117+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
74118+ pol = mpol_dup(vma_policy(mpnt));
74119+ if (IS_ERR(pol))
74120+ goto fail_nomem_policy;
74121+ vma_set_policy(tmp, pol);
74122+ if (anon_vma_fork(tmp, mpnt))
74123+ goto fail_nomem_anon_vma_fork;
74124+ tmp->vm_flags &= ~VM_LOCKED;
74125+ tmp->vm_next = tmp->vm_prev = NULL;
74126+ tmp->vm_mirror = NULL;
74127+ file = tmp->vm_file;
74128+ if (file) {
74129+ struct inode *inode = file->f_path.dentry->d_inode;
74130+ struct address_space *mapping = file->f_mapping;
74131+
74132+ get_file(file);
74133+ if (tmp->vm_flags & VM_DENYWRITE)
74134+ atomic_dec(&inode->i_writecount);
74135+ mutex_lock(&mapping->i_mmap_mutex);
74136+ if (tmp->vm_flags & VM_SHARED)
74137+ mapping->i_mmap_writable++;
74138+ flush_dcache_mmap_lock(mapping);
74139+ /* insert tmp into the share list, just after mpnt */
74140+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74141+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
74142+ else
74143+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
74144+ flush_dcache_mmap_unlock(mapping);
74145+ mutex_unlock(&mapping->i_mmap_mutex);
74146+ }
74147+
74148+ /*
74149+ * Clear hugetlb-related page reserves for children. This only
74150+ * affects MAP_PRIVATE mappings. Faults generated by the child
74151+ * are not guaranteed to succeed, even if read-only
74152+ */
74153+ if (is_vm_hugetlb_page(tmp))
74154+ reset_vma_resv_huge_pages(tmp);
74155+
74156+ return tmp;
74157+
74158+fail_nomem_anon_vma_fork:
74159+ mpol_put(pol);
74160+fail_nomem_policy:
74161+ kmem_cache_free(vm_area_cachep, tmp);
74162+fail_nomem:
74163+ vm_unacct_memory(charge);
74164+ return NULL;
74165+}
74166+
74167 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74168 {
74169 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
74170 struct rb_node **rb_link, *rb_parent;
74171 int retval;
74172- unsigned long charge;
74173- struct mempolicy *pol;
74174
74175 uprobe_start_dup_mmap();
74176 down_write(&oldmm->mmap_sem);
74177@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74178 mm->locked_vm = 0;
74179 mm->mmap = NULL;
74180 mm->mmap_cache = NULL;
74181- mm->free_area_cache = oldmm->mmap_base;
74182- mm->cached_hole_size = ~0UL;
74183+ mm->free_area_cache = oldmm->free_area_cache;
74184+ mm->cached_hole_size = oldmm->cached_hole_size;
74185 mm->map_count = 0;
74186 cpumask_clear(mm_cpumask(mm));
74187 mm->mm_rb = RB_ROOT;
74188@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74189
74190 prev = NULL;
74191 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
74192- struct file *file;
74193-
74194 if (mpnt->vm_flags & VM_DONTCOPY) {
74195 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
74196 -vma_pages(mpnt));
74197 continue;
74198 }
74199- charge = 0;
74200- if (mpnt->vm_flags & VM_ACCOUNT) {
74201- unsigned long len = vma_pages(mpnt);
74202-
74203- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74204- goto fail_nomem;
74205- charge = len;
74206- }
74207- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74208- if (!tmp)
74209- goto fail_nomem;
74210- *tmp = *mpnt;
74211- INIT_LIST_HEAD(&tmp->anon_vma_chain);
74212- pol = mpol_dup(vma_policy(mpnt));
74213- retval = PTR_ERR(pol);
74214- if (IS_ERR(pol))
74215- goto fail_nomem_policy;
74216- vma_set_policy(tmp, pol);
74217- tmp->vm_mm = mm;
74218- if (anon_vma_fork(tmp, mpnt))
74219- goto fail_nomem_anon_vma_fork;
74220- tmp->vm_flags &= ~VM_LOCKED;
74221- tmp->vm_next = tmp->vm_prev = NULL;
74222- file = tmp->vm_file;
74223- if (file) {
74224- struct inode *inode = file->f_path.dentry->d_inode;
74225- struct address_space *mapping = file->f_mapping;
74226-
74227- get_file(file);
74228- if (tmp->vm_flags & VM_DENYWRITE)
74229- atomic_dec(&inode->i_writecount);
74230- mutex_lock(&mapping->i_mmap_mutex);
74231- if (tmp->vm_flags & VM_SHARED)
74232- mapping->i_mmap_writable++;
74233- flush_dcache_mmap_lock(mapping);
74234- /* insert tmp into the share list, just after mpnt */
74235- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74236- vma_nonlinear_insert(tmp,
74237- &mapping->i_mmap_nonlinear);
74238- else
74239- vma_interval_tree_insert_after(tmp, mpnt,
74240- &mapping->i_mmap);
74241- flush_dcache_mmap_unlock(mapping);
74242- mutex_unlock(&mapping->i_mmap_mutex);
74243+ tmp = dup_vma(mm, oldmm, mpnt);
74244+ if (!tmp) {
74245+ retval = -ENOMEM;
74246+ goto out;
74247 }
74248
74249 /*
74250@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74251 if (retval)
74252 goto out;
74253 }
74254+
74255+#ifdef CONFIG_PAX_SEGMEXEC
74256+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
74257+ struct vm_area_struct *mpnt_m;
74258+
74259+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
74260+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
74261+
74262+ if (!mpnt->vm_mirror)
74263+ continue;
74264+
74265+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
74266+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
74267+ mpnt->vm_mirror = mpnt_m;
74268+ } else {
74269+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
74270+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
74271+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
74272+ mpnt->vm_mirror->vm_mirror = mpnt;
74273+ }
74274+ }
74275+ BUG_ON(mpnt_m);
74276+ }
74277+#endif
74278+
74279 /* a new mm has just been created */
74280 arch_dup_mmap(oldmm, mm);
74281 retval = 0;
74282@@ -472,14 +523,6 @@ out:
74283 up_write(&oldmm->mmap_sem);
74284 uprobe_end_dup_mmap();
74285 return retval;
74286-fail_nomem_anon_vma_fork:
74287- mpol_put(pol);
74288-fail_nomem_policy:
74289- kmem_cache_free(vm_area_cachep, tmp);
74290-fail_nomem:
74291- retval = -ENOMEM;
74292- vm_unacct_memory(charge);
74293- goto out;
74294 }
74295
74296 static inline int mm_alloc_pgd(struct mm_struct *mm)
74297@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
74298 return ERR_PTR(err);
74299
74300 mm = get_task_mm(task);
74301- if (mm && mm != current->mm &&
74302- !ptrace_may_access(task, mode)) {
74303+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
74304+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
74305 mmput(mm);
74306 mm = ERR_PTR(-EACCES);
74307 }
74308@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
74309 spin_unlock(&fs->lock);
74310 return -EAGAIN;
74311 }
74312- fs->users++;
74313+ atomic_inc(&fs->users);
74314 spin_unlock(&fs->lock);
74315 return 0;
74316 }
74317 tsk->fs = copy_fs_struct(fs);
74318 if (!tsk->fs)
74319 return -ENOMEM;
74320+ /* Carry through gr_chroot_dentry and is_chrooted instead
74321+ of recomputing it here. Already copied when the task struct
74322+ is duplicated. This allows pivot_root to not be treated as
74323+ a chroot
74324+ */
74325+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
74326+
74327 return 0;
74328 }
74329
74330@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
74331 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
74332 #endif
74333 retval = -EAGAIN;
74334+
74335+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
74336+
74337 if (atomic_read(&p->real_cred->user->processes) >=
74338 task_rlimit(p, RLIMIT_NPROC)) {
74339 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
74340@@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
74341 goto bad_fork_free_pid;
74342 }
74343
74344+ /* synchronizes with gr_set_acls()
74345+ we need to call this past the point of no return for fork()
74346+ */
74347+ gr_copy_label(p);
74348+
74349 if (clone_flags & CLONE_THREAD) {
74350 current->signal->nr_threads++;
74351 atomic_inc(&current->signal->live);
74352@@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
74353 bad_fork_free:
74354 free_task(p);
74355 fork_out:
74356+ gr_log_forkfail(retval);
74357+
74358 return ERR_PTR(retval);
74359 }
74360
74361@@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
74362 return -EINVAL;
74363 }
74364
74365+#ifdef CONFIG_GRKERNSEC
74366+ if (clone_flags & CLONE_NEWUSER) {
74367+ /*
74368+ * This doesn't really inspire confidence:
74369+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
74370+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
74371+ * Increases kernel attack surface in areas developers
74372+ * previously cared little about ("low importance due
74373+ * to requiring "root" capability")
74374+ * To be removed when this code receives *proper* review
74375+ */
74376+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
74377+ !capable(CAP_SETGID))
74378+ return -EPERM;
74379+ }
74380+#endif
74381+
74382 /*
74383 * Determine whether and which event to report to ptracer. When
74384 * called from kernel_thread or CLONE_UNTRACED is explicitly
74385@@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
74386 if (clone_flags & CLONE_PARENT_SETTID)
74387 put_user(nr, parent_tidptr);
74388
74389+ gr_handle_brute_check();
74390+
74391 if (clone_flags & CLONE_VFORK) {
74392 p->vfork_done = &vfork;
74393 init_completion(&vfork);
74394@@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
74395 return 0;
74396
74397 /* don't need lock here; in the worst case we'll do useless copy */
74398- if (fs->users == 1)
74399+ if (atomic_read(&fs->users) == 1)
74400 return 0;
74401
74402 *new_fsp = copy_fs_struct(fs);
74403@@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
74404 fs = current->fs;
74405 spin_lock(&fs->lock);
74406 current->fs = new_fs;
74407- if (--fs->users)
74408+ gr_set_chroot_entries(current, &current->fs->root);
74409+ if (atomic_dec_return(&fs->users))
74410 new_fs = NULL;
74411 else
74412 new_fs = fs;
74413diff --git a/kernel/futex.c b/kernel/futex.c
74414index 8879430..31696f1 100644
74415--- a/kernel/futex.c
74416+++ b/kernel/futex.c
74417@@ -54,6 +54,7 @@
74418 #include <linux/mount.h>
74419 #include <linux/pagemap.h>
74420 #include <linux/syscalls.h>
74421+#include <linux/ptrace.h>
74422 #include <linux/signal.h>
74423 #include <linux/export.h>
74424 #include <linux/magic.h>
74425@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
74426 struct page *page, *page_head;
74427 int err, ro = 0;
74428
74429+#ifdef CONFIG_PAX_SEGMEXEC
74430+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
74431+ return -EFAULT;
74432+#endif
74433+
74434 /*
74435 * The futex address must be "naturally" aligned.
74436 */
74437@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
74438 {
74439 u32 curval;
74440 int i;
74441+ mm_segment_t oldfs;
74442
74443 /*
74444 * This will fail and we want it. Some arch implementations do
74445@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
74446 * implementation, the non-functional ones will return
74447 * -ENOSYS.
74448 */
74449+ oldfs = get_fs();
74450+ set_fs(USER_DS);
74451 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
74452 futex_cmpxchg_enabled = 1;
74453+ set_fs(oldfs);
74454
74455 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
74456 plist_head_init(&futex_queues[i].chain);
74457diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
74458index 9b22d03..6295b62 100644
74459--- a/kernel/gcov/base.c
74460+++ b/kernel/gcov/base.c
74461@@ -102,11 +102,6 @@ void gcov_enable_events(void)
74462 }
74463
74464 #ifdef CONFIG_MODULES
74465-static inline int within(void *addr, void *start, unsigned long size)
74466-{
74467- return ((addr >= start) && (addr < start + size));
74468-}
74469-
74470 /* Update list and generate events when modules are unloaded. */
74471 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
74472 void *data)
74473@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
74474 prev = NULL;
74475 /* Remove entries located in module from linked list. */
74476 for (info = gcov_info_head; info; info = info->next) {
74477- if (within(info, mod->module_core, mod->core_size)) {
74478+ if (within_module_core_rw((unsigned long)info, mod)) {
74479 if (prev)
74480 prev->next = info->next;
74481 else
74482diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
74483index cdd5607..c3fc919 100644
74484--- a/kernel/hrtimer.c
74485+++ b/kernel/hrtimer.c
74486@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
74487 local_irq_restore(flags);
74488 }
74489
74490-static void run_hrtimer_softirq(struct softirq_action *h)
74491+static void run_hrtimer_softirq(void)
74492 {
74493 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
74494
74495@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
74496 return NOTIFY_OK;
74497 }
74498
74499-static struct notifier_block __cpuinitdata hrtimers_nb = {
74500+static struct notifier_block hrtimers_nb = {
74501 .notifier_call = hrtimer_cpu_notify,
74502 };
74503
74504diff --git a/kernel/jump_label.c b/kernel/jump_label.c
74505index 60f48fa..7f3a770 100644
74506--- a/kernel/jump_label.c
74507+++ b/kernel/jump_label.c
74508@@ -13,6 +13,7 @@
74509 #include <linux/sort.h>
74510 #include <linux/err.h>
74511 #include <linux/static_key.h>
74512+#include <linux/mm.h>
74513
74514 #ifdef HAVE_JUMP_LABEL
74515
74516@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
74517
74518 size = (((unsigned long)stop - (unsigned long)start)
74519 / sizeof(struct jump_entry));
74520+ pax_open_kernel();
74521 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
74522+ pax_close_kernel();
74523 }
74524
74525 static void jump_label_update(struct static_key *key, int enable);
74526@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
74527 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
74528 struct jump_entry *iter;
74529
74530+ pax_open_kernel();
74531 for (iter = iter_start; iter < iter_stop; iter++) {
74532 if (within_module_init(iter->code, mod))
74533 iter->code = 0;
74534 }
74535+ pax_close_kernel();
74536 }
74537
74538 static int
74539diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
74540index 2169fee..706ccca 100644
74541--- a/kernel/kallsyms.c
74542+++ b/kernel/kallsyms.c
74543@@ -11,6 +11,9 @@
74544 * Changed the compression method from stem compression to "table lookup"
74545 * compression (see scripts/kallsyms.c for a more complete description)
74546 */
74547+#ifdef CONFIG_GRKERNSEC_HIDESYM
74548+#define __INCLUDED_BY_HIDESYM 1
74549+#endif
74550 #include <linux/kallsyms.h>
74551 #include <linux/module.h>
74552 #include <linux/init.h>
74553@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
74554
74555 static inline int is_kernel_inittext(unsigned long addr)
74556 {
74557+ if (system_state != SYSTEM_BOOTING)
74558+ return 0;
74559+
74560 if (addr >= (unsigned long)_sinittext
74561 && addr <= (unsigned long)_einittext)
74562 return 1;
74563 return 0;
74564 }
74565
74566+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74567+#ifdef CONFIG_MODULES
74568+static inline int is_module_text(unsigned long addr)
74569+{
74570+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
74571+ return 1;
74572+
74573+ addr = ktla_ktva(addr);
74574+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
74575+}
74576+#else
74577+static inline int is_module_text(unsigned long addr)
74578+{
74579+ return 0;
74580+}
74581+#endif
74582+#endif
74583+
74584 static inline int is_kernel_text(unsigned long addr)
74585 {
74586 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
74587@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
74588
74589 static inline int is_kernel(unsigned long addr)
74590 {
74591+
74592+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74593+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
74594+ return 1;
74595+
74596+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
74597+#else
74598 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
74599+#endif
74600+
74601 return 1;
74602 return in_gate_area_no_mm(addr);
74603 }
74604
74605 static int is_ksym_addr(unsigned long addr)
74606 {
74607+
74608+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74609+ if (is_module_text(addr))
74610+ return 0;
74611+#endif
74612+
74613 if (all_var)
74614 return is_kernel(addr);
74615
74616@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
74617
74618 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
74619 {
74620- iter->name[0] = '\0';
74621 iter->nameoff = get_symbol_offset(new_pos);
74622 iter->pos = new_pos;
74623 }
74624@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
74625 {
74626 struct kallsym_iter *iter = m->private;
74627
74628+#ifdef CONFIG_GRKERNSEC_HIDESYM
74629+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
74630+ return 0;
74631+#endif
74632+
74633 /* Some debugging symbols have no name. Ignore them. */
74634 if (!iter->name[0])
74635 return 0;
74636@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
74637 */
74638 type = iter->exported ? toupper(iter->type) :
74639 tolower(iter->type);
74640+
74641 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
74642 type, iter->name, iter->module_name);
74643 } else
74644@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
74645 struct kallsym_iter *iter;
74646 int ret;
74647
74648- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
74649+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
74650 if (!iter)
74651 return -ENOMEM;
74652 reset_iter(iter, 0);
74653diff --git a/kernel/kcmp.c b/kernel/kcmp.c
74654index e30ac0f..3528cac 100644
74655--- a/kernel/kcmp.c
74656+++ b/kernel/kcmp.c
74657@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
74658 struct task_struct *task1, *task2;
74659 int ret;
74660
74661+#ifdef CONFIG_GRKERNSEC
74662+ return -ENOSYS;
74663+#endif
74664+
74665 rcu_read_lock();
74666
74667 /*
74668diff --git a/kernel/kexec.c b/kernel/kexec.c
74669index 5e4bd78..00c5b91 100644
74670--- a/kernel/kexec.c
74671+++ b/kernel/kexec.c
74672@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
74673 unsigned long flags)
74674 {
74675 struct compat_kexec_segment in;
74676- struct kexec_segment out, __user *ksegments;
74677+ struct kexec_segment out;
74678+ struct kexec_segment __user *ksegments;
74679 unsigned long i, result;
74680
74681 /* Don't allow clients that don't understand the native
74682diff --git a/kernel/kmod.c b/kernel/kmod.c
74683index 0023a87..9c0c068 100644
74684--- a/kernel/kmod.c
74685+++ b/kernel/kmod.c
74686@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
74687 kfree(info->argv);
74688 }
74689
74690-static int call_modprobe(char *module_name, int wait)
74691+static int call_modprobe(char *module_name, char *module_param, int wait)
74692 {
74693 static char *envp[] = {
74694 "HOME=/",
74695@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
74696 NULL
74697 };
74698
74699- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
74700+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
74701 if (!argv)
74702 goto out;
74703
74704@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
74705 argv[1] = "-q";
74706 argv[2] = "--";
74707 argv[3] = module_name; /* check free_modprobe_argv() */
74708- argv[4] = NULL;
74709+ argv[4] = module_param;
74710+ argv[5] = NULL;
74711
74712 return call_usermodehelper_fns(modprobe_path, argv, envp,
74713 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
74714@@ -120,9 +121,8 @@ out:
74715 * If module auto-loading support is disabled then this function
74716 * becomes a no-operation.
74717 */
74718-int __request_module(bool wait, const char *fmt, ...)
74719+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
74720 {
74721- va_list args;
74722 char module_name[MODULE_NAME_LEN];
74723 unsigned int max_modprobes;
74724 int ret;
74725@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
74726 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
74727 static int kmod_loop_msg;
74728
74729- va_start(args, fmt);
74730- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
74731- va_end(args);
74732+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
74733 if (ret >= MODULE_NAME_LEN)
74734 return -ENAMETOOLONG;
74735
74736@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
74737 if (ret)
74738 return ret;
74739
74740+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74741+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74742+ /* hack to workaround consolekit/udisks stupidity */
74743+ read_lock(&tasklist_lock);
74744+ if (!strcmp(current->comm, "mount") &&
74745+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
74746+ read_unlock(&tasklist_lock);
74747+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
74748+ return -EPERM;
74749+ }
74750+ read_unlock(&tasklist_lock);
74751+ }
74752+#endif
74753+
74754 /* If modprobe needs a service that is in a module, we get a recursive
74755 * loop. Limit the number of running kmod threads to max_threads/2 or
74756 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
74757@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
74758
74759 trace_module_request(module_name, wait, _RET_IP_);
74760
74761- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74762+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74763
74764 atomic_dec(&kmod_concurrent);
74765 return ret;
74766 }
74767+
74768+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
74769+{
74770+ va_list args;
74771+ int ret;
74772+
74773+ va_start(args, fmt);
74774+ ret = ____request_module(wait, module_param, fmt, args);
74775+ va_end(args);
74776+
74777+ return ret;
74778+}
74779+
74780+int __request_module(bool wait, const char *fmt, ...)
74781+{
74782+ va_list args;
74783+ int ret;
74784+
74785+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74786+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74787+ char module_param[MODULE_NAME_LEN];
74788+
74789+ memset(module_param, 0, sizeof(module_param));
74790+
74791+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
74792+
74793+ va_start(args, fmt);
74794+ ret = ____request_module(wait, module_param, fmt, args);
74795+ va_end(args);
74796+
74797+ return ret;
74798+ }
74799+#endif
74800+
74801+ va_start(args, fmt);
74802+ ret = ____request_module(wait, NULL, fmt, args);
74803+ va_end(args);
74804+
74805+ return ret;
74806+}
74807+
74808 EXPORT_SYMBOL(__request_module);
74809 #endif /* CONFIG_MODULES */
74810
74811@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
74812 *
74813 * Thus the __user pointer cast is valid here.
74814 */
74815- sys_wait4(pid, (int __user *)&ret, 0, NULL);
74816+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
74817
74818 /*
74819 * If ret is 0, either ____call_usermodehelper failed and the
74820@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
74821 static int proc_cap_handler(struct ctl_table *table, int write,
74822 void __user *buffer, size_t *lenp, loff_t *ppos)
74823 {
74824- struct ctl_table t;
74825+ ctl_table_no_const t;
74826 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
74827 kernel_cap_t new_cap;
74828 int err, i;
74829diff --git a/kernel/kprobes.c b/kernel/kprobes.c
74830index 098f396..fe85ff1 100644
74831--- a/kernel/kprobes.c
74832+++ b/kernel/kprobes.c
74833@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
74834 * kernel image and loaded module images reside. This is required
74835 * so x86_64 can correctly handle the %rip-relative fixups.
74836 */
74837- kip->insns = module_alloc(PAGE_SIZE);
74838+ kip->insns = module_alloc_exec(PAGE_SIZE);
74839 if (!kip->insns) {
74840 kfree(kip);
74841 return NULL;
74842@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
74843 */
74844 if (!list_is_singular(&kip->list)) {
74845 list_del(&kip->list);
74846- module_free(NULL, kip->insns);
74847+ module_free_exec(NULL, kip->insns);
74848 kfree(kip);
74849 }
74850 return 1;
74851@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
74852 {
74853 int i, err = 0;
74854 unsigned long offset = 0, size = 0;
74855- char *modname, namebuf[128];
74856+ char *modname, namebuf[KSYM_NAME_LEN];
74857 const char *symbol_name;
74858 void *addr;
74859 struct kprobe_blackpoint *kb;
74860@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
74861 kprobe_type = "k";
74862
74863 if (sym)
74864- seq_printf(pi, "%p %s %s+0x%x %s ",
74865+ seq_printf(pi, "%pK %s %s+0x%x %s ",
74866 p->addr, kprobe_type, sym, offset,
74867 (modname ? modname : " "));
74868 else
74869- seq_printf(pi, "%p %s %p ",
74870+ seq_printf(pi, "%pK %s %pK ",
74871 p->addr, kprobe_type, p->addr);
74872
74873 if (!pp)
74874@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
74875 const char *sym = NULL;
74876 unsigned int i = *(loff_t *) v;
74877 unsigned long offset = 0;
74878- char *modname, namebuf[128];
74879+ char *modname, namebuf[KSYM_NAME_LEN];
74880
74881 head = &kprobe_table[i];
74882 preempt_disable();
74883diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
74884index 6ada93c..dce7d5d 100644
74885--- a/kernel/ksysfs.c
74886+++ b/kernel/ksysfs.c
74887@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
74888 {
74889 if (count+1 > UEVENT_HELPER_PATH_LEN)
74890 return -ENOENT;
74891+ if (!capable(CAP_SYS_ADMIN))
74892+ return -EPERM;
74893 memcpy(uevent_helper, buf, count);
74894 uevent_helper[count] = '\0';
74895 if (count && uevent_helper[count-1] == '\n')
74896@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
74897 return count;
74898 }
74899
74900-static struct bin_attribute notes_attr = {
74901+static bin_attribute_no_const notes_attr __read_only = {
74902 .attr = {
74903 .name = "notes",
74904 .mode = S_IRUGO,
74905diff --git a/kernel/lockdep.c b/kernel/lockdep.c
74906index 7981e5b..7f2105c 100644
74907--- a/kernel/lockdep.c
74908+++ b/kernel/lockdep.c
74909@@ -590,6 +590,10 @@ static int static_obj(void *obj)
74910 end = (unsigned long) &_end,
74911 addr = (unsigned long) obj;
74912
74913+#ifdef CONFIG_PAX_KERNEXEC
74914+ start = ktla_ktva(start);
74915+#endif
74916+
74917 /*
74918 * static variable?
74919 */
74920@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
74921 if (!static_obj(lock->key)) {
74922 debug_locks_off();
74923 printk("INFO: trying to register non-static key.\n");
74924+ printk("lock:%pS key:%pS.\n", lock, lock->key);
74925 printk("the code is fine but needs lockdep annotation.\n");
74926 printk("turning off the locking correctness validator.\n");
74927 dump_stack();
74928@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
74929 if (!class)
74930 return 0;
74931 }
74932- atomic_inc((atomic_t *)&class->ops);
74933+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
74934 if (very_verbose(class)) {
74935 printk("\nacquire class [%p] %s", class->key, class->name);
74936 if (class->name_version > 1)
74937diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
74938index b2c71c5..7b88d63 100644
74939--- a/kernel/lockdep_proc.c
74940+++ b/kernel/lockdep_proc.c
74941@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
74942 return 0;
74943 }
74944
74945- seq_printf(m, "%p", class->key);
74946+ seq_printf(m, "%pK", class->key);
74947 #ifdef CONFIG_DEBUG_LOCKDEP
74948 seq_printf(m, " OPS:%8ld", class->ops);
74949 #endif
74950@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
74951
74952 list_for_each_entry(entry, &class->locks_after, entry) {
74953 if (entry->distance == 1) {
74954- seq_printf(m, " -> [%p] ", entry->class->key);
74955+ seq_printf(m, " -> [%pK] ", entry->class->key);
74956 print_name(m, entry->class);
74957 seq_puts(m, "\n");
74958 }
74959@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
74960 if (!class->key)
74961 continue;
74962
74963- seq_printf(m, "[%p] ", class->key);
74964+ seq_printf(m, "[%pK] ", class->key);
74965 print_name(m, class);
74966 seq_puts(m, "\n");
74967 }
74968@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74969 if (!i)
74970 seq_line(m, '-', 40-namelen, namelen);
74971
74972- snprintf(ip, sizeof(ip), "[<%p>]",
74973+ snprintf(ip, sizeof(ip), "[<%pK>]",
74974 (void *)class->contention_point[i]);
74975 seq_printf(m, "%40s %14lu %29s %pS\n",
74976 name, stats->contention_point[i],
74977@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74978 if (!i)
74979 seq_line(m, '-', 40-namelen, namelen);
74980
74981- snprintf(ip, sizeof(ip), "[<%p>]",
74982+ snprintf(ip, sizeof(ip), "[<%pK>]",
74983 (void *)class->contending_point[i]);
74984 seq_printf(m, "%40s %14lu %29s %pS\n",
74985 name, stats->contending_point[i],
74986diff --git a/kernel/module.c b/kernel/module.c
74987index eab0827..f488603 100644
74988--- a/kernel/module.c
74989+++ b/kernel/module.c
74990@@ -61,6 +61,7 @@
74991 #include <linux/pfn.h>
74992 #include <linux/bsearch.h>
74993 #include <linux/fips.h>
74994+#include <linux/grsecurity.h>
74995 #include <uapi/linux/module.h>
74996 #include "module-internal.h"
74997
74998@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
74999
75000 /* Bounds of module allocation, for speeding __module_address.
75001 * Protected by module_mutex. */
75002-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
75003+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
75004+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
75005
75006 int register_module_notifier(struct notifier_block * nb)
75007 {
75008@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75009 return true;
75010
75011 list_for_each_entry_rcu(mod, &modules, list) {
75012- struct symsearch arr[] = {
75013+ struct symsearch modarr[] = {
75014 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
75015 NOT_GPL_ONLY, false },
75016 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
75017@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75018 if (mod->state == MODULE_STATE_UNFORMED)
75019 continue;
75020
75021- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
75022+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
75023 return true;
75024 }
75025 return false;
75026@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
75027 static int percpu_modalloc(struct module *mod,
75028 unsigned long size, unsigned long align)
75029 {
75030- if (align > PAGE_SIZE) {
75031+ if (align-1 >= PAGE_SIZE) {
75032 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
75033 mod->name, align, PAGE_SIZE);
75034 align = PAGE_SIZE;
75035@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
75036 static ssize_t show_coresize(struct module_attribute *mattr,
75037 struct module_kobject *mk, char *buffer)
75038 {
75039- return sprintf(buffer, "%u\n", mk->mod->core_size);
75040+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
75041 }
75042
75043 static struct module_attribute modinfo_coresize =
75044@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
75045 static ssize_t show_initsize(struct module_attribute *mattr,
75046 struct module_kobject *mk, char *buffer)
75047 {
75048- return sprintf(buffer, "%u\n", mk->mod->init_size);
75049+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
75050 }
75051
75052 static struct module_attribute modinfo_initsize =
75053@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
75054 */
75055 #ifdef CONFIG_SYSFS
75056
75057-#ifdef CONFIG_KALLSYMS
75058+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
75059 static inline bool sect_empty(const Elf_Shdr *sect)
75060 {
75061 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
75062@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
75063 {
75064 unsigned int notes, loaded, i;
75065 struct module_notes_attrs *notes_attrs;
75066- struct bin_attribute *nattr;
75067+ bin_attribute_no_const *nattr;
75068
75069 /* failed to create section attributes, so can't create notes */
75070 if (!mod->sect_attrs)
75071@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
75072 static int module_add_modinfo_attrs(struct module *mod)
75073 {
75074 struct module_attribute *attr;
75075- struct module_attribute *temp_attr;
75076+ module_attribute_no_const *temp_attr;
75077 int error = 0;
75078 int i;
75079
75080@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
75081
75082 static void unset_module_core_ro_nx(struct module *mod)
75083 {
75084- set_page_attributes(mod->module_core + mod->core_text_size,
75085- mod->module_core + mod->core_size,
75086+ set_page_attributes(mod->module_core_rw,
75087+ mod->module_core_rw + mod->core_size_rw,
75088 set_memory_x);
75089- set_page_attributes(mod->module_core,
75090- mod->module_core + mod->core_ro_size,
75091+ set_page_attributes(mod->module_core_rx,
75092+ mod->module_core_rx + mod->core_size_rx,
75093 set_memory_rw);
75094 }
75095
75096 static void unset_module_init_ro_nx(struct module *mod)
75097 {
75098- set_page_attributes(mod->module_init + mod->init_text_size,
75099- mod->module_init + mod->init_size,
75100+ set_page_attributes(mod->module_init_rw,
75101+ mod->module_init_rw + mod->init_size_rw,
75102 set_memory_x);
75103- set_page_attributes(mod->module_init,
75104- mod->module_init + mod->init_ro_size,
75105+ set_page_attributes(mod->module_init_rx,
75106+ mod->module_init_rx + mod->init_size_rx,
75107 set_memory_rw);
75108 }
75109
75110@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
75111 list_for_each_entry_rcu(mod, &modules, list) {
75112 if (mod->state == MODULE_STATE_UNFORMED)
75113 continue;
75114- if ((mod->module_core) && (mod->core_text_size)) {
75115- set_page_attributes(mod->module_core,
75116- mod->module_core + mod->core_text_size,
75117+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75118+ set_page_attributes(mod->module_core_rx,
75119+ mod->module_core_rx + mod->core_size_rx,
75120 set_memory_rw);
75121 }
75122- if ((mod->module_init) && (mod->init_text_size)) {
75123- set_page_attributes(mod->module_init,
75124- mod->module_init + mod->init_text_size,
75125+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75126+ set_page_attributes(mod->module_init_rx,
75127+ mod->module_init_rx + mod->init_size_rx,
75128 set_memory_rw);
75129 }
75130 }
75131@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
75132 list_for_each_entry_rcu(mod, &modules, list) {
75133 if (mod->state == MODULE_STATE_UNFORMED)
75134 continue;
75135- if ((mod->module_core) && (mod->core_text_size)) {
75136- set_page_attributes(mod->module_core,
75137- mod->module_core + mod->core_text_size,
75138+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75139+ set_page_attributes(mod->module_core_rx,
75140+ mod->module_core_rx + mod->core_size_rx,
75141 set_memory_ro);
75142 }
75143- if ((mod->module_init) && (mod->init_text_size)) {
75144- set_page_attributes(mod->module_init,
75145- mod->module_init + mod->init_text_size,
75146+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75147+ set_page_attributes(mod->module_init_rx,
75148+ mod->module_init_rx + mod->init_size_rx,
75149 set_memory_ro);
75150 }
75151 }
75152@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
75153
75154 /* This may be NULL, but that's OK */
75155 unset_module_init_ro_nx(mod);
75156- module_free(mod, mod->module_init);
75157+ module_free(mod, mod->module_init_rw);
75158+ module_free_exec(mod, mod->module_init_rx);
75159 kfree(mod->args);
75160 percpu_modfree(mod);
75161
75162 /* Free lock-classes: */
75163- lockdep_free_key_range(mod->module_core, mod->core_size);
75164+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
75165+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
75166
75167 /* Finally, free the core (containing the module structure) */
75168 unset_module_core_ro_nx(mod);
75169- module_free(mod, mod->module_core);
75170+ module_free_exec(mod, mod->module_core_rx);
75171+ module_free(mod, mod->module_core_rw);
75172
75173 #ifdef CONFIG_MPU
75174 update_protections(current->mm);
75175@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75176 int ret = 0;
75177 const struct kernel_symbol *ksym;
75178
75179+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75180+ int is_fs_load = 0;
75181+ int register_filesystem_found = 0;
75182+ char *p;
75183+
75184+ p = strstr(mod->args, "grsec_modharden_fs");
75185+ if (p) {
75186+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
75187+ /* copy \0 as well */
75188+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
75189+ is_fs_load = 1;
75190+ }
75191+#endif
75192+
75193 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
75194 const char *name = info->strtab + sym[i].st_name;
75195
75196+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75197+ /* it's a real shame this will never get ripped and copied
75198+ upstream! ;(
75199+ */
75200+ if (is_fs_load && !strcmp(name, "register_filesystem"))
75201+ register_filesystem_found = 1;
75202+#endif
75203+
75204 switch (sym[i].st_shndx) {
75205 case SHN_COMMON:
75206 /* We compiled with -fno-common. These are not
75207@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75208 ksym = resolve_symbol_wait(mod, info, name);
75209 /* Ok if resolved. */
75210 if (ksym && !IS_ERR(ksym)) {
75211+ pax_open_kernel();
75212 sym[i].st_value = ksym->value;
75213+ pax_close_kernel();
75214 break;
75215 }
75216
75217@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75218 secbase = (unsigned long)mod_percpu(mod);
75219 else
75220 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
75221+ pax_open_kernel();
75222 sym[i].st_value += secbase;
75223+ pax_close_kernel();
75224 break;
75225 }
75226 }
75227
75228+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75229+ if (is_fs_load && !register_filesystem_found) {
75230+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
75231+ ret = -EPERM;
75232+ }
75233+#endif
75234+
75235 return ret;
75236 }
75237
75238@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
75239 || s->sh_entsize != ~0UL
75240 || strstarts(sname, ".init"))
75241 continue;
75242- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
75243+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
75244+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
75245+ else
75246+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
75247 pr_debug("\t%s\n", sname);
75248 }
75249- switch (m) {
75250- case 0: /* executable */
75251- mod->core_size = debug_align(mod->core_size);
75252- mod->core_text_size = mod->core_size;
75253- break;
75254- case 1: /* RO: text and ro-data */
75255- mod->core_size = debug_align(mod->core_size);
75256- mod->core_ro_size = mod->core_size;
75257- break;
75258- case 3: /* whole core */
75259- mod->core_size = debug_align(mod->core_size);
75260- break;
75261- }
75262 }
75263
75264 pr_debug("Init section allocation order:\n");
75265@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
75266 || s->sh_entsize != ~0UL
75267 || !strstarts(sname, ".init"))
75268 continue;
75269- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
75270- | INIT_OFFSET_MASK);
75271+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
75272+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
75273+ else
75274+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
75275+ s->sh_entsize |= INIT_OFFSET_MASK;
75276 pr_debug("\t%s\n", sname);
75277 }
75278- switch (m) {
75279- case 0: /* executable */
75280- mod->init_size = debug_align(mod->init_size);
75281- mod->init_text_size = mod->init_size;
75282- break;
75283- case 1: /* RO: text and ro-data */
75284- mod->init_size = debug_align(mod->init_size);
75285- mod->init_ro_size = mod->init_size;
75286- break;
75287- case 3: /* whole init */
75288- mod->init_size = debug_align(mod->init_size);
75289- break;
75290- }
75291 }
75292 }
75293
75294@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
75295
75296 /* Put symbol section at end of init part of module. */
75297 symsect->sh_flags |= SHF_ALLOC;
75298- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
75299+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
75300 info->index.sym) | INIT_OFFSET_MASK;
75301 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
75302
75303@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
75304 }
75305
75306 /* Append room for core symbols at end of core part. */
75307- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
75308- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
75309- mod->core_size += strtab_size;
75310+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
75311+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
75312+ mod->core_size_rx += strtab_size;
75313
75314 /* Put string table section at end of init part of module. */
75315 strsect->sh_flags |= SHF_ALLOC;
75316- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
75317+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
75318 info->index.str) | INIT_OFFSET_MASK;
75319 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
75320 }
75321@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
75322 /* Make sure we get permanent strtab: don't use info->strtab. */
75323 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
75324
75325+ pax_open_kernel();
75326+
75327 /* Set types up while we still have access to sections. */
75328 for (i = 0; i < mod->num_symtab; i++)
75329 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
75330
75331- mod->core_symtab = dst = mod->module_core + info->symoffs;
75332- mod->core_strtab = s = mod->module_core + info->stroffs;
75333+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
75334+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
75335 src = mod->symtab;
75336 for (ndst = i = 0; i < mod->num_symtab; i++) {
75337 if (i == 0 ||
75338@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
75339 }
75340 }
75341 mod->core_num_syms = ndst;
75342+
75343+ pax_close_kernel();
75344 }
75345 #else
75346 static inline void layout_symtab(struct module *mod, struct load_info *info)
75347@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
75348 return vmalloc_exec(size);
75349 }
75350
75351-static void *module_alloc_update_bounds(unsigned long size)
75352+static void *module_alloc_update_bounds_rw(unsigned long size)
75353 {
75354 void *ret = module_alloc(size);
75355
75356 if (ret) {
75357 mutex_lock(&module_mutex);
75358 /* Update module bounds. */
75359- if ((unsigned long)ret < module_addr_min)
75360- module_addr_min = (unsigned long)ret;
75361- if ((unsigned long)ret + size > module_addr_max)
75362- module_addr_max = (unsigned long)ret + size;
75363+ if ((unsigned long)ret < module_addr_min_rw)
75364+ module_addr_min_rw = (unsigned long)ret;
75365+ if ((unsigned long)ret + size > module_addr_max_rw)
75366+ module_addr_max_rw = (unsigned long)ret + size;
75367+ mutex_unlock(&module_mutex);
75368+ }
75369+ return ret;
75370+}
75371+
75372+static void *module_alloc_update_bounds_rx(unsigned long size)
75373+{
75374+ void *ret = module_alloc_exec(size);
75375+
75376+ if (ret) {
75377+ mutex_lock(&module_mutex);
75378+ /* Update module bounds. */
75379+ if ((unsigned long)ret < module_addr_min_rx)
75380+ module_addr_min_rx = (unsigned long)ret;
75381+ if ((unsigned long)ret + size > module_addr_max_rx)
75382+ module_addr_max_rx = (unsigned long)ret + size;
75383 mutex_unlock(&module_mutex);
75384 }
75385 return ret;
75386@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
75387 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
75388 {
75389 const char *modmagic = get_modinfo(info, "vermagic");
75390+ const char *license = get_modinfo(info, "license");
75391 int err;
75392
75393+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
75394+ if (!license || !license_is_gpl_compatible(license))
75395+ return -ENOEXEC;
75396+#endif
75397+
75398 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
75399 modmagic = NULL;
75400
75401@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
75402 }
75403
75404 /* Set up license info based on the info section */
75405- set_license(mod, get_modinfo(info, "license"));
75406+ set_license(mod, license);
75407
75408 return 0;
75409 }
75410@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
75411 void *ptr;
75412
75413 /* Do the allocs. */
75414- ptr = module_alloc_update_bounds(mod->core_size);
75415+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
75416 /*
75417 * The pointer to this block is stored in the module structure
75418 * which is inside the block. Just mark it as not being a
75419@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
75420 if (!ptr)
75421 return -ENOMEM;
75422
75423- memset(ptr, 0, mod->core_size);
75424- mod->module_core = ptr;
75425+ memset(ptr, 0, mod->core_size_rw);
75426+ mod->module_core_rw = ptr;
75427
75428- if (mod->init_size) {
75429- ptr = module_alloc_update_bounds(mod->init_size);
75430+ if (mod->init_size_rw) {
75431+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
75432 /*
75433 * The pointer to this block is stored in the module structure
75434 * which is inside the block. This block doesn't need to be
75435@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
75436 */
75437 kmemleak_ignore(ptr);
75438 if (!ptr) {
75439- module_free(mod, mod->module_core);
75440+ module_free(mod, mod->module_core_rw);
75441 return -ENOMEM;
75442 }
75443- memset(ptr, 0, mod->init_size);
75444- mod->module_init = ptr;
75445+ memset(ptr, 0, mod->init_size_rw);
75446+ mod->module_init_rw = ptr;
75447 } else
75448- mod->module_init = NULL;
75449+ mod->module_init_rw = NULL;
75450+
75451+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
75452+ kmemleak_not_leak(ptr);
75453+ if (!ptr) {
75454+ if (mod->module_init_rw)
75455+ module_free(mod, mod->module_init_rw);
75456+ module_free(mod, mod->module_core_rw);
75457+ return -ENOMEM;
75458+ }
75459+
75460+ pax_open_kernel();
75461+ memset(ptr, 0, mod->core_size_rx);
75462+ pax_close_kernel();
75463+ mod->module_core_rx = ptr;
75464+
75465+ if (mod->init_size_rx) {
75466+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
75467+ kmemleak_ignore(ptr);
75468+ if (!ptr && mod->init_size_rx) {
75469+ module_free_exec(mod, mod->module_core_rx);
75470+ if (mod->module_init_rw)
75471+ module_free(mod, mod->module_init_rw);
75472+ module_free(mod, mod->module_core_rw);
75473+ return -ENOMEM;
75474+ }
75475+
75476+ pax_open_kernel();
75477+ memset(ptr, 0, mod->init_size_rx);
75478+ pax_close_kernel();
75479+ mod->module_init_rx = ptr;
75480+ } else
75481+ mod->module_init_rx = NULL;
75482
75483 /* Transfer each section which specifies SHF_ALLOC */
75484 pr_debug("final section addresses:\n");
75485@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
75486 if (!(shdr->sh_flags & SHF_ALLOC))
75487 continue;
75488
75489- if (shdr->sh_entsize & INIT_OFFSET_MASK)
75490- dest = mod->module_init
75491- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75492- else
75493- dest = mod->module_core + shdr->sh_entsize;
75494+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
75495+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
75496+ dest = mod->module_init_rw
75497+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75498+ else
75499+ dest = mod->module_init_rx
75500+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
75501+ } else {
75502+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
75503+ dest = mod->module_core_rw + shdr->sh_entsize;
75504+ else
75505+ dest = mod->module_core_rx + shdr->sh_entsize;
75506+ }
75507+
75508+ if (shdr->sh_type != SHT_NOBITS) {
75509+
75510+#ifdef CONFIG_PAX_KERNEXEC
75511+#ifdef CONFIG_X86_64
75512+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
75513+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
75514+#endif
75515+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
75516+ pax_open_kernel();
75517+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
75518+ pax_close_kernel();
75519+ } else
75520+#endif
75521
75522- if (shdr->sh_type != SHT_NOBITS)
75523 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
75524+ }
75525 /* Update sh_addr to point to copy in image. */
75526- shdr->sh_addr = (unsigned long)dest;
75527+
75528+#ifdef CONFIG_PAX_KERNEXEC
75529+ if (shdr->sh_flags & SHF_EXECINSTR)
75530+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
75531+ else
75532+#endif
75533+
75534+ shdr->sh_addr = (unsigned long)dest;
75535 pr_debug("\t0x%lx %s\n",
75536 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
75537 }
75538@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
75539 * Do it before processing of module parameters, so the module
75540 * can provide parameter accessor functions of its own.
75541 */
75542- if (mod->module_init)
75543- flush_icache_range((unsigned long)mod->module_init,
75544- (unsigned long)mod->module_init
75545- + mod->init_size);
75546- flush_icache_range((unsigned long)mod->module_core,
75547- (unsigned long)mod->module_core + mod->core_size);
75548+ if (mod->module_init_rx)
75549+ flush_icache_range((unsigned long)mod->module_init_rx,
75550+ (unsigned long)mod->module_init_rx
75551+ + mod->init_size_rx);
75552+ flush_icache_range((unsigned long)mod->module_core_rx,
75553+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
75554
75555 set_fs(old_fs);
75556 }
75557@@ -2983,8 +3088,10 @@ out:
75558 static void module_deallocate(struct module *mod, struct load_info *info)
75559 {
75560 percpu_modfree(mod);
75561- module_free(mod, mod->module_init);
75562- module_free(mod, mod->module_core);
75563+ module_free_exec(mod, mod->module_init_rx);
75564+ module_free_exec(mod, mod->module_core_rx);
75565+ module_free(mod, mod->module_init_rw);
75566+ module_free(mod, mod->module_core_rw);
75567 }
75568
75569 int __weak module_finalize(const Elf_Ehdr *hdr,
75570@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
75571 static int post_relocation(struct module *mod, const struct load_info *info)
75572 {
75573 /* Sort exception table now relocations are done. */
75574+ pax_open_kernel();
75575 sort_extable(mod->extable, mod->extable + mod->num_exentries);
75576+ pax_close_kernel();
75577
75578 /* Copy relocated percpu area over. */
75579 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
75580@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
75581 MODULE_STATE_COMING, mod);
75582
75583 /* Set RO and NX regions for core */
75584- set_section_ro_nx(mod->module_core,
75585- mod->core_text_size,
75586- mod->core_ro_size,
75587- mod->core_size);
75588+ set_section_ro_nx(mod->module_core_rx,
75589+ mod->core_size_rx,
75590+ mod->core_size_rx,
75591+ mod->core_size_rx);
75592
75593 /* Set RO and NX regions for init */
75594- set_section_ro_nx(mod->module_init,
75595- mod->init_text_size,
75596- mod->init_ro_size,
75597- mod->init_size);
75598+ set_section_ro_nx(mod->module_init_rx,
75599+ mod->init_size_rx,
75600+ mod->init_size_rx,
75601+ mod->init_size_rx);
75602
75603 do_mod_ctors(mod);
75604 /* Start the module */
75605@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
75606 mod->strtab = mod->core_strtab;
75607 #endif
75608 unset_module_init_ro_nx(mod);
75609- module_free(mod, mod->module_init);
75610- mod->module_init = NULL;
75611- mod->init_size = 0;
75612- mod->init_ro_size = 0;
75613- mod->init_text_size = 0;
75614+ module_free(mod, mod->module_init_rw);
75615+ module_free_exec(mod, mod->module_init_rx);
75616+ mod->module_init_rw = NULL;
75617+ mod->module_init_rx = NULL;
75618+ mod->init_size_rw = 0;
75619+ mod->init_size_rx = 0;
75620 mutex_unlock(&module_mutex);
75621 wake_up_all(&module_wq);
75622
75623@@ -3209,9 +3319,38 @@ again:
75624 if (err)
75625 goto free_unload;
75626
75627+ /* Now copy in args */
75628+ mod->args = strndup_user(uargs, ~0UL >> 1);
75629+ if (IS_ERR(mod->args)) {
75630+ err = PTR_ERR(mod->args);
75631+ goto free_unload;
75632+ }
75633+
75634 /* Set up MODINFO_ATTR fields */
75635 setup_modinfo(mod, info);
75636
75637+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75638+ {
75639+ char *p, *p2;
75640+
75641+ if (strstr(mod->args, "grsec_modharden_netdev")) {
75642+ 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);
75643+ err = -EPERM;
75644+ goto free_modinfo;
75645+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
75646+ p += sizeof("grsec_modharden_normal") - 1;
75647+ p2 = strstr(p, "_");
75648+ if (p2) {
75649+ *p2 = '\0';
75650+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
75651+ *p2 = '_';
75652+ }
75653+ err = -EPERM;
75654+ goto free_modinfo;
75655+ }
75656+ }
75657+#endif
75658+
75659 /* Fix up syms, so that st_value is a pointer to location. */
75660 err = simplify_symbols(mod, info);
75661 if (err < 0)
75662@@ -3227,13 +3366,6 @@ again:
75663
75664 flush_module_icache(mod);
75665
75666- /* Now copy in args */
75667- mod->args = strndup_user(uargs, ~0UL >> 1);
75668- if (IS_ERR(mod->args)) {
75669- err = PTR_ERR(mod->args);
75670- goto free_arch_cleanup;
75671- }
75672-
75673 dynamic_debug_setup(info->debug, info->num_debug);
75674
75675 mutex_lock(&module_mutex);
75676@@ -3278,11 +3410,10 @@ again:
75677 mutex_unlock(&module_mutex);
75678 dynamic_debug_remove(info->debug);
75679 synchronize_sched();
75680- kfree(mod->args);
75681- free_arch_cleanup:
75682 module_arch_cleanup(mod);
75683 free_modinfo:
75684 free_modinfo(mod);
75685+ kfree(mod->args);
75686 free_unload:
75687 module_unload_free(mod);
75688 unlink_mod:
75689@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
75690 unsigned long nextval;
75691
75692 /* At worse, next value is at end of module */
75693- if (within_module_init(addr, mod))
75694- nextval = (unsigned long)mod->module_init+mod->init_text_size;
75695+ if (within_module_init_rx(addr, mod))
75696+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
75697+ else if (within_module_init_rw(addr, mod))
75698+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
75699+ else if (within_module_core_rx(addr, mod))
75700+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
75701+ else if (within_module_core_rw(addr, mod))
75702+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
75703 else
75704- nextval = (unsigned long)mod->module_core+mod->core_text_size;
75705+ return NULL;
75706
75707 /* Scan for closest preceding symbol, and next symbol. (ELF
75708 starts real symbols at 1). */
75709@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
75710 return 0;
75711
75712 seq_printf(m, "%s %u",
75713- mod->name, mod->init_size + mod->core_size);
75714+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
75715 print_unload_info(m, mod);
75716
75717 /* Informative for users. */
75718@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
75719 mod->state == MODULE_STATE_COMING ? "Loading":
75720 "Live");
75721 /* Used by oprofile and other similar tools. */
75722- seq_printf(m, " 0x%pK", mod->module_core);
75723+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
75724
75725 /* Taints info */
75726 if (mod->taints)
75727@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
75728
75729 static int __init proc_modules_init(void)
75730 {
75731+#ifndef CONFIG_GRKERNSEC_HIDESYM
75732+#ifdef CONFIG_GRKERNSEC_PROC_USER
75733+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75734+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75735+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
75736+#else
75737 proc_create("modules", 0, NULL, &proc_modules_operations);
75738+#endif
75739+#else
75740+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75741+#endif
75742 return 0;
75743 }
75744 module_init(proc_modules_init);
75745@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
75746 {
75747 struct module *mod;
75748
75749- if (addr < module_addr_min || addr > module_addr_max)
75750+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
75751+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
75752 return NULL;
75753
75754 list_for_each_entry_rcu(mod, &modules, list) {
75755 if (mod->state == MODULE_STATE_UNFORMED)
75756 continue;
75757- if (within_module_core(addr, mod)
75758- || within_module_init(addr, mod))
75759+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
75760 return mod;
75761 }
75762 return NULL;
75763@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
75764 */
75765 struct module *__module_text_address(unsigned long addr)
75766 {
75767- struct module *mod = __module_address(addr);
75768+ struct module *mod;
75769+
75770+#ifdef CONFIG_X86_32
75771+ addr = ktla_ktva(addr);
75772+#endif
75773+
75774+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
75775+ return NULL;
75776+
75777+ mod = __module_address(addr);
75778+
75779 if (mod) {
75780 /* Make sure it's within the text section. */
75781- if (!within(addr, mod->module_init, mod->init_text_size)
75782- && !within(addr, mod->module_core, mod->core_text_size))
75783+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
75784 mod = NULL;
75785 }
75786 return mod;
75787diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
75788index 7e3443f..b2a1e6b 100644
75789--- a/kernel/mutex-debug.c
75790+++ b/kernel/mutex-debug.c
75791@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
75792 }
75793
75794 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75795- struct thread_info *ti)
75796+ struct task_struct *task)
75797 {
75798 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
75799
75800 /* Mark the current thread as blocked on the lock: */
75801- ti->task->blocked_on = waiter;
75802+ task->blocked_on = waiter;
75803 }
75804
75805 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75806- struct thread_info *ti)
75807+ struct task_struct *task)
75808 {
75809 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
75810- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
75811- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
75812- ti->task->blocked_on = NULL;
75813+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
75814+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
75815+ task->blocked_on = NULL;
75816
75817 list_del_init(&waiter->list);
75818 waiter->task = NULL;
75819diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
75820index 0799fd3..d06ae3b 100644
75821--- a/kernel/mutex-debug.h
75822+++ b/kernel/mutex-debug.h
75823@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
75824 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
75825 extern void debug_mutex_add_waiter(struct mutex *lock,
75826 struct mutex_waiter *waiter,
75827- struct thread_info *ti);
75828+ struct task_struct *task);
75829 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75830- struct thread_info *ti);
75831+ struct task_struct *task);
75832 extern void debug_mutex_unlock(struct mutex *lock);
75833 extern void debug_mutex_init(struct mutex *lock, const char *name,
75834 struct lock_class_key *key);
75835diff --git a/kernel/mutex.c b/kernel/mutex.c
75836index a307cc9..27fd2e9 100644
75837--- a/kernel/mutex.c
75838+++ b/kernel/mutex.c
75839@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75840 spin_lock_mutex(&lock->wait_lock, flags);
75841
75842 debug_mutex_lock_common(lock, &waiter);
75843- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
75844+ debug_mutex_add_waiter(lock, &waiter, task);
75845
75846 /* add waiting tasks to the end of the waitqueue (FIFO): */
75847 list_add_tail(&waiter.list, &lock->wait_list);
75848@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75849 * TASK_UNINTERRUPTIBLE case.)
75850 */
75851 if (unlikely(signal_pending_state(state, task))) {
75852- mutex_remove_waiter(lock, &waiter,
75853- task_thread_info(task));
75854+ mutex_remove_waiter(lock, &waiter, task);
75855 mutex_release(&lock->dep_map, 1, ip);
75856 spin_unlock_mutex(&lock->wait_lock, flags);
75857
75858@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75859 done:
75860 lock_acquired(&lock->dep_map, ip);
75861 /* got the lock - rejoice! */
75862- mutex_remove_waiter(lock, &waiter, current_thread_info());
75863+ mutex_remove_waiter(lock, &waiter, task);
75864 mutex_set_owner(lock);
75865
75866 /* set it to 0 if there are no waiters left: */
75867diff --git a/kernel/notifier.c b/kernel/notifier.c
75868index 2d5cc4c..d9ea600 100644
75869--- a/kernel/notifier.c
75870+++ b/kernel/notifier.c
75871@@ -5,6 +5,7 @@
75872 #include <linux/rcupdate.h>
75873 #include <linux/vmalloc.h>
75874 #include <linux/reboot.h>
75875+#include <linux/mm.h>
75876
75877 /*
75878 * Notifier list for kernel code which wants to be called
75879@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
75880 while ((*nl) != NULL) {
75881 if (n->priority > (*nl)->priority)
75882 break;
75883- nl = &((*nl)->next);
75884+ nl = (struct notifier_block **)&((*nl)->next);
75885 }
75886- n->next = *nl;
75887+ pax_open_kernel();
75888+ *(const void **)&n->next = *nl;
75889 rcu_assign_pointer(*nl, n);
75890+ pax_close_kernel();
75891 return 0;
75892 }
75893
75894@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
75895 return 0;
75896 if (n->priority > (*nl)->priority)
75897 break;
75898- nl = &((*nl)->next);
75899+ nl = (struct notifier_block **)&((*nl)->next);
75900 }
75901- n->next = *nl;
75902+ pax_open_kernel();
75903+ *(const void **)&n->next = *nl;
75904 rcu_assign_pointer(*nl, n);
75905+ pax_close_kernel();
75906 return 0;
75907 }
75908
75909@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
75910 {
75911 while ((*nl) != NULL) {
75912 if ((*nl) == n) {
75913+ pax_open_kernel();
75914 rcu_assign_pointer(*nl, n->next);
75915+ pax_close_kernel();
75916 return 0;
75917 }
75918- nl = &((*nl)->next);
75919+ nl = (struct notifier_block **)&((*nl)->next);
75920 }
75921 return -ENOENT;
75922 }
75923diff --git a/kernel/panic.c b/kernel/panic.c
75924index e1b2822..5edc1d9 100644
75925--- a/kernel/panic.c
75926+++ b/kernel/panic.c
75927@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
75928 const char *board;
75929
75930 printk(KERN_WARNING "------------[ cut here ]------------\n");
75931- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
75932+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
75933 board = dmi_get_system_info(DMI_PRODUCT_NAME);
75934 if (board)
75935 printk(KERN_WARNING "Hardware name: %s\n", board);
75936@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
75937 */
75938 void __stack_chk_fail(void)
75939 {
75940- panic("stack-protector: Kernel stack is corrupted in: %p\n",
75941+ dump_stack();
75942+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
75943 __builtin_return_address(0));
75944 }
75945 EXPORT_SYMBOL(__stack_chk_fail);
75946diff --git a/kernel/pid.c b/kernel/pid.c
75947index f2c6a68..4922d97 100644
75948--- a/kernel/pid.c
75949+++ b/kernel/pid.c
75950@@ -33,6 +33,7 @@
75951 #include <linux/rculist.h>
75952 #include <linux/bootmem.h>
75953 #include <linux/hash.h>
75954+#include <linux/security.h>
75955 #include <linux/pid_namespace.h>
75956 #include <linux/init_task.h>
75957 #include <linux/syscalls.h>
75958@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
75959
75960 int pid_max = PID_MAX_DEFAULT;
75961
75962-#define RESERVED_PIDS 300
75963+#define RESERVED_PIDS 500
75964
75965 int pid_max_min = RESERVED_PIDS + 1;
75966 int pid_max_max = PID_MAX_LIMIT;
75967@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
75968 */
75969 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
75970 {
75971+ struct task_struct *task;
75972+
75973 rcu_lockdep_assert(rcu_read_lock_held(),
75974 "find_task_by_pid_ns() needs rcu_read_lock()"
75975 " protection");
75976- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75977+
75978+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75979+
75980+ if (gr_pid_is_chrooted(task))
75981+ return NULL;
75982+
75983+ return task;
75984 }
75985
75986 struct task_struct *find_task_by_vpid(pid_t vnr)
75987@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
75988 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
75989 }
75990
75991+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
75992+{
75993+ rcu_lockdep_assert(rcu_read_lock_held(),
75994+ "find_task_by_pid_ns() needs rcu_read_lock()"
75995+ " protection");
75996+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
75997+}
75998+
75999 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
76000 {
76001 struct pid *pid;
76002diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
76003index c1c3dc1..bbeaf31 100644
76004--- a/kernel/pid_namespace.c
76005+++ b/kernel/pid_namespace.c
76006@@ -248,7 +248,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
76007 void __user *buffer, size_t *lenp, loff_t *ppos)
76008 {
76009 struct pid_namespace *pid_ns = task_active_pid_ns(current);
76010- struct ctl_table tmp = *table;
76011+ ctl_table_no_const tmp = *table;
76012
76013 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
76014 return -EPERM;
76015diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
76016index 942ca27..111e609 100644
76017--- a/kernel/posix-cpu-timers.c
76018+++ b/kernel/posix-cpu-timers.c
76019@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
76020
76021 static __init int init_posix_cpu_timers(void)
76022 {
76023- struct k_clock process = {
76024+ static struct k_clock process = {
76025 .clock_getres = process_cpu_clock_getres,
76026 .clock_get = process_cpu_clock_get,
76027 .timer_create = process_cpu_timer_create,
76028 .nsleep = process_cpu_nsleep,
76029 .nsleep_restart = process_cpu_nsleep_restart,
76030 };
76031- struct k_clock thread = {
76032+ static struct k_clock thread = {
76033 .clock_getres = thread_cpu_clock_getres,
76034 .clock_get = thread_cpu_clock_get,
76035 .timer_create = thread_cpu_timer_create,
76036diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
76037index e885be1..380fe76 100644
76038--- a/kernel/posix-timers.c
76039+++ b/kernel/posix-timers.c
76040@@ -43,6 +43,7 @@
76041 #include <linux/idr.h>
76042 #include <linux/posix-clock.h>
76043 #include <linux/posix-timers.h>
76044+#include <linux/grsecurity.h>
76045 #include <linux/syscalls.h>
76046 #include <linux/wait.h>
76047 #include <linux/workqueue.h>
76048@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
76049 * which we beg off on and pass to do_sys_settimeofday().
76050 */
76051
76052-static struct k_clock posix_clocks[MAX_CLOCKS];
76053+static struct k_clock *posix_clocks[MAX_CLOCKS];
76054
76055 /*
76056 * These ones are defined below.
76057@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
76058 */
76059 static __init int init_posix_timers(void)
76060 {
76061- struct k_clock clock_realtime = {
76062+ static struct k_clock clock_realtime = {
76063 .clock_getres = hrtimer_get_res,
76064 .clock_get = posix_clock_realtime_get,
76065 .clock_set = posix_clock_realtime_set,
76066@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
76067 .timer_get = common_timer_get,
76068 .timer_del = common_timer_del,
76069 };
76070- struct k_clock clock_monotonic = {
76071+ static struct k_clock clock_monotonic = {
76072 .clock_getres = hrtimer_get_res,
76073 .clock_get = posix_ktime_get_ts,
76074 .nsleep = common_nsleep,
76075@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
76076 .timer_get = common_timer_get,
76077 .timer_del = common_timer_del,
76078 };
76079- struct k_clock clock_monotonic_raw = {
76080+ static struct k_clock clock_monotonic_raw = {
76081 .clock_getres = hrtimer_get_res,
76082 .clock_get = posix_get_monotonic_raw,
76083 };
76084- struct k_clock clock_realtime_coarse = {
76085+ static struct k_clock clock_realtime_coarse = {
76086 .clock_getres = posix_get_coarse_res,
76087 .clock_get = posix_get_realtime_coarse,
76088 };
76089- struct k_clock clock_monotonic_coarse = {
76090+ static struct k_clock clock_monotonic_coarse = {
76091 .clock_getres = posix_get_coarse_res,
76092 .clock_get = posix_get_monotonic_coarse,
76093 };
76094- struct k_clock clock_boottime = {
76095+ static struct k_clock clock_boottime = {
76096 .clock_getres = hrtimer_get_res,
76097 .clock_get = posix_get_boottime,
76098 .nsleep = common_nsleep,
76099@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
76100 return;
76101 }
76102
76103- posix_clocks[clock_id] = *new_clock;
76104+ posix_clocks[clock_id] = new_clock;
76105 }
76106 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
76107
76108@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
76109 return (id & CLOCKFD_MASK) == CLOCKFD ?
76110 &clock_posix_dynamic : &clock_posix_cpu;
76111
76112- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
76113+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
76114 return NULL;
76115- return &posix_clocks[id];
76116+ return posix_clocks[id];
76117 }
76118
76119 static int common_timer_create(struct k_itimer *new_timer)
76120@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
76121 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
76122 return -EFAULT;
76123
76124+ /* only the CLOCK_REALTIME clock can be set, all other clocks
76125+ have their clock_set fptr set to a nosettime dummy function
76126+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
76127+ call common_clock_set, which calls do_sys_settimeofday, which
76128+ we hook
76129+ */
76130+
76131 return kc->clock_set(which_clock, &new_tp);
76132 }
76133
76134diff --git a/kernel/power/process.c b/kernel/power/process.c
76135index d5a258b..4271191 100644
76136--- a/kernel/power/process.c
76137+++ b/kernel/power/process.c
76138@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
76139 u64 elapsed_csecs64;
76140 unsigned int elapsed_csecs;
76141 bool wakeup = false;
76142+ bool timedout = false;
76143
76144 do_gettimeofday(&start);
76145
76146@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
76147
76148 while (true) {
76149 todo = 0;
76150+ if (time_after(jiffies, end_time))
76151+ timedout = true;
76152 read_lock(&tasklist_lock);
76153 do_each_thread(g, p) {
76154 if (p == current || !freeze_task(p))
76155 continue;
76156
76157- if (!freezer_should_skip(p))
76158+ if (!freezer_should_skip(p)) {
76159 todo++;
76160+ if (timedout) {
76161+ printk(KERN_ERR "Task refusing to freeze:\n");
76162+ sched_show_task(p);
76163+ }
76164+ }
76165 } while_each_thread(g, p);
76166 read_unlock(&tasklist_lock);
76167
76168@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
76169 todo += wq_busy;
76170 }
76171
76172- if (!todo || time_after(jiffies, end_time))
76173+ if (!todo || timedout)
76174 break;
76175
76176 if (pm_wakeup_pending()) {
76177diff --git a/kernel/printk.c b/kernel/printk.c
76178index 267ce78..2487112 100644
76179--- a/kernel/printk.c
76180+++ b/kernel/printk.c
76181@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
76182 return ret;
76183 }
76184
76185+static int check_syslog_permissions(int type, bool from_file);
76186+
76187 static int devkmsg_open(struct inode *inode, struct file *file)
76188 {
76189 struct devkmsg_user *user;
76190 int err;
76191
76192+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
76193+ if (err)
76194+ return err;
76195+
76196 /* write-only does not need any file context */
76197 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
76198 return 0;
76199@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
76200 if (dmesg_restrict)
76201 return 1;
76202 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
76203- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
76204+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
76205 }
76206
76207 static int check_syslog_permissions(int type, bool from_file)
76208@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
76209 if (from_file && type != SYSLOG_ACTION_OPEN)
76210 return 0;
76211
76212+#ifdef CONFIG_GRKERNSEC_DMESG
76213+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
76214+ return -EPERM;
76215+#endif
76216+
76217 if (syslog_action_restricted(type)) {
76218 if (capable(CAP_SYSLOG))
76219 return 0;
76220diff --git a/kernel/profile.c b/kernel/profile.c
76221index 1f39181..86093471 100644
76222--- a/kernel/profile.c
76223+++ b/kernel/profile.c
76224@@ -40,7 +40,7 @@ struct profile_hit {
76225 /* Oprofile timer tick hook */
76226 static int (*timer_hook)(struct pt_regs *) __read_mostly;
76227
76228-static atomic_t *prof_buffer;
76229+static atomic_unchecked_t *prof_buffer;
76230 static unsigned long prof_len, prof_shift;
76231
76232 int prof_on __read_mostly;
76233@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
76234 hits[i].pc = 0;
76235 continue;
76236 }
76237- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
76238+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
76239 hits[i].hits = hits[i].pc = 0;
76240 }
76241 }
76242@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
76243 * Add the current hit(s) and flush the write-queue out
76244 * to the global buffer:
76245 */
76246- atomic_add(nr_hits, &prof_buffer[pc]);
76247+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
76248 for (i = 0; i < NR_PROFILE_HIT; ++i) {
76249- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
76250+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
76251 hits[i].pc = hits[i].hits = 0;
76252 }
76253 out:
76254@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
76255 {
76256 unsigned long pc;
76257 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
76258- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
76259+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
76260 }
76261 #endif /* !CONFIG_SMP */
76262
76263@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
76264 return -EFAULT;
76265 buf++; p++; count--; read++;
76266 }
76267- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
76268+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
76269 if (copy_to_user(buf, (void *)pnt, count))
76270 return -EFAULT;
76271 read += count;
76272@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
76273 }
76274 #endif
76275 profile_discard_flip_buffers();
76276- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
76277+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
76278 return count;
76279 }
76280
76281diff --git a/kernel/ptrace.c b/kernel/ptrace.c
76282index 6cbeaae..363c48a 100644
76283--- a/kernel/ptrace.c
76284+++ b/kernel/ptrace.c
76285@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
76286 if (seize)
76287 flags |= PT_SEIZED;
76288 rcu_read_lock();
76289- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
76290+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
76291 flags |= PT_PTRACE_CAP;
76292 rcu_read_unlock();
76293 task->ptrace = flags;
76294@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
76295 break;
76296 return -EIO;
76297 }
76298- if (copy_to_user(dst, buf, retval))
76299+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
76300 return -EFAULT;
76301 copied += retval;
76302 src += retval;
76303@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
76304 bool seized = child->ptrace & PT_SEIZED;
76305 int ret = -EIO;
76306 siginfo_t siginfo, *si;
76307- void __user *datavp = (void __user *) data;
76308+ void __user *datavp = (__force void __user *) data;
76309 unsigned long __user *datalp = datavp;
76310 unsigned long flags;
76311
76312@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
76313 goto out;
76314 }
76315
76316+ if (gr_handle_ptrace(child, request)) {
76317+ ret = -EPERM;
76318+ goto out_put_task_struct;
76319+ }
76320+
76321 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
76322 ret = ptrace_attach(child, request, addr, data);
76323 /*
76324 * Some architectures need to do book-keeping after
76325 * a ptrace attach.
76326 */
76327- if (!ret)
76328+ if (!ret) {
76329 arch_ptrace_attach(child);
76330+ gr_audit_ptrace(child);
76331+ }
76332 goto out_put_task_struct;
76333 }
76334
76335@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
76336 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
76337 if (copied != sizeof(tmp))
76338 return -EIO;
76339- return put_user(tmp, (unsigned long __user *)data);
76340+ return put_user(tmp, (__force unsigned long __user *)data);
76341 }
76342
76343 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
76344@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76345 goto out;
76346 }
76347
76348+ if (gr_handle_ptrace(child, request)) {
76349+ ret = -EPERM;
76350+ goto out_put_task_struct;
76351+ }
76352+
76353 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
76354 ret = ptrace_attach(child, request, addr, data);
76355 /*
76356 * Some architectures need to do book-keeping after
76357 * a ptrace attach.
76358 */
76359- if (!ret)
76360+ if (!ret) {
76361 arch_ptrace_attach(child);
76362+ gr_audit_ptrace(child);
76363+ }
76364 goto out_put_task_struct;
76365 }
76366
76367diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
76368index e7dce58..ad0d7b7 100644
76369--- a/kernel/rcutiny.c
76370+++ b/kernel/rcutiny.c
76371@@ -46,7 +46,7 @@
76372 struct rcu_ctrlblk;
76373 static void invoke_rcu_callbacks(void);
76374 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
76375-static void rcu_process_callbacks(struct softirq_action *unused);
76376+static void rcu_process_callbacks(void);
76377 static void __call_rcu(struct rcu_head *head,
76378 void (*func)(struct rcu_head *rcu),
76379 struct rcu_ctrlblk *rcp);
76380@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
76381 rcu_is_callbacks_kthread()));
76382 }
76383
76384-static void rcu_process_callbacks(struct softirq_action *unused)
76385+static void rcu_process_callbacks(void)
76386 {
76387 __rcu_process_callbacks(&rcu_sched_ctrlblk);
76388 __rcu_process_callbacks(&rcu_bh_ctrlblk);
76389diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
76390index f85016a..91cb03b 100644
76391--- a/kernel/rcutiny_plugin.h
76392+++ b/kernel/rcutiny_plugin.h
76393@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
76394 have_rcu_kthread_work = morework;
76395 local_irq_restore(flags);
76396 if (work)
76397- rcu_process_callbacks(NULL);
76398+ rcu_process_callbacks();
76399 schedule_timeout_interruptible(1); /* Leave CPU for others. */
76400 }
76401
76402diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
76403index 31dea01..ad91ffb 100644
76404--- a/kernel/rcutorture.c
76405+++ b/kernel/rcutorture.c
76406@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
76407 { 0 };
76408 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
76409 { 0 };
76410-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
76411-static atomic_t n_rcu_torture_alloc;
76412-static atomic_t n_rcu_torture_alloc_fail;
76413-static atomic_t n_rcu_torture_free;
76414-static atomic_t n_rcu_torture_mberror;
76415-static atomic_t n_rcu_torture_error;
76416+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
76417+static atomic_unchecked_t n_rcu_torture_alloc;
76418+static atomic_unchecked_t n_rcu_torture_alloc_fail;
76419+static atomic_unchecked_t n_rcu_torture_free;
76420+static atomic_unchecked_t n_rcu_torture_mberror;
76421+static atomic_unchecked_t n_rcu_torture_error;
76422 static long n_rcu_torture_barrier_error;
76423 static long n_rcu_torture_boost_ktrerror;
76424 static long n_rcu_torture_boost_rterror;
76425@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
76426
76427 spin_lock_bh(&rcu_torture_lock);
76428 if (list_empty(&rcu_torture_freelist)) {
76429- atomic_inc(&n_rcu_torture_alloc_fail);
76430+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
76431 spin_unlock_bh(&rcu_torture_lock);
76432 return NULL;
76433 }
76434- atomic_inc(&n_rcu_torture_alloc);
76435+ atomic_inc_unchecked(&n_rcu_torture_alloc);
76436 p = rcu_torture_freelist.next;
76437 list_del_init(p);
76438 spin_unlock_bh(&rcu_torture_lock);
76439@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
76440 static void
76441 rcu_torture_free(struct rcu_torture *p)
76442 {
76443- atomic_inc(&n_rcu_torture_free);
76444+ atomic_inc_unchecked(&n_rcu_torture_free);
76445 spin_lock_bh(&rcu_torture_lock);
76446 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
76447 spin_unlock_bh(&rcu_torture_lock);
76448@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
76449 i = rp->rtort_pipe_count;
76450 if (i > RCU_TORTURE_PIPE_LEN)
76451 i = RCU_TORTURE_PIPE_LEN;
76452- atomic_inc(&rcu_torture_wcount[i]);
76453+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76454 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
76455 rp->rtort_mbtest = 0;
76456 rcu_torture_free(rp);
76457@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
76458 i = rp->rtort_pipe_count;
76459 if (i > RCU_TORTURE_PIPE_LEN)
76460 i = RCU_TORTURE_PIPE_LEN;
76461- atomic_inc(&rcu_torture_wcount[i]);
76462+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76463 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
76464 rp->rtort_mbtest = 0;
76465 list_del(&rp->rtort_free);
76466@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
76467 i = old_rp->rtort_pipe_count;
76468 if (i > RCU_TORTURE_PIPE_LEN)
76469 i = RCU_TORTURE_PIPE_LEN;
76470- atomic_inc(&rcu_torture_wcount[i]);
76471+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
76472 old_rp->rtort_pipe_count++;
76473 cur_ops->deferred_free(old_rp);
76474 }
76475@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
76476 }
76477 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
76478 if (p->rtort_mbtest == 0)
76479- atomic_inc(&n_rcu_torture_mberror);
76480+ atomic_inc_unchecked(&n_rcu_torture_mberror);
76481 spin_lock(&rand_lock);
76482 cur_ops->read_delay(&rand);
76483 n_rcu_torture_timers++;
76484@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
76485 }
76486 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
76487 if (p->rtort_mbtest == 0)
76488- atomic_inc(&n_rcu_torture_mberror);
76489+ atomic_inc_unchecked(&n_rcu_torture_mberror);
76490 cur_ops->read_delay(&rand);
76491 preempt_disable();
76492 pipe_count = p->rtort_pipe_count;
76493@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
76494 rcu_torture_current,
76495 rcu_torture_current_version,
76496 list_empty(&rcu_torture_freelist),
76497- atomic_read(&n_rcu_torture_alloc),
76498- atomic_read(&n_rcu_torture_alloc_fail),
76499- atomic_read(&n_rcu_torture_free));
76500+ atomic_read_unchecked(&n_rcu_torture_alloc),
76501+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
76502+ atomic_read_unchecked(&n_rcu_torture_free));
76503 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
76504- atomic_read(&n_rcu_torture_mberror),
76505+ atomic_read_unchecked(&n_rcu_torture_mberror),
76506 n_rcu_torture_boost_ktrerror,
76507 n_rcu_torture_boost_rterror);
76508 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
76509@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
76510 n_barrier_attempts,
76511 n_rcu_torture_barrier_error);
76512 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
76513- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
76514+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
76515 n_rcu_torture_barrier_error != 0 ||
76516 n_rcu_torture_boost_ktrerror != 0 ||
76517 n_rcu_torture_boost_rterror != 0 ||
76518 n_rcu_torture_boost_failure != 0 ||
76519 i > 1) {
76520 cnt += sprintf(&page[cnt], "!!! ");
76521- atomic_inc(&n_rcu_torture_error);
76522+ atomic_inc_unchecked(&n_rcu_torture_error);
76523 WARN_ON_ONCE(1);
76524 }
76525 cnt += sprintf(&page[cnt], "Reader Pipe: ");
76526@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
76527 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
76528 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
76529 cnt += sprintf(&page[cnt], " %d",
76530- atomic_read(&rcu_torture_wcount[i]));
76531+ atomic_read_unchecked(&rcu_torture_wcount[i]));
76532 }
76533 cnt += sprintf(&page[cnt], "\n");
76534 if (cur_ops->stats)
76535@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
76536
76537 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
76538
76539- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
76540+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
76541 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
76542 else if (n_online_successes != n_online_attempts ||
76543 n_offline_successes != n_offline_attempts)
76544@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
76545
76546 rcu_torture_current = NULL;
76547 rcu_torture_current_version = 0;
76548- atomic_set(&n_rcu_torture_alloc, 0);
76549- atomic_set(&n_rcu_torture_alloc_fail, 0);
76550- atomic_set(&n_rcu_torture_free, 0);
76551- atomic_set(&n_rcu_torture_mberror, 0);
76552- atomic_set(&n_rcu_torture_error, 0);
76553+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
76554+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
76555+ atomic_set_unchecked(&n_rcu_torture_free, 0);
76556+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
76557+ atomic_set_unchecked(&n_rcu_torture_error, 0);
76558 n_rcu_torture_barrier_error = 0;
76559 n_rcu_torture_boost_ktrerror = 0;
76560 n_rcu_torture_boost_rterror = 0;
76561 n_rcu_torture_boost_failure = 0;
76562 n_rcu_torture_boosts = 0;
76563 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
76564- atomic_set(&rcu_torture_wcount[i], 0);
76565+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
76566 for_each_possible_cpu(cpu) {
76567 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
76568 per_cpu(rcu_torture_count, cpu)[i] = 0;
76569diff --git a/kernel/rcutree.c b/kernel/rcutree.c
76570index e441b77..dd54f17 100644
76571--- a/kernel/rcutree.c
76572+++ b/kernel/rcutree.c
76573@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
76574 rcu_prepare_for_idle(smp_processor_id());
76575 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76576 smp_mb__before_atomic_inc(); /* See above. */
76577- atomic_inc(&rdtp->dynticks);
76578+ atomic_inc_unchecked(&rdtp->dynticks);
76579 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
76580- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76581+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76582
76583 /*
76584 * It is illegal to enter an extended quiescent state while
76585@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
76586 int user)
76587 {
76588 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
76589- atomic_inc(&rdtp->dynticks);
76590+ atomic_inc_unchecked(&rdtp->dynticks);
76591 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76592 smp_mb__after_atomic_inc(); /* See above. */
76593- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76594+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76595 rcu_cleanup_after_idle(smp_processor_id());
76596 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
76597 if (!user && !is_idle_task(current)) {
76598@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
76599 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
76600
76601 if (rdtp->dynticks_nmi_nesting == 0 &&
76602- (atomic_read(&rdtp->dynticks) & 0x1))
76603+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
76604 return;
76605 rdtp->dynticks_nmi_nesting++;
76606 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
76607- atomic_inc(&rdtp->dynticks);
76608+ atomic_inc_unchecked(&rdtp->dynticks);
76609 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76610 smp_mb__after_atomic_inc(); /* See above. */
76611- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76612+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76613 }
76614
76615 /**
76616@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
76617 return;
76618 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76619 smp_mb__before_atomic_inc(); /* See above. */
76620- atomic_inc(&rdtp->dynticks);
76621+ atomic_inc_unchecked(&rdtp->dynticks);
76622 smp_mb__after_atomic_inc(); /* Force delay to next write. */
76623- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76624+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76625 }
76626
76627 /**
76628@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
76629 int ret;
76630
76631 preempt_disable();
76632- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76633+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76634 preempt_enable();
76635 return ret;
76636 }
76637@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
76638 */
76639 static int dyntick_save_progress_counter(struct rcu_data *rdp)
76640 {
76641- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
76642+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76643 return (rdp->dynticks_snap & 0x1) == 0;
76644 }
76645
76646@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
76647 unsigned int curr;
76648 unsigned int snap;
76649
76650- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
76651+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76652 snap = (unsigned int)rdp->dynticks_snap;
76653
76654 /*
76655@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
76656 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
76657 */
76658 if (till_stall_check < 3) {
76659- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
76660+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
76661 till_stall_check = 3;
76662 } else if (till_stall_check > 300) {
76663- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
76664+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
76665 till_stall_check = 300;
76666 }
76667 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
76668@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
76669 rsp->qlen += rdp->qlen;
76670 rdp->n_cbs_orphaned += rdp->qlen;
76671 rdp->qlen_lazy = 0;
76672- ACCESS_ONCE(rdp->qlen) = 0;
76673+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76674 }
76675
76676 /*
76677@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
76678 }
76679 smp_mb(); /* List handling before counting for rcu_barrier(). */
76680 rdp->qlen_lazy -= count_lazy;
76681- ACCESS_ONCE(rdp->qlen) -= count;
76682+ ACCESS_ONCE_RW(rdp->qlen) -= count;
76683 rdp->n_cbs_invoked += count;
76684
76685 /* Reinstate batch limit if we have worked down the excess. */
76686@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
76687 /*
76688 * Do RCU core processing for the current CPU.
76689 */
76690-static void rcu_process_callbacks(struct softirq_action *unused)
76691+static void rcu_process_callbacks(void)
76692 {
76693 struct rcu_state *rsp;
76694
76695@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
76696 local_irq_restore(flags);
76697 return;
76698 }
76699- ACCESS_ONCE(rdp->qlen)++;
76700+ ACCESS_ONCE_RW(rdp->qlen)++;
76701 if (lazy)
76702 rdp->qlen_lazy++;
76703 else
76704@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
76705 * counter wrap on a 32-bit system. Quite a few more CPUs would of
76706 * course be required on a 64-bit system.
76707 */
76708- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
76709+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
76710 (ulong)atomic_long_read(&rsp->expedited_done) +
76711 ULONG_MAX / 8)) {
76712 synchronize_sched();
76713- atomic_long_inc(&rsp->expedited_wrap);
76714+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
76715 return;
76716 }
76717
76718@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
76719 * Take a ticket. Note that atomic_inc_return() implies a
76720 * full memory barrier.
76721 */
76722- snap = atomic_long_inc_return(&rsp->expedited_start);
76723+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
76724 firstsnap = snap;
76725 get_online_cpus();
76726 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
76727@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
76728 synchronize_sched_expedited_cpu_stop,
76729 NULL) == -EAGAIN) {
76730 put_online_cpus();
76731- atomic_long_inc(&rsp->expedited_tryfail);
76732+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
76733
76734 /* Check to see if someone else did our work for us. */
76735 s = atomic_long_read(&rsp->expedited_done);
76736 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76737 /* ensure test happens before caller kfree */
76738 smp_mb__before_atomic_inc(); /* ^^^ */
76739- atomic_long_inc(&rsp->expedited_workdone1);
76740+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
76741 return;
76742 }
76743
76744@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
76745 udelay(trycount * num_online_cpus());
76746 } else {
76747 wait_rcu_gp(call_rcu_sched);
76748- atomic_long_inc(&rsp->expedited_normal);
76749+ atomic_long_inc_unchecked(&rsp->expedited_normal);
76750 return;
76751 }
76752
76753@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
76754 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76755 /* ensure test happens before caller kfree */
76756 smp_mb__before_atomic_inc(); /* ^^^ */
76757- atomic_long_inc(&rsp->expedited_workdone2);
76758+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
76759 return;
76760 }
76761
76762@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
76763 * period works for us.
76764 */
76765 get_online_cpus();
76766- snap = atomic_long_read(&rsp->expedited_start);
76767+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
76768 smp_mb(); /* ensure read is before try_stop_cpus(). */
76769 }
76770- atomic_long_inc(&rsp->expedited_stoppedcpus);
76771+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
76772
76773 /*
76774 * Everyone up to our most recent fetch is covered by our grace
76775@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
76776 * than we did already did their update.
76777 */
76778 do {
76779- atomic_long_inc(&rsp->expedited_done_tries);
76780+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
76781 s = atomic_long_read(&rsp->expedited_done);
76782 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
76783 /* ensure test happens before caller kfree */
76784 smp_mb__before_atomic_inc(); /* ^^^ */
76785- atomic_long_inc(&rsp->expedited_done_lost);
76786+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
76787 break;
76788 }
76789 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
76790- atomic_long_inc(&rsp->expedited_done_exit);
76791+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
76792
76793 put_online_cpus();
76794 }
76795@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76796 * ACCESS_ONCE() to prevent the compiler from speculating
76797 * the increment to precede the early-exit check.
76798 */
76799- ACCESS_ONCE(rsp->n_barrier_done)++;
76800+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76801 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
76802 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
76803 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
76804@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76805
76806 /* Increment ->n_barrier_done to prevent duplicate work. */
76807 smp_mb(); /* Keep increment after above mechanism. */
76808- ACCESS_ONCE(rsp->n_barrier_done)++;
76809+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76810 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
76811 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
76812 smp_mb(); /* Keep increment before caller's subsequent code. */
76813@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
76814 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
76815 init_callback_list(rdp);
76816 rdp->qlen_lazy = 0;
76817- ACCESS_ONCE(rdp->qlen) = 0;
76818+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76819 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
76820 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
76821- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
76822+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
76823 #ifdef CONFIG_RCU_USER_QS
76824 WARN_ON_ONCE(rdp->dynticks->in_user);
76825 #endif
76826@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
76827 rdp->blimit = blimit;
76828 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
76829 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
76830- atomic_set(&rdp->dynticks->dynticks,
76831- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
76832+ atomic_set_unchecked(&rdp->dynticks->dynticks,
76833+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
76834 rcu_prepare_for_idle_init(cpu);
76835 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
76836
76837diff --git a/kernel/rcutree.h b/kernel/rcutree.h
76838index 4b69291..704c92e 100644
76839--- a/kernel/rcutree.h
76840+++ b/kernel/rcutree.h
76841@@ -86,7 +86,7 @@ struct rcu_dynticks {
76842 long long dynticks_nesting; /* Track irq/process nesting level. */
76843 /* Process level is worth LLONG_MAX/2. */
76844 int dynticks_nmi_nesting; /* Track NMI nesting level. */
76845- atomic_t dynticks; /* Even value for idle, else odd. */
76846+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
76847 #ifdef CONFIG_RCU_FAST_NO_HZ
76848 int dyntick_drain; /* Prepare-for-idle state variable. */
76849 unsigned long dyntick_holdoff;
76850@@ -423,17 +423,17 @@ struct rcu_state {
76851 /* _rcu_barrier(). */
76852 /* End of fields guarded by barrier_mutex. */
76853
76854- atomic_long_t expedited_start; /* Starting ticket. */
76855- atomic_long_t expedited_done; /* Done ticket. */
76856- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
76857- atomic_long_t expedited_tryfail; /* # acquisition failures. */
76858- atomic_long_t expedited_workdone1; /* # done by others #1. */
76859- atomic_long_t expedited_workdone2; /* # done by others #2. */
76860- atomic_long_t expedited_normal; /* # fallbacks to normal. */
76861- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
76862- atomic_long_t expedited_done_tries; /* # tries to update _done. */
76863- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
76864- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
76865+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
76866+ atomic_long_t expedited_done; /* Done ticket. */
76867+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
76868+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
76869+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
76870+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
76871+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
76872+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
76873+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
76874+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
76875+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
76876
76877 unsigned long jiffies_force_qs; /* Time at which to invoke */
76878 /* force_quiescent_state(). */
76879diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
76880index c1cc7e1..f62e436 100644
76881--- a/kernel/rcutree_plugin.h
76882+++ b/kernel/rcutree_plugin.h
76883@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
76884
76885 /* Clean up and exit. */
76886 smp_mb(); /* ensure expedited GP seen before counter increment. */
76887- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
76888+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
76889 unlock_mb_ret:
76890 mutex_unlock(&sync_rcu_preempt_exp_mutex);
76891 mb_ret:
76892@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
76893 free_cpumask_var(cm);
76894 }
76895
76896-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
76897+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
76898 .store = &rcu_cpu_kthread_task,
76899 .thread_should_run = rcu_cpu_kthread_should_run,
76900 .thread_fn = rcu_cpu_kthread,
76901@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
76902 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
76903 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
76904 cpu, ticks_value, ticks_title,
76905- atomic_read(&rdtp->dynticks) & 0xfff,
76906+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
76907 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
76908 fast_no_hz);
76909 }
76910@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
76911
76912 /* Enqueue the callback on the nocb list and update counts. */
76913 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
76914- ACCESS_ONCE(*old_rhpp) = rhp;
76915+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
76916 atomic_long_add(rhcount, &rdp->nocb_q_count);
76917 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
76918
76919@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
76920 * Extract queued callbacks, update counts, and wait
76921 * for a grace period to elapse.
76922 */
76923- ACCESS_ONCE(rdp->nocb_head) = NULL;
76924+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
76925 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
76926 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
76927 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
76928- ACCESS_ONCE(rdp->nocb_p_count) += c;
76929- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
76930+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
76931+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
76932 wait_rcu_gp(rdp->rsp->call_remote);
76933
76934 /* Each pass through the following loop invokes a callback. */
76935@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
76936 list = next;
76937 }
76938 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
76939- ACCESS_ONCE(rdp->nocb_p_count) -= c;
76940- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
76941+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
76942+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
76943 rdp->n_nocbs_invoked += c;
76944 }
76945 return 0;
76946@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
76947 rdp = per_cpu_ptr(rsp->rda, cpu);
76948 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
76949 BUG_ON(IS_ERR(t));
76950- ACCESS_ONCE(rdp->nocb_kthread) = t;
76951+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
76952 }
76953 }
76954
76955diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
76956index 0d095dc..1985b19 100644
76957--- a/kernel/rcutree_trace.c
76958+++ b/kernel/rcutree_trace.c
76959@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
76960 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
76961 rdp->passed_quiesce, rdp->qs_pending);
76962 seq_printf(m, " dt=%d/%llx/%d df=%lu",
76963- atomic_read(&rdp->dynticks->dynticks),
76964+ atomic_read_unchecked(&rdp->dynticks->dynticks),
76965 rdp->dynticks->dynticks_nesting,
76966 rdp->dynticks->dynticks_nmi_nesting,
76967 rdp->dynticks_fqs);
76968@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
76969 struct rcu_state *rsp = (struct rcu_state *)m->private;
76970
76971 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",
76972- atomic_long_read(&rsp->expedited_start),
76973+ atomic_long_read_unchecked(&rsp->expedited_start),
76974 atomic_long_read(&rsp->expedited_done),
76975- atomic_long_read(&rsp->expedited_wrap),
76976- atomic_long_read(&rsp->expedited_tryfail),
76977- atomic_long_read(&rsp->expedited_workdone1),
76978- atomic_long_read(&rsp->expedited_workdone2),
76979- atomic_long_read(&rsp->expedited_normal),
76980- atomic_long_read(&rsp->expedited_stoppedcpus),
76981- atomic_long_read(&rsp->expedited_done_tries),
76982- atomic_long_read(&rsp->expedited_done_lost),
76983- atomic_long_read(&rsp->expedited_done_exit));
76984+ atomic_long_read_unchecked(&rsp->expedited_wrap),
76985+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
76986+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
76987+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
76988+ atomic_long_read_unchecked(&rsp->expedited_normal),
76989+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
76990+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
76991+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
76992+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
76993 return 0;
76994 }
76995
76996diff --git a/kernel/resource.c b/kernel/resource.c
76997index 73f35d4..4684fc4 100644
76998--- a/kernel/resource.c
76999+++ b/kernel/resource.c
77000@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
77001
77002 static int __init ioresources_init(void)
77003 {
77004+#ifdef CONFIG_GRKERNSEC_PROC_ADD
77005+#ifdef CONFIG_GRKERNSEC_PROC_USER
77006+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
77007+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
77008+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77009+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
77010+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
77011+#endif
77012+#else
77013 proc_create("ioports", 0, NULL, &proc_ioports_operations);
77014 proc_create("iomem", 0, NULL, &proc_iomem_operations);
77015+#endif
77016 return 0;
77017 }
77018 __initcall(ioresources_init);
77019diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
77020index 98ec494..4241d6d 100644
77021--- a/kernel/rtmutex-tester.c
77022+++ b/kernel/rtmutex-tester.c
77023@@ -20,7 +20,7 @@
77024 #define MAX_RT_TEST_MUTEXES 8
77025
77026 static spinlock_t rttest_lock;
77027-static atomic_t rttest_event;
77028+static atomic_unchecked_t rttest_event;
77029
77030 struct test_thread_data {
77031 int opcode;
77032@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77033
77034 case RTTEST_LOCKCONT:
77035 td->mutexes[td->opdata] = 1;
77036- td->event = atomic_add_return(1, &rttest_event);
77037+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77038 return 0;
77039
77040 case RTTEST_RESET:
77041@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77042 return 0;
77043
77044 case RTTEST_RESETEVENT:
77045- atomic_set(&rttest_event, 0);
77046+ atomic_set_unchecked(&rttest_event, 0);
77047 return 0;
77048
77049 default:
77050@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77051 return ret;
77052
77053 td->mutexes[id] = 1;
77054- td->event = atomic_add_return(1, &rttest_event);
77055+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77056 rt_mutex_lock(&mutexes[id]);
77057- td->event = atomic_add_return(1, &rttest_event);
77058+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77059 td->mutexes[id] = 4;
77060 return 0;
77061
77062@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77063 return ret;
77064
77065 td->mutexes[id] = 1;
77066- td->event = atomic_add_return(1, &rttest_event);
77067+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77068 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
77069- td->event = atomic_add_return(1, &rttest_event);
77070+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77071 td->mutexes[id] = ret ? 0 : 4;
77072 return ret ? -EINTR : 0;
77073
77074@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77075 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
77076 return ret;
77077
77078- td->event = atomic_add_return(1, &rttest_event);
77079+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77080 rt_mutex_unlock(&mutexes[id]);
77081- td->event = atomic_add_return(1, &rttest_event);
77082+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77083 td->mutexes[id] = 0;
77084 return 0;
77085
77086@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77087 break;
77088
77089 td->mutexes[dat] = 2;
77090- td->event = atomic_add_return(1, &rttest_event);
77091+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77092 break;
77093
77094 default:
77095@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77096 return;
77097
77098 td->mutexes[dat] = 3;
77099- td->event = atomic_add_return(1, &rttest_event);
77100+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77101 break;
77102
77103 case RTTEST_LOCKNOWAIT:
77104@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77105 return;
77106
77107 td->mutexes[dat] = 1;
77108- td->event = atomic_add_return(1, &rttest_event);
77109+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77110 return;
77111
77112 default:
77113diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
77114index 0984a21..939f183 100644
77115--- a/kernel/sched/auto_group.c
77116+++ b/kernel/sched/auto_group.c
77117@@ -11,7 +11,7 @@
77118
77119 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
77120 static struct autogroup autogroup_default;
77121-static atomic_t autogroup_seq_nr;
77122+static atomic_unchecked_t autogroup_seq_nr;
77123
77124 void __init autogroup_init(struct task_struct *init_task)
77125 {
77126@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
77127
77128 kref_init(&ag->kref);
77129 init_rwsem(&ag->lock);
77130- ag->id = atomic_inc_return(&autogroup_seq_nr);
77131+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
77132 ag->tg = tg;
77133 #ifdef CONFIG_RT_GROUP_SCHED
77134 /*
77135diff --git a/kernel/sched/core.c b/kernel/sched/core.c
77136index 26058d0..e315889 100644
77137--- a/kernel/sched/core.c
77138+++ b/kernel/sched/core.c
77139@@ -3367,7 +3367,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
77140 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77141 * positive (at least 1, or number of jiffies left till timeout) if completed.
77142 */
77143-long __sched
77144+long __sched __intentional_overflow(-1)
77145 wait_for_completion_interruptible_timeout(struct completion *x,
77146 unsigned long timeout)
77147 {
77148@@ -3384,7 +3384,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
77149 *
77150 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
77151 */
77152-int __sched wait_for_completion_killable(struct completion *x)
77153+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
77154 {
77155 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
77156 if (t == -ERESTARTSYS)
77157@@ -3405,7 +3405,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
77158 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77159 * positive (at least 1, or number of jiffies left till timeout) if completed.
77160 */
77161-long __sched
77162+long __sched __intentional_overflow(-1)
77163 wait_for_completion_killable_timeout(struct completion *x,
77164 unsigned long timeout)
77165 {
77166@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
77167 /* convert nice value [19,-20] to rlimit style value [1,40] */
77168 int nice_rlim = 20 - nice;
77169
77170+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
77171+
77172 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
77173 capable(CAP_SYS_NICE));
77174 }
77175@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
77176 if (nice > 19)
77177 nice = 19;
77178
77179- if (increment < 0 && !can_nice(current, nice))
77180+ if (increment < 0 && (!can_nice(current, nice) ||
77181+ gr_handle_chroot_nice()))
77182 return -EPERM;
77183
77184 retval = security_task_setnice(current, nice);
77185@@ -3818,6 +3821,7 @@ recheck:
77186 unsigned long rlim_rtprio =
77187 task_rlimit(p, RLIMIT_RTPRIO);
77188
77189+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
77190 /* can't set/change the rt policy */
77191 if (policy != p->policy && !rlim_rtprio)
77192 return -EPERM;
77193@@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
77194
77195 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
77196
77197-static struct ctl_table sd_ctl_dir[] = {
77198+static ctl_table_no_const sd_ctl_dir[] __read_only = {
77199 {
77200 .procname = "sched_domain",
77201 .mode = 0555,
77202@@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
77203 {}
77204 };
77205
77206-static struct ctl_table *sd_alloc_ctl_entry(int n)
77207+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
77208 {
77209- struct ctl_table *entry =
77210+ ctl_table_no_const *entry =
77211 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
77212
77213 return entry;
77214 }
77215
77216-static void sd_free_ctl_entry(struct ctl_table **tablep)
77217+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
77218 {
77219- struct ctl_table *entry;
77220+ ctl_table_no_const *entry;
77221
77222 /*
77223 * In the intermediate directories, both the child directory and
77224@@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
77225 * will always be set. In the lowest directory the names are
77226 * static strings and all have proc handlers.
77227 */
77228- for (entry = *tablep; entry->mode; entry++) {
77229- if (entry->child)
77230- sd_free_ctl_entry(&entry->child);
77231+ for (entry = tablep; entry->mode; entry++) {
77232+ if (entry->child) {
77233+ sd_free_ctl_entry(entry->child);
77234+ pax_open_kernel();
77235+ entry->child = NULL;
77236+ pax_close_kernel();
77237+ }
77238 if (entry->proc_handler == NULL)
77239 kfree(entry->procname);
77240 }
77241
77242- kfree(*tablep);
77243- *tablep = NULL;
77244+ kfree(tablep);
77245 }
77246
77247 static int min_load_idx = 0;
77248 static int max_load_idx = CPU_LOAD_IDX_MAX;
77249
77250 static void
77251-set_table_entry(struct ctl_table *entry,
77252+set_table_entry(ctl_table_no_const *entry,
77253 const char *procname, void *data, int maxlen,
77254 umode_t mode, proc_handler *proc_handler,
77255 bool load_idx)
77256@@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
77257 static struct ctl_table *
77258 sd_alloc_ctl_domain_table(struct sched_domain *sd)
77259 {
77260- struct ctl_table *table = sd_alloc_ctl_entry(13);
77261+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
77262
77263 if (table == NULL)
77264 return NULL;
77265@@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
77266 return table;
77267 }
77268
77269-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
77270+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
77271 {
77272- struct ctl_table *entry, *table;
77273+ ctl_table_no_const *entry, *table;
77274 struct sched_domain *sd;
77275 int domain_num = 0, i;
77276 char buf[32];
77277@@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
77278 static void register_sched_domain_sysctl(void)
77279 {
77280 int i, cpu_num = num_possible_cpus();
77281- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
77282+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
77283 char buf[32];
77284
77285 WARN_ON(sd_ctl_dir[0].child);
77286+ pax_open_kernel();
77287 sd_ctl_dir[0].child = entry;
77288+ pax_close_kernel();
77289
77290 if (entry == NULL)
77291 return;
77292@@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
77293 if (sd_sysctl_header)
77294 unregister_sysctl_table(sd_sysctl_header);
77295 sd_sysctl_header = NULL;
77296- if (sd_ctl_dir[0].child)
77297- sd_free_ctl_entry(&sd_ctl_dir[0].child);
77298+ if (sd_ctl_dir[0].child) {
77299+ sd_free_ctl_entry(sd_ctl_dir[0].child);
77300+ pax_open_kernel();
77301+ sd_ctl_dir[0].child = NULL;
77302+ pax_close_kernel();
77303+ }
77304 }
77305 #else
77306 static void register_sched_domain_sysctl(void)
77307@@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
77308 * happens before everything else. This has to be lower priority than
77309 * the notifier in the perf_event subsystem, though.
77310 */
77311-static struct notifier_block __cpuinitdata migration_notifier = {
77312+static struct notifier_block migration_notifier = {
77313 .notifier_call = migration_call,
77314 .priority = CPU_PRI_MIGRATION,
77315 };
77316diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
77317index 81fa536..6ccf96a 100644
77318--- a/kernel/sched/fair.c
77319+++ b/kernel/sched/fair.c
77320@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
77321
77322 static void reset_ptenuma_scan(struct task_struct *p)
77323 {
77324- ACCESS_ONCE(p->mm->numa_scan_seq)++;
77325+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
77326 p->mm->numa_scan_offset = 0;
77327 }
77328
77329@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
77330 */
77331 static int select_idle_sibling(struct task_struct *p, int target)
77332 {
77333- int cpu = smp_processor_id();
77334- int prev_cpu = task_cpu(p);
77335 struct sched_domain *sd;
77336 struct sched_group *sg;
77337- int i;
77338+ int i = task_cpu(p);
77339
77340- /*
77341- * If the task is going to be woken-up on this cpu and if it is
77342- * already idle, then it is the right target.
77343- */
77344- if (target == cpu && idle_cpu(cpu))
77345- return cpu;
77346+ if (idle_cpu(target))
77347+ return target;
77348
77349 /*
77350- * If the task is going to be woken-up on the cpu where it previously
77351- * ran and if it is currently idle, then it the right target.
77352+ * If the prevous cpu is cache affine and idle, don't be stupid.
77353 */
77354- if (target == prev_cpu && idle_cpu(prev_cpu))
77355- return prev_cpu;
77356+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
77357+ return i;
77358
77359 /*
77360 * Otherwise, iterate the domains and find an elegible idle cpu.
77361@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
77362 goto next;
77363
77364 for_each_cpu(i, sched_group_cpus(sg)) {
77365- if (!idle_cpu(i))
77366+ if (i == target || !idle_cpu(i))
77367 goto next;
77368 }
77369
77370@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
77371 * run_rebalance_domains is triggered when needed from the scheduler tick.
77372 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
77373 */
77374-static void run_rebalance_domains(struct softirq_action *h)
77375+static void run_rebalance_domains(void)
77376 {
77377 int this_cpu = smp_processor_id();
77378 struct rq *this_rq = cpu_rq(this_cpu);
77379diff --git a/kernel/signal.c b/kernel/signal.c
77380index 3d09cf6..8988390 100644
77381--- a/kernel/signal.c
77382+++ b/kernel/signal.c
77383@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
77384
77385 int print_fatal_signals __read_mostly;
77386
77387-static void __user *sig_handler(struct task_struct *t, int sig)
77388+static __sighandler_t sig_handler(struct task_struct *t, int sig)
77389 {
77390 return t->sighand->action[sig - 1].sa.sa_handler;
77391 }
77392
77393-static int sig_handler_ignored(void __user *handler, int sig)
77394+static int sig_handler_ignored(__sighandler_t handler, int sig)
77395 {
77396 /* Is it explicitly or implicitly ignored? */
77397 return handler == SIG_IGN ||
77398@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
77399
77400 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
77401 {
77402- void __user *handler;
77403+ __sighandler_t handler;
77404
77405 handler = sig_handler(t, sig);
77406
77407@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
77408 atomic_inc(&user->sigpending);
77409 rcu_read_unlock();
77410
77411+ if (!override_rlimit)
77412+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
77413+
77414 if (override_rlimit ||
77415 atomic_read(&user->sigpending) <=
77416 task_rlimit(t, RLIMIT_SIGPENDING)) {
77417@@ -485,6 +488,9 @@ flush_signal_handlers(struct task_struct *t, int force_default)
77418 if (force_default || ka->sa.sa_handler != SIG_IGN)
77419 ka->sa.sa_handler = SIG_DFL;
77420 ka->sa.sa_flags = 0;
77421+#ifdef SA_RESTORER
77422+ ka->sa.sa_restorer = NULL;
77423+#endif
77424 sigemptyset(&ka->sa.sa_mask);
77425 ka++;
77426 }
77427@@ -492,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
77428
77429 int unhandled_signal(struct task_struct *tsk, int sig)
77430 {
77431- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
77432+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
77433 if (is_global_init(tsk))
77434 return 1;
77435 if (handler != SIG_IGN && handler != SIG_DFL)
77436@@ -812,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
77437 }
77438 }
77439
77440+ /* allow glibc communication via tgkill to other threads in our
77441+ thread group */
77442+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
77443+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
77444+ && gr_handle_signal(t, sig))
77445+ return -EPERM;
77446+
77447 return security_task_kill(t, info, sig, 0);
77448 }
77449
77450@@ -1194,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
77451 return send_signal(sig, info, p, 1);
77452 }
77453
77454-static int
77455+int
77456 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77457 {
77458 return send_signal(sig, info, t, 0);
77459@@ -1231,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77460 unsigned long int flags;
77461 int ret, blocked, ignored;
77462 struct k_sigaction *action;
77463+ int is_unhandled = 0;
77464
77465 spin_lock_irqsave(&t->sighand->siglock, flags);
77466 action = &t->sighand->action[sig-1];
77467@@ -1245,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
77468 }
77469 if (action->sa.sa_handler == SIG_DFL)
77470 t->signal->flags &= ~SIGNAL_UNKILLABLE;
77471+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
77472+ is_unhandled = 1;
77473 ret = specific_send_sig_info(sig, info, t);
77474 spin_unlock_irqrestore(&t->sighand->siglock, flags);
77475
77476+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
77477+ normal operation */
77478+ if (is_unhandled) {
77479+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
77480+ gr_handle_crash(t, sig);
77481+ }
77482+
77483 return ret;
77484 }
77485
77486@@ -1314,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
77487 ret = check_kill_permission(sig, info, p);
77488 rcu_read_unlock();
77489
77490- if (!ret && sig)
77491+ if (!ret && sig) {
77492 ret = do_send_sig_info(sig, info, p, true);
77493+ if (!ret)
77494+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
77495+ }
77496
77497 return ret;
77498 }
77499@@ -2852,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
77500 int error = -ESRCH;
77501
77502 rcu_read_lock();
77503- p = find_task_by_vpid(pid);
77504+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77505+ /* allow glibc communication via tgkill to other threads in our
77506+ thread group */
77507+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
77508+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
77509+ p = find_task_by_vpid_unrestricted(pid);
77510+ else
77511+#endif
77512+ p = find_task_by_vpid(pid);
77513 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
77514 error = check_kill_permission(sig, info, p);
77515 /*
77516@@ -3135,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
77517 }
77518 seg = get_fs();
77519 set_fs(KERNEL_DS);
77520- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
77521- (stack_t __force __user *) &uoss,
77522+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
77523+ (stack_t __force_user *) &uoss,
77524 compat_user_stack_pointer());
77525 set_fs(seg);
77526 if (ret >= 0 && uoss_ptr) {
77527diff --git a/kernel/smp.c b/kernel/smp.c
77528index 69f38bd..77bbf12 100644
77529--- a/kernel/smp.c
77530+++ b/kernel/smp.c
77531@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
77532 return NOTIFY_OK;
77533 }
77534
77535-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
77536+static struct notifier_block hotplug_cfd_notifier = {
77537 .notifier_call = hotplug_cfd,
77538 };
77539
77540diff --git a/kernel/smpboot.c b/kernel/smpboot.c
77541index d6c5fc0..530560c 100644
77542--- a/kernel/smpboot.c
77543+++ b/kernel/smpboot.c
77544@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
77545 }
77546 smpboot_unpark_thread(plug_thread, cpu);
77547 }
77548- list_add(&plug_thread->list, &hotplug_threads);
77549+ pax_list_add(&plug_thread->list, &hotplug_threads);
77550 out:
77551 mutex_unlock(&smpboot_threads_lock);
77552 return ret;
77553@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
77554 {
77555 get_online_cpus();
77556 mutex_lock(&smpboot_threads_lock);
77557- list_del(&plug_thread->list);
77558+ pax_list_del(&plug_thread->list);
77559 smpboot_destroy_threads(plug_thread);
77560 mutex_unlock(&smpboot_threads_lock);
77561 put_online_cpus();
77562diff --git a/kernel/softirq.c b/kernel/softirq.c
77563index ed567ba..e71dabf 100644
77564--- a/kernel/softirq.c
77565+++ b/kernel/softirq.c
77566@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
77567 EXPORT_SYMBOL(irq_stat);
77568 #endif
77569
77570-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
77571+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
77572
77573 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
77574
77575-char *softirq_to_name[NR_SOFTIRQS] = {
77576+const char * const softirq_to_name[NR_SOFTIRQS] = {
77577 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
77578 "TASKLET", "SCHED", "HRTIMER", "RCU"
77579 };
77580@@ -244,7 +244,7 @@ restart:
77581 kstat_incr_softirqs_this_cpu(vec_nr);
77582
77583 trace_softirq_entry(vec_nr);
77584- h->action(h);
77585+ h->action();
77586 trace_softirq_exit(vec_nr);
77587 if (unlikely(prev_count != preempt_count())) {
77588 printk(KERN_ERR "huh, entered softirq %u %s %p"
77589@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
77590 or_softirq_pending(1UL << nr);
77591 }
77592
77593-void open_softirq(int nr, void (*action)(struct softirq_action *))
77594+void __init open_softirq(int nr, void (*action)(void))
77595 {
77596 softirq_vec[nr].action = action;
77597 }
77598@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
77599
77600 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
77601
77602-static void tasklet_action(struct softirq_action *a)
77603+static void tasklet_action(void)
77604 {
77605 struct tasklet_struct *list;
77606
77607@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
77608 }
77609 }
77610
77611-static void tasklet_hi_action(struct softirq_action *a)
77612+static void tasklet_hi_action(void)
77613 {
77614 struct tasklet_struct *list;
77615
77616@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
77617 return NOTIFY_OK;
77618 }
77619
77620-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
77621+static struct notifier_block remote_softirq_cpu_notifier = {
77622 .notifier_call = remote_softirq_cpu_notify,
77623 };
77624
77625@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
77626 return NOTIFY_OK;
77627 }
77628
77629-static struct notifier_block __cpuinitdata cpu_nfb = {
77630+static struct notifier_block cpu_nfb = {
77631 .notifier_call = cpu_callback
77632 };
77633
77634-static struct smp_hotplug_thread softirq_threads = {
77635+static struct smp_hotplug_thread softirq_threads __read_only = {
77636 .store = &ksoftirqd,
77637 .thread_should_run = ksoftirqd_should_run,
77638 .thread_fn = run_ksoftirqd,
77639diff --git a/kernel/srcu.c b/kernel/srcu.c
77640index 2b85982..d52ab26 100644
77641--- a/kernel/srcu.c
77642+++ b/kernel/srcu.c
77643@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
77644 preempt_disable();
77645 idx = rcu_dereference_index_check(sp->completed,
77646 rcu_read_lock_sched_held()) & 0x1;
77647- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77648+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77649 smp_mb(); /* B */ /* Avoid leaking the critical section. */
77650- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77651+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77652 preempt_enable();
77653 return idx;
77654 }
77655@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
77656 {
77657 preempt_disable();
77658 smp_mb(); /* C */ /* Avoid leaking the critical section. */
77659- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77660+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77661 preempt_enable();
77662 }
77663 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
77664diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
77665index 2f194e9..2c05ea9 100644
77666--- a/kernel/stop_machine.c
77667+++ b/kernel/stop_machine.c
77668@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
77669 * cpu notifiers. It currently shares the same priority as sched
77670 * migration_notifier.
77671 */
77672-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
77673+static struct notifier_block cpu_stop_cpu_notifier = {
77674 .notifier_call = cpu_stop_cpu_callback,
77675 .priority = 10,
77676 };
77677diff --git a/kernel/sys.c b/kernel/sys.c
77678index 265b376..4e42ef5 100644
77679--- a/kernel/sys.c
77680+++ b/kernel/sys.c
77681@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
77682 error = -EACCES;
77683 goto out;
77684 }
77685+
77686+ if (gr_handle_chroot_setpriority(p, niceval)) {
77687+ error = -EACCES;
77688+ goto out;
77689+ }
77690+
77691 no_nice = security_task_setnice(p, niceval);
77692 if (no_nice) {
77693 error = no_nice;
77694@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
77695 goto error;
77696 }
77697
77698+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
77699+ goto error;
77700+
77701 if (rgid != (gid_t) -1 ||
77702 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
77703 new->sgid = new->egid;
77704@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
77705 old = current_cred();
77706
77707 retval = -EPERM;
77708+
77709+ if (gr_check_group_change(kgid, kgid, kgid))
77710+ goto error;
77711+
77712 if (nsown_capable(CAP_SETGID))
77713 new->gid = new->egid = new->sgid = new->fsgid = kgid;
77714 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
77715@@ -647,7 +660,7 @@ error:
77716 /*
77717 * change the user struct in a credentials set to match the new UID
77718 */
77719-static int set_user(struct cred *new)
77720+int set_user(struct cred *new)
77721 {
77722 struct user_struct *new_user;
77723
77724@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
77725 goto error;
77726 }
77727
77728+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
77729+ goto error;
77730+
77731 if (!uid_eq(new->uid, old->uid)) {
77732 retval = set_user(new);
77733 if (retval < 0)
77734@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
77735 old = current_cred();
77736
77737 retval = -EPERM;
77738+
77739+ if (gr_check_crash_uid(kuid))
77740+ goto error;
77741+ if (gr_check_user_change(kuid, kuid, kuid))
77742+ goto error;
77743+
77744 if (nsown_capable(CAP_SETUID)) {
77745 new->suid = new->uid = kuid;
77746 if (!uid_eq(kuid, old->uid)) {
77747@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
77748 goto error;
77749 }
77750
77751+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
77752+ goto error;
77753+
77754 if (ruid != (uid_t) -1) {
77755 new->uid = kruid;
77756 if (!uid_eq(kruid, old->uid)) {
77757@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
77758 goto error;
77759 }
77760
77761+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
77762+ goto error;
77763+
77764 if (rgid != (gid_t) -1)
77765 new->gid = krgid;
77766 if (egid != (gid_t) -1)
77767@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77768 if (!uid_valid(kuid))
77769 return old_fsuid;
77770
77771+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
77772+ goto error;
77773+
77774 new = prepare_creds();
77775 if (!new)
77776 return old_fsuid;
77777@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77778 }
77779 }
77780
77781+error:
77782 abort_creds(new);
77783 return old_fsuid;
77784
77785@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
77786 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
77787 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
77788 nsown_capable(CAP_SETGID)) {
77789+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
77790+ goto error;
77791+
77792 if (!gid_eq(kgid, old->fsgid)) {
77793 new->fsgid = kgid;
77794 goto change_okay;
77795 }
77796 }
77797
77798+error:
77799 abort_creds(new);
77800 return old_fsgid;
77801
77802@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
77803 return -EFAULT;
77804
77805 down_read(&uts_sem);
77806- error = __copy_to_user(&name->sysname, &utsname()->sysname,
77807+ error = __copy_to_user(name->sysname, &utsname()->sysname,
77808 __OLD_UTS_LEN);
77809 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
77810- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
77811+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
77812 __OLD_UTS_LEN);
77813 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
77814- error |= __copy_to_user(&name->release, &utsname()->release,
77815+ error |= __copy_to_user(name->release, &utsname()->release,
77816 __OLD_UTS_LEN);
77817 error |= __put_user(0, name->release + __OLD_UTS_LEN);
77818- error |= __copy_to_user(&name->version, &utsname()->version,
77819+ error |= __copy_to_user(name->version, &utsname()->version,
77820 __OLD_UTS_LEN);
77821 error |= __put_user(0, name->version + __OLD_UTS_LEN);
77822- error |= __copy_to_user(&name->machine, &utsname()->machine,
77823+ error |= __copy_to_user(name->machine, &utsname()->machine,
77824 __OLD_UTS_LEN);
77825 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
77826 up_read(&uts_sem);
77827@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
77828 error = get_dumpable(me->mm);
77829 break;
77830 case PR_SET_DUMPABLE:
77831- if (arg2 < 0 || arg2 > 1) {
77832+ if (arg2 > 1) {
77833 error = -EINVAL;
77834 break;
77835 }
77836diff --git a/kernel/sysctl.c b/kernel/sysctl.c
77837index c88878d..e4fa5d1 100644
77838--- a/kernel/sysctl.c
77839+++ b/kernel/sysctl.c
77840@@ -92,7 +92,6 @@
77841
77842
77843 #if defined(CONFIG_SYSCTL)
77844-
77845 /* External variables not in a header file. */
77846 extern int sysctl_overcommit_memory;
77847 extern int sysctl_overcommit_ratio;
77848@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
77849 void __user *buffer, size_t *lenp, loff_t *ppos);
77850 #endif
77851
77852-#ifdef CONFIG_PRINTK
77853 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77854 void __user *buffer, size_t *lenp, loff_t *ppos);
77855-#endif
77856
77857 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
77858 void __user *buffer, size_t *lenp, loff_t *ppos);
77859@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
77860
77861 #endif
77862
77863+extern struct ctl_table grsecurity_table[];
77864+
77865 static struct ctl_table kern_table[];
77866 static struct ctl_table vm_table[];
77867 static struct ctl_table fs_table[];
77868@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
77869 int sysctl_legacy_va_layout;
77870 #endif
77871
77872+#ifdef CONFIG_PAX_SOFTMODE
77873+static ctl_table pax_table[] = {
77874+ {
77875+ .procname = "softmode",
77876+ .data = &pax_softmode,
77877+ .maxlen = sizeof(unsigned int),
77878+ .mode = 0600,
77879+ .proc_handler = &proc_dointvec,
77880+ },
77881+
77882+ { }
77883+};
77884+#endif
77885+
77886 /* The default sysctl tables: */
77887
77888 static struct ctl_table sysctl_base_table[] = {
77889@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
77890 #endif
77891
77892 static struct ctl_table kern_table[] = {
77893+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
77894+ {
77895+ .procname = "grsecurity",
77896+ .mode = 0500,
77897+ .child = grsecurity_table,
77898+ },
77899+#endif
77900+
77901+#ifdef CONFIG_PAX_SOFTMODE
77902+ {
77903+ .procname = "pax",
77904+ .mode = 0500,
77905+ .child = pax_table,
77906+ },
77907+#endif
77908+
77909 {
77910 .procname = "sched_child_runs_first",
77911 .data = &sysctl_sched_child_runs_first,
77912@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
77913 .data = &modprobe_path,
77914 .maxlen = KMOD_PATH_LEN,
77915 .mode = 0644,
77916- .proc_handler = proc_dostring,
77917+ .proc_handler = proc_dostring_modpriv,
77918 },
77919 {
77920 .procname = "modules_disabled",
77921@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
77922 .extra1 = &zero,
77923 .extra2 = &one,
77924 },
77925+#endif
77926 {
77927 .procname = "kptr_restrict",
77928 .data = &kptr_restrict,
77929 .maxlen = sizeof(int),
77930 .mode = 0644,
77931 .proc_handler = proc_dointvec_minmax_sysadmin,
77932+#ifdef CONFIG_GRKERNSEC_HIDESYM
77933+ .extra1 = &two,
77934+#else
77935 .extra1 = &zero,
77936+#endif
77937 .extra2 = &two,
77938 },
77939-#endif
77940 {
77941 .procname = "ngroups_max",
77942 .data = &ngroups_max,
77943@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
77944 .proc_handler = proc_dointvec_minmax,
77945 .extra1 = &zero,
77946 },
77947+ {
77948+ .procname = "heap_stack_gap",
77949+ .data = &sysctl_heap_stack_gap,
77950+ .maxlen = sizeof(sysctl_heap_stack_gap),
77951+ .mode = 0644,
77952+ .proc_handler = proc_doulongvec_minmax,
77953+ },
77954 #else
77955 {
77956 .procname = "nr_trim_pages",
77957@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
77958 buffer, lenp, ppos);
77959 }
77960
77961+int proc_dostring_modpriv(struct ctl_table *table, int write,
77962+ void __user *buffer, size_t *lenp, loff_t *ppos)
77963+{
77964+ if (write && !capable(CAP_SYS_MODULE))
77965+ return -EPERM;
77966+
77967+ return _proc_do_string(table->data, table->maxlen, write,
77968+ buffer, lenp, ppos);
77969+}
77970+
77971 static size_t proc_skip_spaces(char **buf)
77972 {
77973 size_t ret;
77974@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
77975 len = strlen(tmp);
77976 if (len > *size)
77977 len = *size;
77978+ if (len > sizeof(tmp))
77979+ len = sizeof(tmp);
77980 if (copy_to_user(*buf, tmp, len))
77981 return -EFAULT;
77982 *size -= len;
77983@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
77984 static int proc_taint(struct ctl_table *table, int write,
77985 void __user *buffer, size_t *lenp, loff_t *ppos)
77986 {
77987- struct ctl_table t;
77988+ ctl_table_no_const t;
77989 unsigned long tmptaint = get_taint();
77990 int err;
77991
77992@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
77993 return err;
77994 }
77995
77996-#ifdef CONFIG_PRINTK
77997 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77998 void __user *buffer, size_t *lenp, loff_t *ppos)
77999 {
78000@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78001
78002 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
78003 }
78004-#endif
78005
78006 struct do_proc_dointvec_minmax_conv_param {
78007 int *min;
78008@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
78009 *i = val;
78010 } else {
78011 val = convdiv * (*i) / convmul;
78012- if (!first)
78013+ if (!first) {
78014 err = proc_put_char(&buffer, &left, '\t');
78015+ if (err)
78016+ break;
78017+ }
78018 err = proc_put_long(&buffer, &left, val, false);
78019 if (err)
78020 break;
78021@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
78022 return -ENOSYS;
78023 }
78024
78025+int proc_dostring_modpriv(struct ctl_table *table, int write,
78026+ void __user *buffer, size_t *lenp, loff_t *ppos)
78027+{
78028+ return -ENOSYS;
78029+}
78030+
78031 int proc_dointvec(struct ctl_table *table, int write,
78032 void __user *buffer, size_t *lenp, loff_t *ppos)
78033 {
78034@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
78035 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
78036 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
78037 EXPORT_SYMBOL(proc_dostring);
78038+EXPORT_SYMBOL(proc_dostring_modpriv);
78039 EXPORT_SYMBOL(proc_doulongvec_minmax);
78040 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
78041diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
78042index 0ddf3a0..a199f50 100644
78043--- a/kernel/sysctl_binary.c
78044+++ b/kernel/sysctl_binary.c
78045@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
78046 int i;
78047
78048 set_fs(KERNEL_DS);
78049- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
78050+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
78051 set_fs(old_fs);
78052 if (result < 0)
78053 goto out_kfree;
78054@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
78055 }
78056
78057 set_fs(KERNEL_DS);
78058- result = vfs_write(file, buffer, str - buffer, &pos);
78059+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
78060 set_fs(old_fs);
78061 if (result < 0)
78062 goto out_kfree;
78063@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
78064 int i;
78065
78066 set_fs(KERNEL_DS);
78067- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
78068+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
78069 set_fs(old_fs);
78070 if (result < 0)
78071 goto out_kfree;
78072@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
78073 }
78074
78075 set_fs(KERNEL_DS);
78076- result = vfs_write(file, buffer, str - buffer, &pos);
78077+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
78078 set_fs(old_fs);
78079 if (result < 0)
78080 goto out_kfree;
78081@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
78082 int i;
78083
78084 set_fs(KERNEL_DS);
78085- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
78086+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
78087 set_fs(old_fs);
78088 if (result < 0)
78089 goto out;
78090@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
78091 __le16 dnaddr;
78092
78093 set_fs(KERNEL_DS);
78094- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
78095+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
78096 set_fs(old_fs);
78097 if (result < 0)
78098 goto out;
78099@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
78100 le16_to_cpu(dnaddr) & 0x3ff);
78101
78102 set_fs(KERNEL_DS);
78103- result = vfs_write(file, buf, len, &pos);
78104+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
78105 set_fs(old_fs);
78106 if (result < 0)
78107 goto out;
78108diff --git a/kernel/taskstats.c b/kernel/taskstats.c
78109index 145bb4d..b2aa969 100644
78110--- a/kernel/taskstats.c
78111+++ b/kernel/taskstats.c
78112@@ -28,9 +28,12 @@
78113 #include <linux/fs.h>
78114 #include <linux/file.h>
78115 #include <linux/pid_namespace.h>
78116+#include <linux/grsecurity.h>
78117 #include <net/genetlink.h>
78118 #include <linux/atomic.h>
78119
78120+extern int gr_is_taskstats_denied(int pid);
78121+
78122 /*
78123 * Maximum length of a cpumask that can be specified in
78124 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
78125@@ -570,6 +573,9 @@ err:
78126
78127 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
78128 {
78129+ if (gr_is_taskstats_denied(current->pid))
78130+ return -EACCES;
78131+
78132 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
78133 return cmd_attr_register_cpumask(info);
78134 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
78135diff --git a/kernel/time.c b/kernel/time.c
78136index d226c6a..2f0d217 100644
78137--- a/kernel/time.c
78138+++ b/kernel/time.c
78139@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
78140 return error;
78141
78142 if (tz) {
78143+ /* we log in do_settimeofday called below, so don't log twice
78144+ */
78145+ if (!tv)
78146+ gr_log_timechange();
78147+
78148 sys_tz = *tz;
78149 update_vsyscall_tz();
78150 if (firsttime) {
78151@@ -493,7 +498,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
78152 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
78153 * value to a scaled second value.
78154 */
78155-unsigned long
78156+unsigned long __intentional_overflow(-1)
78157 timespec_to_jiffies(const struct timespec *value)
78158 {
78159 unsigned long sec = value->tv_sec;
78160diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
78161index f11d83b..d016d91 100644
78162--- a/kernel/time/alarmtimer.c
78163+++ b/kernel/time/alarmtimer.c
78164@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
78165 struct platform_device *pdev;
78166 int error = 0;
78167 int i;
78168- struct k_clock alarm_clock = {
78169+ static struct k_clock alarm_clock = {
78170 .clock_getres = alarm_clock_getres,
78171 .clock_get = alarm_clock_get,
78172 .timer_create = alarm_timer_create,
78173diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
78174index f113755..ec24223 100644
78175--- a/kernel/time/tick-broadcast.c
78176+++ b/kernel/time/tick-broadcast.c
78177@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
78178 * then clear the broadcast bit.
78179 */
78180 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
78181- int cpu = smp_processor_id();
78182+ cpu = smp_processor_id();
78183
78184 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
78185 tick_broadcast_clear_oneshot(cpu);
78186diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
78187index cbc6acb..3a77191 100644
78188--- a/kernel/time/timekeeping.c
78189+++ b/kernel/time/timekeeping.c
78190@@ -15,6 +15,7 @@
78191 #include <linux/init.h>
78192 #include <linux/mm.h>
78193 #include <linux/sched.h>
78194+#include <linux/grsecurity.h>
78195 #include <linux/syscore_ops.h>
78196 #include <linux/clocksource.h>
78197 #include <linux/jiffies.h>
78198@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
78199 if (!timespec_valid_strict(tv))
78200 return -EINVAL;
78201
78202+ gr_log_timechange();
78203+
78204 write_seqlock_irqsave(&tk->lock, flags);
78205
78206 timekeeping_forward_now(tk);
78207diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
78208index af5a7e9..715611a 100644
78209--- a/kernel/time/timer_list.c
78210+++ b/kernel/time/timer_list.c
78211@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
78212
78213 static void print_name_offset(struct seq_file *m, void *sym)
78214 {
78215+#ifdef CONFIG_GRKERNSEC_HIDESYM
78216+ SEQ_printf(m, "<%p>", NULL);
78217+#else
78218 char symname[KSYM_NAME_LEN];
78219
78220 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
78221 SEQ_printf(m, "<%pK>", sym);
78222 else
78223 SEQ_printf(m, "%s", symname);
78224+#endif
78225 }
78226
78227 static void
78228@@ -112,7 +116,11 @@ next_one:
78229 static void
78230 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
78231 {
78232+#ifdef CONFIG_GRKERNSEC_HIDESYM
78233+ SEQ_printf(m, " .base: %p\n", NULL);
78234+#else
78235 SEQ_printf(m, " .base: %pK\n", base);
78236+#endif
78237 SEQ_printf(m, " .index: %d\n",
78238 base->index);
78239 SEQ_printf(m, " .resolution: %Lu nsecs\n",
78240@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
78241 {
78242 struct proc_dir_entry *pe;
78243
78244+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78245+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
78246+#else
78247 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
78248+#endif
78249 if (!pe)
78250 return -ENOMEM;
78251 return 0;
78252diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
78253index 0b537f2..40d6c20 100644
78254--- a/kernel/time/timer_stats.c
78255+++ b/kernel/time/timer_stats.c
78256@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
78257 static unsigned long nr_entries;
78258 static struct entry entries[MAX_ENTRIES];
78259
78260-static atomic_t overflow_count;
78261+static atomic_unchecked_t overflow_count;
78262
78263 /*
78264 * The entries are in a hash-table, for fast lookup:
78265@@ -140,7 +140,7 @@ static void reset_entries(void)
78266 nr_entries = 0;
78267 memset(entries, 0, sizeof(entries));
78268 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
78269- atomic_set(&overflow_count, 0);
78270+ atomic_set_unchecked(&overflow_count, 0);
78271 }
78272
78273 static struct entry *alloc_entry(void)
78274@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
78275 if (likely(entry))
78276 entry->count++;
78277 else
78278- atomic_inc(&overflow_count);
78279+ atomic_inc_unchecked(&overflow_count);
78280
78281 out_unlock:
78282 raw_spin_unlock_irqrestore(lock, flags);
78283@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
78284
78285 static void print_name_offset(struct seq_file *m, unsigned long addr)
78286 {
78287+#ifdef CONFIG_GRKERNSEC_HIDESYM
78288+ seq_printf(m, "<%p>", NULL);
78289+#else
78290 char symname[KSYM_NAME_LEN];
78291
78292 if (lookup_symbol_name(addr, symname) < 0)
78293- seq_printf(m, "<%p>", (void *)addr);
78294+ seq_printf(m, "<%pK>", (void *)addr);
78295 else
78296 seq_printf(m, "%s", symname);
78297+#endif
78298 }
78299
78300 static int tstats_show(struct seq_file *m, void *v)
78301@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
78302
78303 seq_puts(m, "Timer Stats Version: v0.2\n");
78304 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
78305- if (atomic_read(&overflow_count))
78306+ if (atomic_read_unchecked(&overflow_count))
78307 seq_printf(m, "Overflow: %d entries\n",
78308- atomic_read(&overflow_count));
78309+ atomic_read_unchecked(&overflow_count));
78310
78311 for (i = 0; i < nr_entries; i++) {
78312 entry = entries + i;
78313@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
78314 {
78315 struct proc_dir_entry *pe;
78316
78317+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78318+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
78319+#else
78320 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
78321+#endif
78322 if (!pe)
78323 return -ENOMEM;
78324 return 0;
78325diff --git a/kernel/timer.c b/kernel/timer.c
78326index 367d008..5dee98f 100644
78327--- a/kernel/timer.c
78328+++ b/kernel/timer.c
78329@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
78330 /*
78331 * This function runs timers and the timer-tq in bottom half context.
78332 */
78333-static void run_timer_softirq(struct softirq_action *h)
78334+static void run_timer_softirq(void)
78335 {
78336 struct tvec_base *base = __this_cpu_read(tvec_bases);
78337
78338@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
78339 *
78340 * In all cases the return value is guaranteed to be non-negative.
78341 */
78342-signed long __sched schedule_timeout(signed long timeout)
78343+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
78344 {
78345 struct timer_list timer;
78346 unsigned long expire;
78347@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
78348 return NOTIFY_OK;
78349 }
78350
78351-static struct notifier_block __cpuinitdata timers_nb = {
78352+static struct notifier_block timers_nb = {
78353 .notifier_call = timer_cpu_notify,
78354 };
78355
78356diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
78357index c0bd030..62a1927 100644
78358--- a/kernel/trace/blktrace.c
78359+++ b/kernel/trace/blktrace.c
78360@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
78361 struct blk_trace *bt = filp->private_data;
78362 char buf[16];
78363
78364- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
78365+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
78366
78367 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
78368 }
78369@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
78370 return 1;
78371
78372 bt = buf->chan->private_data;
78373- atomic_inc(&bt->dropped);
78374+ atomic_inc_unchecked(&bt->dropped);
78375 return 0;
78376 }
78377
78378@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
78379
78380 bt->dir = dir;
78381 bt->dev = dev;
78382- atomic_set(&bt->dropped, 0);
78383+ atomic_set_unchecked(&bt->dropped, 0);
78384
78385 ret = -EIO;
78386 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
78387diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
78388index 43defd1..76da436 100644
78389--- a/kernel/trace/ftrace.c
78390+++ b/kernel/trace/ftrace.c
78391@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
78392 if (unlikely(ftrace_disabled))
78393 return 0;
78394
78395+ ret = ftrace_arch_code_modify_prepare();
78396+ FTRACE_WARN_ON(ret);
78397+ if (ret)
78398+ return 0;
78399+
78400 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
78401+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
78402 if (ret) {
78403 ftrace_bug(ret, ip);
78404- return 0;
78405 }
78406- return 1;
78407+ return ret ? 0 : 1;
78408 }
78409
78410 /*
78411@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
78412
78413 int
78414 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
78415- void *data)
78416+ void *data)
78417 {
78418 struct ftrace_func_probe *entry;
78419 struct ftrace_page *pg;
78420@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
78421 if (!count)
78422 return 0;
78423
78424+ pax_open_kernel();
78425 sort(start, count, sizeof(*start),
78426 ftrace_cmp_ips, ftrace_swap_ips);
78427+ pax_close_kernel();
78428
78429 start_pg = ftrace_allocate_pages(count);
78430 if (!start_pg)
78431@@ -4559,8 +4566,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
78432 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
78433
78434 static int ftrace_graph_active;
78435-static struct notifier_block ftrace_suspend_notifier;
78436-
78437 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
78438 {
78439 return 0;
78440@@ -4704,6 +4709,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
78441 return NOTIFY_DONE;
78442 }
78443
78444+static struct notifier_block ftrace_suspend_notifier = {
78445+ .notifier_call = ftrace_suspend_notifier_call
78446+};
78447+
78448 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
78449 trace_func_graph_ent_t entryfunc)
78450 {
78451@@ -4717,7 +4726,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
78452 goto out;
78453 }
78454
78455- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
78456 register_pm_notifier(&ftrace_suspend_notifier);
78457
78458 ftrace_graph_active++;
78459diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
78460index ce8514f..8233573 100644
78461--- a/kernel/trace/ring_buffer.c
78462+++ b/kernel/trace/ring_buffer.c
78463@@ -346,9 +346,9 @@ struct buffer_data_page {
78464 */
78465 struct buffer_page {
78466 struct list_head list; /* list of buffer pages */
78467- local_t write; /* index for next write */
78468+ local_unchecked_t write; /* index for next write */
78469 unsigned read; /* index for next read */
78470- local_t entries; /* entries on this page */
78471+ local_unchecked_t entries; /* entries on this page */
78472 unsigned long real_end; /* real end of data */
78473 struct buffer_data_page *page; /* Actual data page */
78474 };
78475@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
78476 unsigned long last_overrun;
78477 local_t entries_bytes;
78478 local_t entries;
78479- local_t overrun;
78480- local_t commit_overrun;
78481+ local_unchecked_t overrun;
78482+ local_unchecked_t commit_overrun;
78483 local_t dropped_events;
78484 local_t committing;
78485 local_t commits;
78486@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
78487 *
78488 * We add a counter to the write field to denote this.
78489 */
78490- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
78491- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
78492+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
78493+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
78494
78495 /*
78496 * Just make sure we have seen our old_write and synchronize
78497@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
78498 * cmpxchg to only update if an interrupt did not already
78499 * do it for us. If the cmpxchg fails, we don't care.
78500 */
78501- (void)local_cmpxchg(&next_page->write, old_write, val);
78502- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
78503+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
78504+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
78505
78506 /*
78507 * No need to worry about races with clearing out the commit.
78508@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
78509
78510 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
78511 {
78512- return local_read(&bpage->entries) & RB_WRITE_MASK;
78513+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
78514 }
78515
78516 static inline unsigned long rb_page_write(struct buffer_page *bpage)
78517 {
78518- return local_read(&bpage->write) & RB_WRITE_MASK;
78519+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
78520 }
78521
78522 static int
78523@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
78524 * bytes consumed in ring buffer from here.
78525 * Increment overrun to account for the lost events.
78526 */
78527- local_add(page_entries, &cpu_buffer->overrun);
78528+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
78529 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
78530 }
78531
78532@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
78533 * it is our responsibility to update
78534 * the counters.
78535 */
78536- local_add(entries, &cpu_buffer->overrun);
78537+ local_add_unchecked(entries, &cpu_buffer->overrun);
78538 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
78539
78540 /*
78541@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78542 if (tail == BUF_PAGE_SIZE)
78543 tail_page->real_end = 0;
78544
78545- local_sub(length, &tail_page->write);
78546+ local_sub_unchecked(length, &tail_page->write);
78547 return;
78548 }
78549
78550@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78551 rb_event_set_padding(event);
78552
78553 /* Set the write back to the previous setting */
78554- local_sub(length, &tail_page->write);
78555+ local_sub_unchecked(length, &tail_page->write);
78556 return;
78557 }
78558
78559@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
78560
78561 /* Set write to end of buffer */
78562 length = (tail + length) - BUF_PAGE_SIZE;
78563- local_sub(length, &tail_page->write);
78564+ local_sub_unchecked(length, &tail_page->write);
78565 }
78566
78567 /*
78568@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
78569 * about it.
78570 */
78571 if (unlikely(next_page == commit_page)) {
78572- local_inc(&cpu_buffer->commit_overrun);
78573+ local_inc_unchecked(&cpu_buffer->commit_overrun);
78574 goto out_reset;
78575 }
78576
78577@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
78578 cpu_buffer->tail_page) &&
78579 (cpu_buffer->commit_page ==
78580 cpu_buffer->reader_page))) {
78581- local_inc(&cpu_buffer->commit_overrun);
78582+ local_inc_unchecked(&cpu_buffer->commit_overrun);
78583 goto out_reset;
78584 }
78585 }
78586@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
78587 length += RB_LEN_TIME_EXTEND;
78588
78589 tail_page = cpu_buffer->tail_page;
78590- write = local_add_return(length, &tail_page->write);
78591+ write = local_add_return_unchecked(length, &tail_page->write);
78592
78593 /* set write to only the index of the write */
78594 write &= RB_WRITE_MASK;
78595@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
78596 kmemcheck_annotate_bitfield(event, bitfield);
78597 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
78598
78599- local_inc(&tail_page->entries);
78600+ local_inc_unchecked(&tail_page->entries);
78601
78602 /*
78603 * If this is the first commit on the page, then update
78604@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
78605
78606 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
78607 unsigned long write_mask =
78608- local_read(&bpage->write) & ~RB_WRITE_MASK;
78609+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
78610 unsigned long event_length = rb_event_length(event);
78611 /*
78612 * This is on the tail page. It is possible that
78613@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
78614 */
78615 old_index += write_mask;
78616 new_index += write_mask;
78617- index = local_cmpxchg(&bpage->write, old_index, new_index);
78618+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
78619 if (index == old_index) {
78620 /* update counters */
78621 local_sub(event_length, &cpu_buffer->entries_bytes);
78622@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
78623
78624 /* Do the likely case first */
78625 if (likely(bpage->page == (void *)addr)) {
78626- local_dec(&bpage->entries);
78627+ local_dec_unchecked(&bpage->entries);
78628 return;
78629 }
78630
78631@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
78632 start = bpage;
78633 do {
78634 if (bpage->page == (void *)addr) {
78635- local_dec(&bpage->entries);
78636+ local_dec_unchecked(&bpage->entries);
78637 return;
78638 }
78639 rb_inc_page(cpu_buffer, &bpage);
78640@@ -2926,7 +2926,7 @@ static inline unsigned long
78641 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
78642 {
78643 return local_read(&cpu_buffer->entries) -
78644- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
78645+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
78646 }
78647
78648 /**
78649@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
78650 return 0;
78651
78652 cpu_buffer = buffer->buffers[cpu];
78653- ret = local_read(&cpu_buffer->overrun);
78654+ ret = local_read_unchecked(&cpu_buffer->overrun);
78655
78656 return ret;
78657 }
78658@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
78659 return 0;
78660
78661 cpu_buffer = buffer->buffers[cpu];
78662- ret = local_read(&cpu_buffer->commit_overrun);
78663+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
78664
78665 return ret;
78666 }
78667@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
78668 /* if you care about this being correct, lock the buffer */
78669 for_each_buffer_cpu(buffer, cpu) {
78670 cpu_buffer = buffer->buffers[cpu];
78671- overruns += local_read(&cpu_buffer->overrun);
78672+ overruns += local_read_unchecked(&cpu_buffer->overrun);
78673 }
78674
78675 return overruns;
78676@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78677 /*
78678 * Reset the reader page to size zero.
78679 */
78680- local_set(&cpu_buffer->reader_page->write, 0);
78681- local_set(&cpu_buffer->reader_page->entries, 0);
78682+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78683+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78684 local_set(&cpu_buffer->reader_page->page->commit, 0);
78685 cpu_buffer->reader_page->real_end = 0;
78686
78687@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78688 * want to compare with the last_overrun.
78689 */
78690 smp_mb();
78691- overwrite = local_read(&(cpu_buffer->overrun));
78692+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
78693
78694 /*
78695 * Here's the tricky part.
78696@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78697
78698 cpu_buffer->head_page
78699 = list_entry(cpu_buffer->pages, struct buffer_page, list);
78700- local_set(&cpu_buffer->head_page->write, 0);
78701- local_set(&cpu_buffer->head_page->entries, 0);
78702+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
78703+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
78704 local_set(&cpu_buffer->head_page->page->commit, 0);
78705
78706 cpu_buffer->head_page->read = 0;
78707@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78708
78709 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
78710 INIT_LIST_HEAD(&cpu_buffer->new_pages);
78711- local_set(&cpu_buffer->reader_page->write, 0);
78712- local_set(&cpu_buffer->reader_page->entries, 0);
78713+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78714+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78715 local_set(&cpu_buffer->reader_page->page->commit, 0);
78716 cpu_buffer->reader_page->read = 0;
78717
78718 local_set(&cpu_buffer->entries_bytes, 0);
78719- local_set(&cpu_buffer->overrun, 0);
78720- local_set(&cpu_buffer->commit_overrun, 0);
78721+ local_set_unchecked(&cpu_buffer->overrun, 0);
78722+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
78723 local_set(&cpu_buffer->dropped_events, 0);
78724 local_set(&cpu_buffer->entries, 0);
78725 local_set(&cpu_buffer->committing, 0);
78726@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
78727 rb_init_page(bpage);
78728 bpage = reader->page;
78729 reader->page = *data_page;
78730- local_set(&reader->write, 0);
78731- local_set(&reader->entries, 0);
78732+ local_set_unchecked(&reader->write, 0);
78733+ local_set_unchecked(&reader->entries, 0);
78734 reader->read = 0;
78735 *data_page = bpage;
78736
78737diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
78738index 3c13e46..883d039 100644
78739--- a/kernel/trace/trace.c
78740+++ b/kernel/trace/trace.c
78741@@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
78742 };
78743 #endif
78744
78745-static struct dentry *d_tracer;
78746-
78747 struct dentry *tracing_init_dentry(void)
78748 {
78749+ static struct dentry *d_tracer;
78750 static int once;
78751
78752 if (d_tracer)
78753@@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
78754 return d_tracer;
78755 }
78756
78757-static struct dentry *d_percpu;
78758-
78759 struct dentry *tracing_dentry_percpu(void)
78760 {
78761+ static struct dentry *d_percpu;
78762 static int once;
78763 struct dentry *d_tracer;
78764
78765diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
78766index 880073d..42db7c3 100644
78767--- a/kernel/trace/trace_events.c
78768+++ b/kernel/trace/trace_events.c
78769@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
78770 struct ftrace_module_file_ops {
78771 struct list_head list;
78772 struct module *mod;
78773- struct file_operations id;
78774- struct file_operations enable;
78775- struct file_operations format;
78776- struct file_operations filter;
78777 };
78778
78779 static struct ftrace_module_file_ops *
78780@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
78781
78782 file_ops->mod = mod;
78783
78784- file_ops->id = ftrace_event_id_fops;
78785- file_ops->id.owner = mod;
78786-
78787- file_ops->enable = ftrace_enable_fops;
78788- file_ops->enable.owner = mod;
78789-
78790- file_ops->filter = ftrace_event_filter_fops;
78791- file_ops->filter.owner = mod;
78792-
78793- file_ops->format = ftrace_event_format_fops;
78794- file_ops->format.owner = mod;
78795+ pax_open_kernel();
78796+ mod->trace_id.owner = mod;
78797+ mod->trace_enable.owner = mod;
78798+ mod->trace_filter.owner = mod;
78799+ mod->trace_format.owner = mod;
78800+ pax_close_kernel();
78801
78802 list_add(&file_ops->list, &ftrace_module_file_list);
78803
78804@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
78805
78806 for_each_event(call, start, end) {
78807 __trace_add_event_call(*call, mod,
78808- &file_ops->id, &file_ops->enable,
78809- &file_ops->filter, &file_ops->format);
78810+ &mod->trace_id, &mod->trace_enable,
78811+ &mod->trace_filter, &mod->trace_format);
78812 }
78813 }
78814
78815diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
78816index fd3c8aa..5f324a6 100644
78817--- a/kernel/trace/trace_mmiotrace.c
78818+++ b/kernel/trace/trace_mmiotrace.c
78819@@ -24,7 +24,7 @@ struct header_iter {
78820 static struct trace_array *mmio_trace_array;
78821 static bool overrun_detected;
78822 static unsigned long prev_overruns;
78823-static atomic_t dropped_count;
78824+static atomic_unchecked_t dropped_count;
78825
78826 static void mmio_reset_data(struct trace_array *tr)
78827 {
78828@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
78829
78830 static unsigned long count_overruns(struct trace_iterator *iter)
78831 {
78832- unsigned long cnt = atomic_xchg(&dropped_count, 0);
78833+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
78834 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
78835
78836 if (over > prev_overruns)
78837@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
78838 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
78839 sizeof(*entry), 0, pc);
78840 if (!event) {
78841- atomic_inc(&dropped_count);
78842+ atomic_inc_unchecked(&dropped_count);
78843 return;
78844 }
78845 entry = ring_buffer_event_data(event);
78846@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
78847 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
78848 sizeof(*entry), 0, pc);
78849 if (!event) {
78850- atomic_inc(&dropped_count);
78851+ atomic_inc_unchecked(&dropped_count);
78852 return;
78853 }
78854 entry = ring_buffer_event_data(event);
78855diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
78856index 194d796..76edb8f 100644
78857--- a/kernel/trace/trace_output.c
78858+++ b/kernel/trace/trace_output.c
78859@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
78860
78861 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
78862 if (!IS_ERR(p)) {
78863- p = mangle_path(s->buffer + s->len, p, "\n");
78864+ p = mangle_path(s->buffer + s->len, p, "\n\\");
78865 if (p) {
78866 s->len = p - s->buffer;
78867 return 1;
78868@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
78869 goto out;
78870 }
78871
78872+ pax_open_kernel();
78873 if (event->funcs->trace == NULL)
78874- event->funcs->trace = trace_nop_print;
78875+ *(void **)&event->funcs->trace = trace_nop_print;
78876 if (event->funcs->raw == NULL)
78877- event->funcs->raw = trace_nop_print;
78878+ *(void **)&event->funcs->raw = trace_nop_print;
78879 if (event->funcs->hex == NULL)
78880- event->funcs->hex = trace_nop_print;
78881+ *(void **)&event->funcs->hex = trace_nop_print;
78882 if (event->funcs->binary == NULL)
78883- event->funcs->binary = trace_nop_print;
78884+ *(void **)&event->funcs->binary = trace_nop_print;
78885+ pax_close_kernel();
78886
78887 key = event->type & (EVENT_HASHSIZE - 1);
78888
78889diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
78890index 42ca822..cdcacc6 100644
78891--- a/kernel/trace/trace_stack.c
78892+++ b/kernel/trace/trace_stack.c
78893@@ -52,7 +52,7 @@ static inline void check_stack(void)
78894 return;
78895
78896 /* we do not handle interrupt stacks yet */
78897- if (!object_is_on_stack(&this_size))
78898+ if (!object_starts_on_stack(&this_size))
78899 return;
78900
78901 local_irq_save(flags);
78902diff --git a/kernel/user.c b/kernel/user.c
78903index 33acb5e..57ebfd4 100644
78904--- a/kernel/user.c
78905+++ b/kernel/user.c
78906@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
78907 .count = 4294967295U,
78908 },
78909 },
78910- .kref = {
78911- .refcount = ATOMIC_INIT(3),
78912- },
78913+ .count = ATOMIC_INIT(3),
78914 .owner = GLOBAL_ROOT_UID,
78915 .group = GLOBAL_ROOT_GID,
78916 .proc_inum = PROC_USER_INIT_INO,
78917diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
78918index dbfe36a7..2a3c1df 100644
78919--- a/kernel/user_namespace.c
78920+++ b/kernel/user_namespace.c
78921@@ -79,7 +79,7 @@ int create_user_ns(struct cred *new)
78922 return ret;
78923 }
78924
78925- kref_init(&ns->kref);
78926+ atomic_set(&ns->count, 1);
78927 /* Leave the new->user_ns reference with the new user namespace. */
78928 ns->parent = parent_ns;
78929 ns->owner = owner;
78930@@ -105,15 +105,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
78931 return create_user_ns(cred);
78932 }
78933
78934-void free_user_ns(struct kref *kref)
78935+void free_user_ns(struct user_namespace *ns)
78936 {
78937- struct user_namespace *parent, *ns =
78938- container_of(kref, struct user_namespace, kref);
78939+ struct user_namespace *parent;
78940
78941- parent = ns->parent;
78942- proc_free_inum(ns->proc_inum);
78943- kmem_cache_free(user_ns_cachep, ns);
78944- put_user_ns(parent);
78945+ do {
78946+ parent = ns->parent;
78947+ proc_free_inum(ns->proc_inum);
78948+ kmem_cache_free(user_ns_cachep, ns);
78949+ ns = parent;
78950+ } while (atomic_dec_and_test(&parent->count));
78951 }
78952 EXPORT_SYMBOL(free_user_ns);
78953
78954@@ -804,7 +805,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
78955 if (atomic_read(&current->mm->mm_users) > 1)
78956 return -EINVAL;
78957
78958- if (current->fs->users != 1)
78959+ if (atomic_read(&current->fs->users) != 1)
78960 return -EINVAL;
78961
78962 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
78963diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
78964index 63da38c..639904e 100644
78965--- a/kernel/utsname_sysctl.c
78966+++ b/kernel/utsname_sysctl.c
78967@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
78968 static int proc_do_uts_string(ctl_table *table, int write,
78969 void __user *buffer, size_t *lenp, loff_t *ppos)
78970 {
78971- struct ctl_table uts_table;
78972+ ctl_table_no_const uts_table;
78973 int r;
78974 memcpy(&uts_table, table, sizeof(uts_table));
78975 uts_table.data = get_uts(table, write);
78976diff --git a/kernel/watchdog.c b/kernel/watchdog.c
78977index 75a2ab3..5961da7 100644
78978--- a/kernel/watchdog.c
78979+++ b/kernel/watchdog.c
78980@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
78981 }
78982 #endif /* CONFIG_SYSCTL */
78983
78984-static struct smp_hotplug_thread watchdog_threads = {
78985+static struct smp_hotplug_thread watchdog_threads __read_only = {
78986 .store = &softlockup_watchdog,
78987 .thread_should_run = watchdog_should_run,
78988 .thread_fn = watchdog,
78989diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
78990index 67604e5..fe94fb1 100644
78991--- a/lib/Kconfig.debug
78992+++ b/lib/Kconfig.debug
78993@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
78994
78995 config DEBUG_LOCK_ALLOC
78996 bool "Lock debugging: detect incorrect freeing of live locks"
78997- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78998+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78999 select DEBUG_SPINLOCK
79000 select DEBUG_MUTEXES
79001 select LOCKDEP
79002@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
79003
79004 config PROVE_LOCKING
79005 bool "Lock debugging: prove locking correctness"
79006- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79007+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79008 select LOCKDEP
79009 select DEBUG_SPINLOCK
79010 select DEBUG_MUTEXES
79011@@ -670,7 +670,7 @@ config LOCKDEP
79012
79013 config LOCK_STAT
79014 bool "Lock usage statistics"
79015- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79016+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79017 select LOCKDEP
79018 select DEBUG_SPINLOCK
79019 select DEBUG_MUTEXES
79020@@ -1278,6 +1278,7 @@ config LATENCYTOP
79021 depends on DEBUG_KERNEL
79022 depends on STACKTRACE_SUPPORT
79023 depends on PROC_FS
79024+ depends on !GRKERNSEC_HIDESYM
79025 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
79026 select KALLSYMS
79027 select KALLSYMS_ALL
79028@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
79029
79030 config PROVIDE_OHCI1394_DMA_INIT
79031 bool "Remote debugging over FireWire early on boot"
79032- depends on PCI && X86
79033+ depends on PCI && X86 && !GRKERNSEC
79034 help
79035 If you want to debug problems which hang or crash the kernel early
79036 on boot and the crashing machine has a FireWire port, you can use
79037@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
79038
79039 config FIREWIRE_OHCI_REMOTE_DMA
79040 bool "Remote debugging over FireWire with firewire-ohci"
79041- depends on FIREWIRE_OHCI
79042+ depends on FIREWIRE_OHCI && !GRKERNSEC
79043 help
79044 This option lets you use the FireWire bus for remote debugging
79045 with help of the firewire-ohci driver. It enables unfiltered
79046diff --git a/lib/Makefile b/lib/Makefile
79047index 02ed6c0..bd243da 100644
79048--- a/lib/Makefile
79049+++ b/lib/Makefile
79050@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
79051
79052 obj-$(CONFIG_BTREE) += btree.o
79053 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
79054-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
79055+obj-y += list_debug.o
79056 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
79057
79058 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
79059diff --git a/lib/bitmap.c b/lib/bitmap.c
79060index 06f7e4f..f3cf2b0 100644
79061--- a/lib/bitmap.c
79062+++ b/lib/bitmap.c
79063@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
79064 {
79065 int c, old_c, totaldigits, ndigits, nchunks, nbits;
79066 u32 chunk;
79067- const char __user __force *ubuf = (const char __user __force *)buf;
79068+ const char __user *ubuf = (const char __force_user *)buf;
79069
79070 bitmap_zero(maskp, nmaskbits);
79071
79072@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
79073 {
79074 if (!access_ok(VERIFY_READ, ubuf, ulen))
79075 return -EFAULT;
79076- return __bitmap_parse((const char __force *)ubuf,
79077+ return __bitmap_parse((const char __force_kernel *)ubuf,
79078 ulen, 1, maskp, nmaskbits);
79079
79080 }
79081@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
79082 {
79083 unsigned a, b;
79084 int c, old_c, totaldigits;
79085- const char __user __force *ubuf = (const char __user __force *)buf;
79086+ const char __user *ubuf = (const char __force_user *)buf;
79087 int exp_digit, in_range;
79088
79089 totaldigits = c = 0;
79090@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
79091 {
79092 if (!access_ok(VERIFY_READ, ubuf, ulen))
79093 return -EFAULT;
79094- return __bitmap_parselist((const char __force *)ubuf,
79095+ return __bitmap_parselist((const char __force_kernel *)ubuf,
79096 ulen, 1, maskp, nmaskbits);
79097 }
79098 EXPORT_SYMBOL(bitmap_parselist_user);
79099diff --git a/lib/bug.c b/lib/bug.c
79100index d0cdf14..4d07bd2 100644
79101--- a/lib/bug.c
79102+++ b/lib/bug.c
79103@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
79104 return BUG_TRAP_TYPE_NONE;
79105
79106 bug = find_bug(bugaddr);
79107+ if (!bug)
79108+ return BUG_TRAP_TYPE_NONE;
79109
79110 file = NULL;
79111 line = 0;
79112diff --git a/lib/debugobjects.c b/lib/debugobjects.c
79113index d11808c..dc2d6f8 100644
79114--- a/lib/debugobjects.c
79115+++ b/lib/debugobjects.c
79116@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
79117 if (limit > 4)
79118 return;
79119
79120- is_on_stack = object_is_on_stack(addr);
79121+ is_on_stack = object_starts_on_stack(addr);
79122 if (is_on_stack == onstack)
79123 return;
79124
79125diff --git a/lib/devres.c b/lib/devres.c
79126index 80b9c76..9e32279 100644
79127--- a/lib/devres.c
79128+++ b/lib/devres.c
79129@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
79130 void devm_iounmap(struct device *dev, void __iomem *addr)
79131 {
79132 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
79133- (void *)addr));
79134+ (void __force *)addr));
79135 iounmap(addr);
79136 }
79137 EXPORT_SYMBOL(devm_iounmap);
79138@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
79139 {
79140 ioport_unmap(addr);
79141 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
79142- devm_ioport_map_match, (void *)addr));
79143+ devm_ioport_map_match, (void __force *)addr));
79144 }
79145 EXPORT_SYMBOL(devm_ioport_unmap);
79146
79147diff --git a/lib/div64.c b/lib/div64.c
79148index a163b6c..9618fa5 100644
79149--- a/lib/div64.c
79150+++ b/lib/div64.c
79151@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
79152 EXPORT_SYMBOL(__div64_32);
79153
79154 #ifndef div_s64_rem
79155-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79156+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79157 {
79158 u64 quotient;
79159
79160@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
79161 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
79162 */
79163 #ifndef div64_u64
79164-u64 div64_u64(u64 dividend, u64 divisor)
79165+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79166 {
79167 u32 high = divisor >> 32;
79168 u64 quot;
79169diff --git a/lib/dma-debug.c b/lib/dma-debug.c
79170index 5e396ac..58d5de1 100644
79171--- a/lib/dma-debug.c
79172+++ b/lib/dma-debug.c
79173@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
79174
79175 void dma_debug_add_bus(struct bus_type *bus)
79176 {
79177- struct notifier_block *nb;
79178+ notifier_block_no_const *nb;
79179
79180 if (global_disable)
79181 return;
79182@@ -942,7 +942,7 @@ out:
79183
79184 static void check_for_stack(struct device *dev, void *addr)
79185 {
79186- if (object_is_on_stack(addr))
79187+ if (object_starts_on_stack(addr))
79188 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
79189 "stack [addr=%p]\n", addr);
79190 }
79191diff --git a/lib/inflate.c b/lib/inflate.c
79192index 013a761..c28f3fc 100644
79193--- a/lib/inflate.c
79194+++ b/lib/inflate.c
79195@@ -269,7 +269,7 @@ static void free(void *where)
79196 malloc_ptr = free_mem_ptr;
79197 }
79198 #else
79199-#define malloc(a) kmalloc(a, GFP_KERNEL)
79200+#define malloc(a) kmalloc((a), GFP_KERNEL)
79201 #define free(a) kfree(a)
79202 #endif
79203
79204diff --git a/lib/ioremap.c b/lib/ioremap.c
79205index 0c9216c..863bd89 100644
79206--- a/lib/ioremap.c
79207+++ b/lib/ioremap.c
79208@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
79209 unsigned long next;
79210
79211 phys_addr -= addr;
79212- pmd = pmd_alloc(&init_mm, pud, addr);
79213+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79214 if (!pmd)
79215 return -ENOMEM;
79216 do {
79217@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
79218 unsigned long next;
79219
79220 phys_addr -= addr;
79221- pud = pud_alloc(&init_mm, pgd, addr);
79222+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
79223 if (!pud)
79224 return -ENOMEM;
79225 do {
79226diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
79227index bd2bea9..6b3c95e 100644
79228--- a/lib/is_single_threaded.c
79229+++ b/lib/is_single_threaded.c
79230@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
79231 struct task_struct *p, *t;
79232 bool ret;
79233
79234+ if (!mm)
79235+ return true;
79236+
79237 if (atomic_read(&task->signal->live) != 1)
79238 return false;
79239
79240diff --git a/lib/kobject.c b/lib/kobject.c
79241index e07ee1f..998489d 100644
79242--- a/lib/kobject.c
79243+++ b/lib/kobject.c
79244@@ -852,9 +852,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
79245
79246
79247 static DEFINE_SPINLOCK(kobj_ns_type_lock);
79248-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
79249+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
79250
79251-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79252+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79253 {
79254 enum kobj_ns_type type = ops->type;
79255 int error;
79256diff --git a/lib/list_debug.c b/lib/list_debug.c
79257index c24c2f7..0475b78 100644
79258--- a/lib/list_debug.c
79259+++ b/lib/list_debug.c
79260@@ -11,7 +11,9 @@
79261 #include <linux/bug.h>
79262 #include <linux/kernel.h>
79263 #include <linux/rculist.h>
79264+#include <linux/mm.h>
79265
79266+#ifdef CONFIG_DEBUG_LIST
79267 /*
79268 * Insert a new entry between two known consecutive entries.
79269 *
79270@@ -19,21 +21,32 @@
79271 * the prev/next entries already!
79272 */
79273
79274-void __list_add(struct list_head *new,
79275- struct list_head *prev,
79276- struct list_head *next)
79277+static bool __list_add_debug(struct list_head *new,
79278+ struct list_head *prev,
79279+ struct list_head *next)
79280 {
79281- WARN(next->prev != prev,
79282+ if (WARN(next->prev != prev,
79283 "list_add corruption. next->prev should be "
79284 "prev (%p), but was %p. (next=%p).\n",
79285- prev, next->prev, next);
79286- WARN(prev->next != next,
79287+ prev, next->prev, next) ||
79288+ WARN(prev->next != next,
79289 "list_add corruption. prev->next should be "
79290 "next (%p), but was %p. (prev=%p).\n",
79291- next, prev->next, prev);
79292- WARN(new == prev || new == next,
79293+ next, prev->next, prev) ||
79294+ WARN(new == prev || new == next,
79295 "list_add double add: new=%p, prev=%p, next=%p.\n",
79296- new, prev, next);
79297+ new, prev, next))
79298+ return false;
79299+ return true;
79300+}
79301+
79302+void __list_add(struct list_head *new,
79303+ struct list_head *prev,
79304+ struct list_head *next)
79305+{
79306+ if (!__list_add_debug(new, prev, next))
79307+ return;
79308+
79309 next->prev = new;
79310 new->next = next;
79311 new->prev = prev;
79312@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
79313 }
79314 EXPORT_SYMBOL(__list_add);
79315
79316-void __list_del_entry(struct list_head *entry)
79317+static bool __list_del_entry_debug(struct list_head *entry)
79318 {
79319 struct list_head *prev, *next;
79320
79321@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
79322 WARN(next->prev != entry,
79323 "list_del corruption. next->prev should be %p, "
79324 "but was %p\n", entry, next->prev))
79325+ return false;
79326+ return true;
79327+}
79328+
79329+void __list_del_entry(struct list_head *entry)
79330+{
79331+ if (!__list_del_entry_debug(entry))
79332 return;
79333
79334- __list_del(prev, next);
79335+ __list_del(entry->prev, entry->next);
79336 }
79337 EXPORT_SYMBOL(__list_del_entry);
79338
79339@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
79340 void __list_add_rcu(struct list_head *new,
79341 struct list_head *prev, struct list_head *next)
79342 {
79343- WARN(next->prev != prev,
79344- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
79345- prev, next->prev, next);
79346- WARN(prev->next != next,
79347- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
79348- next, prev->next, prev);
79349+ if (!__list_add_debug(new, prev, next))
79350+ return;
79351+
79352 new->next = next;
79353 new->prev = prev;
79354 rcu_assign_pointer(list_next_rcu(prev), new);
79355 next->prev = new;
79356 }
79357 EXPORT_SYMBOL(__list_add_rcu);
79358+#endif
79359+
79360+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
79361+{
79362+#ifdef CONFIG_DEBUG_LIST
79363+ if (!__list_add_debug(new, prev, next))
79364+ return;
79365+#endif
79366+
79367+ pax_open_kernel();
79368+ next->prev = new;
79369+ new->next = next;
79370+ new->prev = prev;
79371+ prev->next = new;
79372+ pax_close_kernel();
79373+}
79374+EXPORT_SYMBOL(__pax_list_add);
79375+
79376+void pax_list_del(struct list_head *entry)
79377+{
79378+#ifdef CONFIG_DEBUG_LIST
79379+ if (!__list_del_entry_debug(entry))
79380+ return;
79381+#endif
79382+
79383+ pax_open_kernel();
79384+ __list_del(entry->prev, entry->next);
79385+ entry->next = LIST_POISON1;
79386+ entry->prev = LIST_POISON2;
79387+ pax_close_kernel();
79388+}
79389+EXPORT_SYMBOL(pax_list_del);
79390+
79391+void pax_list_del_init(struct list_head *entry)
79392+{
79393+ pax_open_kernel();
79394+ __list_del(entry->prev, entry->next);
79395+ INIT_LIST_HEAD(entry);
79396+ pax_close_kernel();
79397+}
79398+EXPORT_SYMBOL(pax_list_del_init);
79399+
79400+void __pax_list_add_rcu(struct list_head *new,
79401+ struct list_head *prev, struct list_head *next)
79402+{
79403+#ifdef CONFIG_DEBUG_LIST
79404+ if (!__list_add_debug(new, prev, next))
79405+ return;
79406+#endif
79407+
79408+ pax_open_kernel();
79409+ new->next = next;
79410+ new->prev = prev;
79411+ rcu_assign_pointer(list_next_rcu(prev), new);
79412+ next->prev = new;
79413+ pax_close_kernel();
79414+}
79415+EXPORT_SYMBOL(__pax_list_add_rcu);
79416+
79417+void pax_list_del_rcu(struct list_head *entry)
79418+{
79419+#ifdef CONFIG_DEBUG_LIST
79420+ if (!__list_del_entry_debug(entry))
79421+ return;
79422+#endif
79423+
79424+ pax_open_kernel();
79425+ __list_del(entry->prev, entry->next);
79426+ entry->next = LIST_POISON1;
79427+ entry->prev = LIST_POISON2;
79428+ pax_close_kernel();
79429+}
79430+EXPORT_SYMBOL(pax_list_del_rcu);
79431diff --git a/lib/radix-tree.c b/lib/radix-tree.c
79432index e796429..6e38f9f 100644
79433--- a/lib/radix-tree.c
79434+++ b/lib/radix-tree.c
79435@@ -92,7 +92,7 @@ struct radix_tree_preload {
79436 int nr;
79437 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
79438 };
79439-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
79440+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
79441
79442 static inline void *ptr_to_indirect(void *ptr)
79443 {
79444diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
79445index bb2b201..46abaf9 100644
79446--- a/lib/strncpy_from_user.c
79447+++ b/lib/strncpy_from_user.c
79448@@ -21,7 +21,7 @@
79449 */
79450 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
79451 {
79452- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79453+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79454 long res = 0;
79455
79456 /*
79457diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
79458index a28df52..3d55877 100644
79459--- a/lib/strnlen_user.c
79460+++ b/lib/strnlen_user.c
79461@@ -26,7 +26,7 @@
79462 */
79463 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
79464 {
79465- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79466+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
79467 long align, res = 0;
79468 unsigned long c;
79469
79470diff --git a/lib/swiotlb.c b/lib/swiotlb.c
79471index 196b069..358f342 100644
79472--- a/lib/swiotlb.c
79473+++ b/lib/swiotlb.c
79474@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
79475
79476 void
79477 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
79478- dma_addr_t dev_addr)
79479+ dma_addr_t dev_addr, struct dma_attrs *attrs)
79480 {
79481 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
79482
79483diff --git a/lib/vsprintf.c b/lib/vsprintf.c
79484index fab33a9..3b5fe68 100644
79485--- a/lib/vsprintf.c
79486+++ b/lib/vsprintf.c
79487@@ -16,6 +16,9 @@
79488 * - scnprintf and vscnprintf
79489 */
79490
79491+#ifdef CONFIG_GRKERNSEC_HIDESYM
79492+#define __INCLUDED_BY_HIDESYM 1
79493+#endif
79494 #include <stdarg.h>
79495 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
79496 #include <linux/types.h>
79497@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
79498 char sym[KSYM_SYMBOL_LEN];
79499 if (ext == 'B')
79500 sprint_backtrace(sym, value);
79501- else if (ext != 'f' && ext != 's')
79502+ else if (ext != 'f' && ext != 's' && ext != 'a')
79503 sprint_symbol(sym, value);
79504 else
79505 sprint_symbol_no_offset(sym, value);
79506@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
79507 return number(buf, end, *(const netdev_features_t *)addr, spec);
79508 }
79509
79510+#ifdef CONFIG_GRKERNSEC_HIDESYM
79511+int kptr_restrict __read_mostly = 2;
79512+#else
79513 int kptr_restrict __read_mostly;
79514+#endif
79515
79516 /*
79517 * Show a '%p' thing. A kernel extension is that the '%p' is followed
79518@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
79519 * - 'S' For symbolic direct pointers with offset
79520 * - 's' For symbolic direct pointers without offset
79521 * - 'B' For backtraced symbolic direct pointers with offset
79522+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
79523+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
79524 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
79525 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
79526 * - 'M' For a 6-byte MAC address, it prints the address in the
79527@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79528
79529 if (!ptr && *fmt != 'K') {
79530 /*
79531- * Print (null) with the same width as a pointer so it makes
79532+ * Print (nil) with the same width as a pointer so it makes
79533 * tabular output look nice.
79534 */
79535 if (spec.field_width == -1)
79536 spec.field_width = default_width;
79537- return string(buf, end, "(null)", spec);
79538+ return string(buf, end, "(nil)", spec);
79539 }
79540
79541 switch (*fmt) {
79542@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79543 /* Fallthrough */
79544 case 'S':
79545 case 's':
79546+#ifdef CONFIG_GRKERNSEC_HIDESYM
79547+ break;
79548+#else
79549+ return symbol_string(buf, end, ptr, spec, *fmt);
79550+#endif
79551+ case 'A':
79552+ case 'a':
79553 case 'B':
79554 return symbol_string(buf, end, ptr, spec, *fmt);
79555 case 'R':
79556@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79557 va_end(va);
79558 return buf;
79559 }
79560+ case 'P':
79561+ break;
79562 case 'K':
79563 /*
79564 * %pK cannot be used in IRQ context because its test
79565@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
79566 }
79567 break;
79568 }
79569+
79570+#ifdef CONFIG_GRKERNSEC_HIDESYM
79571+ /* 'P' = approved pointers to copy to userland,
79572+ as in the /proc/kallsyms case, as we make it display nothing
79573+ for non-root users, and the real contents for root users
79574+ Also ignore 'K' pointers, since we force their NULLing for non-root users
79575+ above
79576+ */
79577+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
79578+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
79579+ dump_stack();
79580+ ptr = NULL;
79581+ }
79582+#endif
79583+
79584 spec.flags |= SMALL;
79585 if (spec.field_width == -1) {
79586 spec.field_width = default_width;
79587@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
79588 typeof(type) value; \
79589 if (sizeof(type) == 8) { \
79590 args = PTR_ALIGN(args, sizeof(u32)); \
79591- *(u32 *)&value = *(u32 *)args; \
79592- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
79593+ *(u32 *)&value = *(const u32 *)args; \
79594+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
79595 } else { \
79596 args = PTR_ALIGN(args, sizeof(type)); \
79597- value = *(typeof(type) *)args; \
79598+ value = *(const typeof(type) *)args; \
79599 } \
79600 args += sizeof(type); \
79601 value; \
79602@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
79603 case FORMAT_TYPE_STR: {
79604 const char *str_arg = args;
79605 args += strlen(str_arg) + 1;
79606- str = string(str, end, (char *)str_arg, spec);
79607+ str = string(str, end, str_arg, spec);
79608 break;
79609 }
79610
79611diff --git a/localversion-grsec b/localversion-grsec
79612new file mode 100644
79613index 0000000..7cd6065
79614--- /dev/null
79615+++ b/localversion-grsec
79616@@ -0,0 +1 @@
79617+-grsec
79618diff --git a/mm/Kconfig b/mm/Kconfig
79619index 278e3ab..87c384d 100644
79620--- a/mm/Kconfig
79621+++ b/mm/Kconfig
79622@@ -286,10 +286,10 @@ config KSM
79623 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
79624
79625 config DEFAULT_MMAP_MIN_ADDR
79626- int "Low address space to protect from user allocation"
79627+ int "Low address space to protect from user allocation"
79628 depends on MMU
79629- default 4096
79630- help
79631+ default 65536
79632+ help
79633 This is the portion of low virtual memory which should be protected
79634 from userspace allocation. Keeping a user from writing to low pages
79635 can help reduce the impact of kernel NULL pointer bugs.
79636@@ -320,7 +320,7 @@ config MEMORY_FAILURE
79637
79638 config HWPOISON_INJECT
79639 tristate "HWPoison pages injector"
79640- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
79641+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
79642 select PROC_PAGE_MONITOR
79643
79644 config NOMMU_INITIAL_TRIM_EXCESS
79645diff --git a/mm/filemap.c b/mm/filemap.c
79646index 83efee7..3f99381 100644
79647--- a/mm/filemap.c
79648+++ b/mm/filemap.c
79649@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
79650 struct address_space *mapping = file->f_mapping;
79651
79652 if (!mapping->a_ops->readpage)
79653- return -ENOEXEC;
79654+ return -ENODEV;
79655 file_accessed(file);
79656 vma->vm_ops = &generic_file_vm_ops;
79657 return 0;
79658@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
79659 *pos = i_size_read(inode);
79660
79661 if (limit != RLIM_INFINITY) {
79662+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
79663 if (*pos >= limit) {
79664 send_sig(SIGXFSZ, current, 0);
79665 return -EFBIG;
79666diff --git a/mm/fremap.c b/mm/fremap.c
79667index a0aaf0e..20325c3 100644
79668--- a/mm/fremap.c
79669+++ b/mm/fremap.c
79670@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
79671 retry:
79672 vma = find_vma(mm, start);
79673
79674+#ifdef CONFIG_PAX_SEGMEXEC
79675+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
79676+ goto out;
79677+#endif
79678+
79679 /*
79680 * Make sure the vma is shared, that it supports prefaulting,
79681 * and that the remapped range is valid and fully within
79682diff --git a/mm/highmem.c b/mm/highmem.c
79683index b32b70c..e512eb0 100644
79684--- a/mm/highmem.c
79685+++ b/mm/highmem.c
79686@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
79687 * So no dangers, even with speculative execution.
79688 */
79689 page = pte_page(pkmap_page_table[i]);
79690+ pax_open_kernel();
79691 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
79692-
79693+ pax_close_kernel();
79694 set_page_address(page, NULL);
79695 need_flush = 1;
79696 }
79697@@ -198,9 +199,11 @@ start:
79698 }
79699 }
79700 vaddr = PKMAP_ADDR(last_pkmap_nr);
79701+
79702+ pax_open_kernel();
79703 set_pte_at(&init_mm, vaddr,
79704 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
79705-
79706+ pax_close_kernel();
79707 pkmap_count[last_pkmap_nr] = 1;
79708 set_page_address(page, (void *)vaddr);
79709
79710diff --git a/mm/hugetlb.c b/mm/hugetlb.c
79711index 546db81..34830af 100644
79712--- a/mm/hugetlb.c
79713+++ b/mm/hugetlb.c
79714@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
79715 struct hstate *h = &default_hstate;
79716 unsigned long tmp;
79717 int ret;
79718+ ctl_table_no_const hugetlb_table;
79719
79720 tmp = h->max_huge_pages;
79721
79722 if (write && h->order >= MAX_ORDER)
79723 return -EINVAL;
79724
79725- table->data = &tmp;
79726- table->maxlen = sizeof(unsigned long);
79727- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79728+ hugetlb_table = *table;
79729+ hugetlb_table.data = &tmp;
79730+ hugetlb_table.maxlen = sizeof(unsigned long);
79731+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79732 if (ret)
79733 goto out;
79734
79735@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
79736 struct hstate *h = &default_hstate;
79737 unsigned long tmp;
79738 int ret;
79739+ ctl_table_no_const hugetlb_table;
79740
79741 tmp = h->nr_overcommit_huge_pages;
79742
79743 if (write && h->order >= MAX_ORDER)
79744 return -EINVAL;
79745
79746- table->data = &tmp;
79747- table->maxlen = sizeof(unsigned long);
79748- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79749+ hugetlb_table = *table;
79750+ hugetlb_table.data = &tmp;
79751+ hugetlb_table.maxlen = sizeof(unsigned long);
79752+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79753 if (ret)
79754 goto out;
79755
79756@@ -2511,6 +2515,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
79757 return 1;
79758 }
79759
79760+#ifdef CONFIG_PAX_SEGMEXEC
79761+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
79762+{
79763+ struct mm_struct *mm = vma->vm_mm;
79764+ struct vm_area_struct *vma_m;
79765+ unsigned long address_m;
79766+ pte_t *ptep_m;
79767+
79768+ vma_m = pax_find_mirror_vma(vma);
79769+ if (!vma_m)
79770+ return;
79771+
79772+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79773+ address_m = address + SEGMEXEC_TASK_SIZE;
79774+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
79775+ get_page(page_m);
79776+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
79777+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
79778+}
79779+#endif
79780+
79781 /*
79782 * Hugetlb_cow() should be called with page lock of the original hugepage held.
79783 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
79784@@ -2629,6 +2654,11 @@ retry_avoidcopy:
79785 make_huge_pte(vma, new_page, 1));
79786 page_remove_rmap(old_page);
79787 hugepage_add_new_anon_rmap(new_page, vma, address);
79788+
79789+#ifdef CONFIG_PAX_SEGMEXEC
79790+ pax_mirror_huge_pte(vma, address, new_page);
79791+#endif
79792+
79793 /* Make the old page be freed below */
79794 new_page = old_page;
79795 }
79796@@ -2788,6 +2818,10 @@ retry:
79797 && (vma->vm_flags & VM_SHARED)));
79798 set_huge_pte_at(mm, address, ptep, new_pte);
79799
79800+#ifdef CONFIG_PAX_SEGMEXEC
79801+ pax_mirror_huge_pte(vma, address, page);
79802+#endif
79803+
79804 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
79805 /* Optimization, do the COW without a second fault */
79806 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
79807@@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79808 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
79809 struct hstate *h = hstate_vma(vma);
79810
79811+#ifdef CONFIG_PAX_SEGMEXEC
79812+ struct vm_area_struct *vma_m;
79813+#endif
79814+
79815 address &= huge_page_mask(h);
79816
79817 ptep = huge_pte_offset(mm, address);
79818@@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79819 VM_FAULT_SET_HINDEX(hstate_index(h));
79820 }
79821
79822+#ifdef CONFIG_PAX_SEGMEXEC
79823+ vma_m = pax_find_mirror_vma(vma);
79824+ if (vma_m) {
79825+ unsigned long address_m;
79826+
79827+ if (vma->vm_start > vma_m->vm_start) {
79828+ address_m = address;
79829+ address -= SEGMEXEC_TASK_SIZE;
79830+ vma = vma_m;
79831+ h = hstate_vma(vma);
79832+ } else
79833+ address_m = address + SEGMEXEC_TASK_SIZE;
79834+
79835+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
79836+ return VM_FAULT_OOM;
79837+ address_m &= HPAGE_MASK;
79838+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
79839+ }
79840+#endif
79841+
79842 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
79843 if (!ptep)
79844 return VM_FAULT_OOM;
79845diff --git a/mm/internal.h b/mm/internal.h
79846index 9ba2110..eaf0674 100644
79847--- a/mm/internal.h
79848+++ b/mm/internal.h
79849@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
79850 * in mm/page_alloc.c
79851 */
79852 extern void __free_pages_bootmem(struct page *page, unsigned int order);
79853+extern void free_compound_page(struct page *page);
79854 extern void prep_compound_page(struct page *page, unsigned long order);
79855 #ifdef CONFIG_MEMORY_FAILURE
79856 extern bool is_free_buddy_page(struct page *page);
79857diff --git a/mm/kmemleak.c b/mm/kmemleak.c
79858index 752a705..6c3102e 100644
79859--- a/mm/kmemleak.c
79860+++ b/mm/kmemleak.c
79861@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
79862
79863 for (i = 0; i < object->trace_len; i++) {
79864 void *ptr = (void *)object->trace[i];
79865- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
79866+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
79867 }
79868 }
79869
79870@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
79871 return -ENOMEM;
79872 }
79873
79874- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
79875+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
79876 &kmemleak_fops);
79877 if (!dentry)
79878 pr_warning("Failed to create the debugfs kmemleak file\n");
79879diff --git a/mm/maccess.c b/mm/maccess.c
79880index d53adf9..03a24bf 100644
79881--- a/mm/maccess.c
79882+++ b/mm/maccess.c
79883@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
79884 set_fs(KERNEL_DS);
79885 pagefault_disable();
79886 ret = __copy_from_user_inatomic(dst,
79887- (__force const void __user *)src, size);
79888+ (const void __force_user *)src, size);
79889 pagefault_enable();
79890 set_fs(old_fs);
79891
79892@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
79893
79894 set_fs(KERNEL_DS);
79895 pagefault_disable();
79896- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
79897+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
79898 pagefault_enable();
79899 set_fs(old_fs);
79900
79901diff --git a/mm/madvise.c b/mm/madvise.c
79902index 03dfa5c..b032917 100644
79903--- a/mm/madvise.c
79904+++ b/mm/madvise.c
79905@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
79906 pgoff_t pgoff;
79907 unsigned long new_flags = vma->vm_flags;
79908
79909+#ifdef CONFIG_PAX_SEGMEXEC
79910+ struct vm_area_struct *vma_m;
79911+#endif
79912+
79913 switch (behavior) {
79914 case MADV_NORMAL:
79915 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
79916@@ -123,6 +127,13 @@ success:
79917 /*
79918 * vm_flags is protected by the mmap_sem held in write mode.
79919 */
79920+
79921+#ifdef CONFIG_PAX_SEGMEXEC
79922+ vma_m = pax_find_mirror_vma(vma);
79923+ if (vma_m)
79924+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
79925+#endif
79926+
79927 vma->vm_flags = new_flags;
79928
79929 out:
79930@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79931 struct vm_area_struct ** prev,
79932 unsigned long start, unsigned long end)
79933 {
79934+
79935+#ifdef CONFIG_PAX_SEGMEXEC
79936+ struct vm_area_struct *vma_m;
79937+#endif
79938+
79939 *prev = vma;
79940 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
79941 return -EINVAL;
79942@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79943 zap_page_range(vma, start, end - start, &details);
79944 } else
79945 zap_page_range(vma, start, end - start, NULL);
79946+
79947+#ifdef CONFIG_PAX_SEGMEXEC
79948+ vma_m = pax_find_mirror_vma(vma);
79949+ if (vma_m) {
79950+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
79951+ struct zap_details details = {
79952+ .nonlinear_vma = vma_m,
79953+ .last_index = ULONG_MAX,
79954+ };
79955+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
79956+ } else
79957+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
79958+ }
79959+#endif
79960+
79961 return 0;
79962 }
79963
79964@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
79965 if (end < start)
79966 goto out;
79967
79968+#ifdef CONFIG_PAX_SEGMEXEC
79969+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
79970+ if (end > SEGMEXEC_TASK_SIZE)
79971+ goto out;
79972+ } else
79973+#endif
79974+
79975+ if (end > TASK_SIZE)
79976+ goto out;
79977+
79978 error = 0;
79979 if (end == start)
79980 goto out;
79981diff --git a/mm/memory-failure.c b/mm/memory-failure.c
79982index c6e4dd3..1f41988 100644
79983--- a/mm/memory-failure.c
79984+++ b/mm/memory-failure.c
79985@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
79986
79987 int sysctl_memory_failure_recovery __read_mostly = 1;
79988
79989-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79990+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79991
79992 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
79993
79994@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
79995 pfn, t->comm, t->pid);
79996 si.si_signo = SIGBUS;
79997 si.si_errno = 0;
79998- si.si_addr = (void *)addr;
79999+ si.si_addr = (void __user *)addr;
80000 #ifdef __ARCH_SI_TRAPNO
80001 si.si_trapno = trapno;
80002 #endif
80003@@ -760,7 +760,7 @@ static struct page_state {
80004 unsigned long res;
80005 char *msg;
80006 int (*action)(struct page *p, unsigned long pfn);
80007-} error_states[] = {
80008+} __do_const error_states[] = {
80009 { reserved, reserved, "reserved kernel", me_kernel },
80010 /*
80011 * free pages are specially detected outside this table:
80012@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80013 }
80014
80015 nr_pages = 1 << compound_trans_order(hpage);
80016- atomic_long_add(nr_pages, &mce_bad_pages);
80017+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
80018
80019 /*
80020 * We need/can do nothing about count=0 pages.
80021@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80022 if (!PageHWPoison(hpage)
80023 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
80024 || (p != hpage && TestSetPageHWPoison(hpage))) {
80025- atomic_long_sub(nr_pages, &mce_bad_pages);
80026+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80027 return 0;
80028 }
80029 set_page_hwpoison_huge_page(hpage);
80030@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80031 }
80032 if (hwpoison_filter(p)) {
80033 if (TestClearPageHWPoison(p))
80034- atomic_long_sub(nr_pages, &mce_bad_pages);
80035+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80036 unlock_page(hpage);
80037 put_page(hpage);
80038 return 0;
80039@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
80040 return 0;
80041 }
80042 if (TestClearPageHWPoison(p))
80043- atomic_long_sub(nr_pages, &mce_bad_pages);
80044+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80045 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
80046 return 0;
80047 }
80048@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
80049 */
80050 if (TestClearPageHWPoison(page)) {
80051 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
80052- atomic_long_sub(nr_pages, &mce_bad_pages);
80053+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
80054 freeit = 1;
80055 if (PageHuge(page))
80056 clear_page_hwpoison_huge_page(page);
80057@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
80058 }
80059 done:
80060 if (!PageHWPoison(hpage))
80061- atomic_long_add(1 << compound_trans_order(hpage),
80062+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
80063 &mce_bad_pages);
80064 set_page_hwpoison_huge_page(hpage);
80065 dequeue_hwpoisoned_huge_page(hpage);
80066@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
80067 return ret;
80068
80069 done:
80070- atomic_long_add(1, &mce_bad_pages);
80071+ atomic_long_add_unchecked(1, &mce_bad_pages);
80072 SetPageHWPoison(page);
80073 /* keep elevated page count for bad page */
80074 return ret;
80075diff --git a/mm/memory.c b/mm/memory.c
80076index bb1369f..efb96b5 100644
80077--- a/mm/memory.c
80078+++ b/mm/memory.c
80079@@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80080 free_pte_range(tlb, pmd, addr);
80081 } while (pmd++, addr = next, addr != end);
80082
80083+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
80084 start &= PUD_MASK;
80085 if (start < floor)
80086 return;
80087@@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80088 pmd = pmd_offset(pud, start);
80089 pud_clear(pud);
80090 pmd_free_tlb(tlb, pmd, start);
80091+#endif
80092+
80093 }
80094
80095 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80096@@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80097 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
80098 } while (pud++, addr = next, addr != end);
80099
80100+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
80101 start &= PGDIR_MASK;
80102 if (start < floor)
80103 return;
80104@@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80105 pud = pud_offset(pgd, start);
80106 pgd_clear(pgd);
80107 pud_free_tlb(tlb, pud, start);
80108+#endif
80109+
80110 }
80111
80112 /*
80113@@ -1618,12 +1624,6 @@ no_page_table:
80114 return page;
80115 }
80116
80117-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
80118-{
80119- return stack_guard_page_start(vma, addr) ||
80120- stack_guard_page_end(vma, addr+PAGE_SIZE);
80121-}
80122-
80123 /**
80124 * __get_user_pages() - pin user pages in memory
80125 * @tsk: task_struct of target task
80126@@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80127
80128 i = 0;
80129
80130- do {
80131+ while (nr_pages) {
80132 struct vm_area_struct *vma;
80133
80134- vma = find_extend_vma(mm, start);
80135+ vma = find_vma(mm, start);
80136 if (!vma && in_gate_area(mm, start)) {
80137 unsigned long pg = start & PAGE_MASK;
80138 pgd_t *pgd;
80139@@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80140 goto next_page;
80141 }
80142
80143- if (!vma ||
80144+ if (!vma || start < vma->vm_start ||
80145 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
80146 !(vm_flags & vma->vm_flags))
80147 return i ? : -EFAULT;
80148@@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80149 int ret;
80150 unsigned int fault_flags = 0;
80151
80152- /* For mlock, just skip the stack guard page. */
80153- if (foll_flags & FOLL_MLOCK) {
80154- if (stack_guard_page(vma, start))
80155- goto next_page;
80156- }
80157 if (foll_flags & FOLL_WRITE)
80158 fault_flags |= FAULT_FLAG_WRITE;
80159 if (nonblocking)
80160@@ -1865,7 +1860,7 @@ next_page:
80161 start += PAGE_SIZE;
80162 nr_pages--;
80163 } while (nr_pages && start < vma->vm_end);
80164- } while (nr_pages);
80165+ }
80166 return i;
80167 }
80168 EXPORT_SYMBOL(__get_user_pages);
80169@@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
80170 page_add_file_rmap(page);
80171 set_pte_at(mm, addr, pte, mk_pte(page, prot));
80172
80173+#ifdef CONFIG_PAX_SEGMEXEC
80174+ pax_mirror_file_pte(vma, addr, page, ptl);
80175+#endif
80176+
80177 retval = 0;
80178 pte_unmap_unlock(pte, ptl);
80179 return retval;
80180@@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
80181 if (!page_count(page))
80182 return -EINVAL;
80183 if (!(vma->vm_flags & VM_MIXEDMAP)) {
80184+
80185+#ifdef CONFIG_PAX_SEGMEXEC
80186+ struct vm_area_struct *vma_m;
80187+#endif
80188+
80189 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
80190 BUG_ON(vma->vm_flags & VM_PFNMAP);
80191 vma->vm_flags |= VM_MIXEDMAP;
80192+
80193+#ifdef CONFIG_PAX_SEGMEXEC
80194+ vma_m = pax_find_mirror_vma(vma);
80195+ if (vma_m)
80196+ vma_m->vm_flags |= VM_MIXEDMAP;
80197+#endif
80198+
80199 }
80200 return insert_page(vma, addr, page, vma->vm_page_prot);
80201 }
80202@@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
80203 unsigned long pfn)
80204 {
80205 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
80206+ BUG_ON(vma->vm_mirror);
80207
80208 if (addr < vma->vm_start || addr >= vma->vm_end)
80209 return -EFAULT;
80210@@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
80211
80212 BUG_ON(pud_huge(*pud));
80213
80214- pmd = pmd_alloc(mm, pud, addr);
80215+ pmd = (mm == &init_mm) ?
80216+ pmd_alloc_kernel(mm, pud, addr) :
80217+ pmd_alloc(mm, pud, addr);
80218 if (!pmd)
80219 return -ENOMEM;
80220 do {
80221@@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
80222 unsigned long next;
80223 int err;
80224
80225- pud = pud_alloc(mm, pgd, addr);
80226+ pud = (mm == &init_mm) ?
80227+ pud_alloc_kernel(mm, pgd, addr) :
80228+ pud_alloc(mm, pgd, addr);
80229 if (!pud)
80230 return -ENOMEM;
80231 do {
80232@@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
80233 copy_user_highpage(dst, src, va, vma);
80234 }
80235
80236+#ifdef CONFIG_PAX_SEGMEXEC
80237+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
80238+{
80239+ struct mm_struct *mm = vma->vm_mm;
80240+ spinlock_t *ptl;
80241+ pte_t *pte, entry;
80242+
80243+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
80244+ entry = *pte;
80245+ if (!pte_present(entry)) {
80246+ if (!pte_none(entry)) {
80247+ BUG_ON(pte_file(entry));
80248+ free_swap_and_cache(pte_to_swp_entry(entry));
80249+ pte_clear_not_present_full(mm, address, pte, 0);
80250+ }
80251+ } else {
80252+ struct page *page;
80253+
80254+ flush_cache_page(vma, address, pte_pfn(entry));
80255+ entry = ptep_clear_flush(vma, address, pte);
80256+ BUG_ON(pte_dirty(entry));
80257+ page = vm_normal_page(vma, address, entry);
80258+ if (page) {
80259+ update_hiwater_rss(mm);
80260+ if (PageAnon(page))
80261+ dec_mm_counter_fast(mm, MM_ANONPAGES);
80262+ else
80263+ dec_mm_counter_fast(mm, MM_FILEPAGES);
80264+ page_remove_rmap(page);
80265+ page_cache_release(page);
80266+ }
80267+ }
80268+ pte_unmap_unlock(pte, ptl);
80269+}
80270+
80271+/* PaX: if vma is mirrored, synchronize the mirror's PTE
80272+ *
80273+ * the ptl of the lower mapped page is held on entry and is not released on exit
80274+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
80275+ */
80276+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80277+{
80278+ struct mm_struct *mm = vma->vm_mm;
80279+ unsigned long address_m;
80280+ spinlock_t *ptl_m;
80281+ struct vm_area_struct *vma_m;
80282+ pmd_t *pmd_m;
80283+ pte_t *pte_m, entry_m;
80284+
80285+ BUG_ON(!page_m || !PageAnon(page_m));
80286+
80287+ vma_m = pax_find_mirror_vma(vma);
80288+ if (!vma_m)
80289+ return;
80290+
80291+ BUG_ON(!PageLocked(page_m));
80292+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80293+ address_m = address + SEGMEXEC_TASK_SIZE;
80294+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80295+ pte_m = pte_offset_map(pmd_m, address_m);
80296+ ptl_m = pte_lockptr(mm, pmd_m);
80297+ if (ptl != ptl_m) {
80298+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80299+ if (!pte_none(*pte_m))
80300+ goto out;
80301+ }
80302+
80303+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
80304+ page_cache_get(page_m);
80305+ page_add_anon_rmap(page_m, vma_m, address_m);
80306+ inc_mm_counter_fast(mm, MM_ANONPAGES);
80307+ set_pte_at(mm, address_m, pte_m, entry_m);
80308+ update_mmu_cache(vma_m, address_m, entry_m);
80309+out:
80310+ if (ptl != ptl_m)
80311+ spin_unlock(ptl_m);
80312+ pte_unmap(pte_m);
80313+ unlock_page(page_m);
80314+}
80315+
80316+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80317+{
80318+ struct mm_struct *mm = vma->vm_mm;
80319+ unsigned long address_m;
80320+ spinlock_t *ptl_m;
80321+ struct vm_area_struct *vma_m;
80322+ pmd_t *pmd_m;
80323+ pte_t *pte_m, entry_m;
80324+
80325+ BUG_ON(!page_m || PageAnon(page_m));
80326+
80327+ vma_m = pax_find_mirror_vma(vma);
80328+ if (!vma_m)
80329+ return;
80330+
80331+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80332+ address_m = address + SEGMEXEC_TASK_SIZE;
80333+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80334+ pte_m = pte_offset_map(pmd_m, address_m);
80335+ ptl_m = pte_lockptr(mm, pmd_m);
80336+ if (ptl != ptl_m) {
80337+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80338+ if (!pte_none(*pte_m))
80339+ goto out;
80340+ }
80341+
80342+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
80343+ page_cache_get(page_m);
80344+ page_add_file_rmap(page_m);
80345+ inc_mm_counter_fast(mm, MM_FILEPAGES);
80346+ set_pte_at(mm, address_m, pte_m, entry_m);
80347+ update_mmu_cache(vma_m, address_m, entry_m);
80348+out:
80349+ if (ptl != ptl_m)
80350+ spin_unlock(ptl_m);
80351+ pte_unmap(pte_m);
80352+}
80353+
80354+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
80355+{
80356+ struct mm_struct *mm = vma->vm_mm;
80357+ unsigned long address_m;
80358+ spinlock_t *ptl_m;
80359+ struct vm_area_struct *vma_m;
80360+ pmd_t *pmd_m;
80361+ pte_t *pte_m, entry_m;
80362+
80363+ vma_m = pax_find_mirror_vma(vma);
80364+ if (!vma_m)
80365+ return;
80366+
80367+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80368+ address_m = address + SEGMEXEC_TASK_SIZE;
80369+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
80370+ pte_m = pte_offset_map(pmd_m, address_m);
80371+ ptl_m = pte_lockptr(mm, pmd_m);
80372+ if (ptl != ptl_m) {
80373+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
80374+ if (!pte_none(*pte_m))
80375+ goto out;
80376+ }
80377+
80378+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
80379+ set_pte_at(mm, address_m, pte_m, entry_m);
80380+out:
80381+ if (ptl != ptl_m)
80382+ spin_unlock(ptl_m);
80383+ pte_unmap(pte_m);
80384+}
80385+
80386+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
80387+{
80388+ struct page *page_m;
80389+ pte_t entry;
80390+
80391+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
80392+ goto out;
80393+
80394+ entry = *pte;
80395+ page_m = vm_normal_page(vma, address, entry);
80396+ if (!page_m)
80397+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
80398+ else if (PageAnon(page_m)) {
80399+ if (pax_find_mirror_vma(vma)) {
80400+ pte_unmap_unlock(pte, ptl);
80401+ lock_page(page_m);
80402+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
80403+ if (pte_same(entry, *pte))
80404+ pax_mirror_anon_pte(vma, address, page_m, ptl);
80405+ else
80406+ unlock_page(page_m);
80407+ }
80408+ } else
80409+ pax_mirror_file_pte(vma, address, page_m, ptl);
80410+
80411+out:
80412+ pte_unmap_unlock(pte, ptl);
80413+}
80414+#endif
80415+
80416 /*
80417 * This routine handles present pages, when users try to write
80418 * to a shared page. It is done by copying the page to a new address
80419@@ -2725,6 +2921,12 @@ gotten:
80420 */
80421 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
80422 if (likely(pte_same(*page_table, orig_pte))) {
80423+
80424+#ifdef CONFIG_PAX_SEGMEXEC
80425+ if (pax_find_mirror_vma(vma))
80426+ BUG_ON(!trylock_page(new_page));
80427+#endif
80428+
80429 if (old_page) {
80430 if (!PageAnon(old_page)) {
80431 dec_mm_counter_fast(mm, MM_FILEPAGES);
80432@@ -2776,6 +2978,10 @@ gotten:
80433 page_remove_rmap(old_page);
80434 }
80435
80436+#ifdef CONFIG_PAX_SEGMEXEC
80437+ pax_mirror_anon_pte(vma, address, new_page, ptl);
80438+#endif
80439+
80440 /* Free the old page.. */
80441 new_page = old_page;
80442 ret |= VM_FAULT_WRITE;
80443@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
80444 swap_free(entry);
80445 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
80446 try_to_free_swap(page);
80447+
80448+#ifdef CONFIG_PAX_SEGMEXEC
80449+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
80450+#endif
80451+
80452 unlock_page(page);
80453 if (swapcache) {
80454 /*
80455@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
80456
80457 /* No need to invalidate - it was non-present before */
80458 update_mmu_cache(vma, address, page_table);
80459+
80460+#ifdef CONFIG_PAX_SEGMEXEC
80461+ pax_mirror_anon_pte(vma, address, page, ptl);
80462+#endif
80463+
80464 unlock:
80465 pte_unmap_unlock(page_table, ptl);
80466 out:
80467@@ -3093,40 +3309,6 @@ out_release:
80468 }
80469
80470 /*
80471- * This is like a special single-page "expand_{down|up}wards()",
80472- * except we must first make sure that 'address{-|+}PAGE_SIZE'
80473- * doesn't hit another vma.
80474- */
80475-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
80476-{
80477- address &= PAGE_MASK;
80478- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
80479- struct vm_area_struct *prev = vma->vm_prev;
80480-
80481- /*
80482- * Is there a mapping abutting this one below?
80483- *
80484- * That's only ok if it's the same stack mapping
80485- * that has gotten split..
80486- */
80487- if (prev && prev->vm_end == address)
80488- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
80489-
80490- expand_downwards(vma, address - PAGE_SIZE);
80491- }
80492- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
80493- struct vm_area_struct *next = vma->vm_next;
80494-
80495- /* As VM_GROWSDOWN but s/below/above/ */
80496- if (next && next->vm_start == address + PAGE_SIZE)
80497- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
80498-
80499- expand_upwards(vma, address + PAGE_SIZE);
80500- }
80501- return 0;
80502-}
80503-
80504-/*
80505 * We enter with non-exclusive mmap_sem (to exclude vma changes,
80506 * but allow concurrent faults), and pte mapped but not yet locked.
80507 * We return with mmap_sem still held, but pte unmapped and unlocked.
80508@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
80509 unsigned long address, pte_t *page_table, pmd_t *pmd,
80510 unsigned int flags)
80511 {
80512- struct page *page;
80513+ struct page *page = NULL;
80514 spinlock_t *ptl;
80515 pte_t entry;
80516
80517- pte_unmap(page_table);
80518-
80519- /* Check if we need to add a guard page to the stack */
80520- if (check_stack_guard_page(vma, address) < 0)
80521- return VM_FAULT_SIGBUS;
80522-
80523- /* Use the zero-page for reads */
80524 if (!(flags & FAULT_FLAG_WRITE)) {
80525 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
80526 vma->vm_page_prot));
80527- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
80528+ ptl = pte_lockptr(mm, pmd);
80529+ spin_lock(ptl);
80530 if (!pte_none(*page_table))
80531 goto unlock;
80532 goto setpte;
80533 }
80534
80535 /* Allocate our own private page. */
80536+ pte_unmap(page_table);
80537+
80538 if (unlikely(anon_vma_prepare(vma)))
80539 goto oom;
80540 page = alloc_zeroed_user_highpage_movable(vma, address);
80541@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
80542 if (!pte_none(*page_table))
80543 goto release;
80544
80545+#ifdef CONFIG_PAX_SEGMEXEC
80546+ if (pax_find_mirror_vma(vma))
80547+ BUG_ON(!trylock_page(page));
80548+#endif
80549+
80550 inc_mm_counter_fast(mm, MM_ANONPAGES);
80551 page_add_new_anon_rmap(page, vma, address);
80552 setpte:
80553@@ -3181,6 +3364,12 @@ setpte:
80554
80555 /* No need to invalidate - it was non-present before */
80556 update_mmu_cache(vma, address, page_table);
80557+
80558+#ifdef CONFIG_PAX_SEGMEXEC
80559+ if (page)
80560+ pax_mirror_anon_pte(vma, address, page, ptl);
80561+#endif
80562+
80563 unlock:
80564 pte_unmap_unlock(page_table, ptl);
80565 return 0;
80566@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80567 */
80568 /* Only go through if we didn't race with anybody else... */
80569 if (likely(pte_same(*page_table, orig_pte))) {
80570+
80571+#ifdef CONFIG_PAX_SEGMEXEC
80572+ if (anon && pax_find_mirror_vma(vma))
80573+ BUG_ON(!trylock_page(page));
80574+#endif
80575+
80576 flush_icache_page(vma, page);
80577 entry = mk_pte(page, vma->vm_page_prot);
80578 if (flags & FAULT_FLAG_WRITE)
80579@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80580
80581 /* no need to invalidate: a not-present page won't be cached */
80582 update_mmu_cache(vma, address, page_table);
80583+
80584+#ifdef CONFIG_PAX_SEGMEXEC
80585+ if (anon)
80586+ pax_mirror_anon_pte(vma, address, page, ptl);
80587+ else
80588+ pax_mirror_file_pte(vma, address, page, ptl);
80589+#endif
80590+
80591 } else {
80592 if (cow_page)
80593 mem_cgroup_uncharge_page(cow_page);
80594@@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
80595 if (flags & FAULT_FLAG_WRITE)
80596 flush_tlb_fix_spurious_fault(vma, address);
80597 }
80598+
80599+#ifdef CONFIG_PAX_SEGMEXEC
80600+ pax_mirror_pte(vma, address, pte, pmd, ptl);
80601+ return 0;
80602+#endif
80603+
80604 unlock:
80605 pte_unmap_unlock(pte, ptl);
80606 return 0;
80607@@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80608 pmd_t *pmd;
80609 pte_t *pte;
80610
80611+#ifdef CONFIG_PAX_SEGMEXEC
80612+ struct vm_area_struct *vma_m;
80613+#endif
80614+
80615 __set_current_state(TASK_RUNNING);
80616
80617 count_vm_event(PGFAULT);
80618@@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80619 if (unlikely(is_vm_hugetlb_page(vma)))
80620 return hugetlb_fault(mm, vma, address, flags);
80621
80622+#ifdef CONFIG_PAX_SEGMEXEC
80623+ vma_m = pax_find_mirror_vma(vma);
80624+ if (vma_m) {
80625+ unsigned long address_m;
80626+ pgd_t *pgd_m;
80627+ pud_t *pud_m;
80628+ pmd_t *pmd_m;
80629+
80630+ if (vma->vm_start > vma_m->vm_start) {
80631+ address_m = address;
80632+ address -= SEGMEXEC_TASK_SIZE;
80633+ vma = vma_m;
80634+ } else
80635+ address_m = address + SEGMEXEC_TASK_SIZE;
80636+
80637+ pgd_m = pgd_offset(mm, address_m);
80638+ pud_m = pud_alloc(mm, pgd_m, address_m);
80639+ if (!pud_m)
80640+ return VM_FAULT_OOM;
80641+ pmd_m = pmd_alloc(mm, pud_m, address_m);
80642+ if (!pmd_m)
80643+ return VM_FAULT_OOM;
80644+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
80645+ return VM_FAULT_OOM;
80646+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
80647+ }
80648+#endif
80649+
80650 retry:
80651 pgd = pgd_offset(mm, address);
80652 pud = pud_alloc(mm, pgd, address);
80653@@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80654 spin_unlock(&mm->page_table_lock);
80655 return 0;
80656 }
80657+
80658+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80659+{
80660+ pud_t *new = pud_alloc_one(mm, address);
80661+ if (!new)
80662+ return -ENOMEM;
80663+
80664+ smp_wmb(); /* See comment in __pte_alloc */
80665+
80666+ spin_lock(&mm->page_table_lock);
80667+ if (pgd_present(*pgd)) /* Another has populated it */
80668+ pud_free(mm, new);
80669+ else
80670+ pgd_populate_kernel(mm, pgd, new);
80671+ spin_unlock(&mm->page_table_lock);
80672+ return 0;
80673+}
80674 #endif /* __PAGETABLE_PUD_FOLDED */
80675
80676 #ifndef __PAGETABLE_PMD_FOLDED
80677@@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80678 spin_unlock(&mm->page_table_lock);
80679 return 0;
80680 }
80681+
80682+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80683+{
80684+ pmd_t *new = pmd_alloc_one(mm, address);
80685+ if (!new)
80686+ return -ENOMEM;
80687+
80688+ smp_wmb(); /* See comment in __pte_alloc */
80689+
80690+ spin_lock(&mm->page_table_lock);
80691+#ifndef __ARCH_HAS_4LEVEL_HACK
80692+ if (pud_present(*pud)) /* Another has populated it */
80693+ pmd_free(mm, new);
80694+ else
80695+ pud_populate_kernel(mm, pud, new);
80696+#else
80697+ if (pgd_present(*pud)) /* Another has populated it */
80698+ pmd_free(mm, new);
80699+ else
80700+ pgd_populate_kernel(mm, pud, new);
80701+#endif /* __ARCH_HAS_4LEVEL_HACK */
80702+ spin_unlock(&mm->page_table_lock);
80703+ return 0;
80704+}
80705 #endif /* __PAGETABLE_PMD_FOLDED */
80706
80707 int make_pages_present(unsigned long addr, unsigned long end)
80708@@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
80709 gate_vma.vm_start = FIXADDR_USER_START;
80710 gate_vma.vm_end = FIXADDR_USER_END;
80711 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
80712- gate_vma.vm_page_prot = __P101;
80713+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
80714
80715 return 0;
80716 }
80717diff --git a/mm/mempolicy.c b/mm/mempolicy.c
80718index 3df6d12..a11056a 100644
80719--- a/mm/mempolicy.c
80720+++ b/mm/mempolicy.c
80721@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80722 unsigned long vmstart;
80723 unsigned long vmend;
80724
80725+#ifdef CONFIG_PAX_SEGMEXEC
80726+ struct vm_area_struct *vma_m;
80727+#endif
80728+
80729 vma = find_vma(mm, start);
80730 if (!vma || vma->vm_start > start)
80731 return -EFAULT;
80732@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80733 if (err)
80734 goto out;
80735 }
80736+
80737 err = vma_replace_policy(vma, new_pol);
80738 if (err)
80739 goto out;
80740+
80741+#ifdef CONFIG_PAX_SEGMEXEC
80742+ vma_m = pax_find_mirror_vma(vma);
80743+ if (vma_m) {
80744+ err = vma_replace_policy(vma_m, new_pol);
80745+ if (err)
80746+ goto out;
80747+ }
80748+#endif
80749+
80750 }
80751
80752 out:
80753@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
80754
80755 if (end < start)
80756 return -EINVAL;
80757+
80758+#ifdef CONFIG_PAX_SEGMEXEC
80759+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
80760+ if (end > SEGMEXEC_TASK_SIZE)
80761+ return -EINVAL;
80762+ } else
80763+#endif
80764+
80765+ if (end > TASK_SIZE)
80766+ return -EINVAL;
80767+
80768 if (end == start)
80769 return 0;
80770
80771@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80772 */
80773 tcred = __task_cred(task);
80774 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80775- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80776- !capable(CAP_SYS_NICE)) {
80777+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80778 rcu_read_unlock();
80779 err = -EPERM;
80780 goto out_put;
80781@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80782 goto out;
80783 }
80784
80785+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80786+ if (mm != current->mm &&
80787+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
80788+ mmput(mm);
80789+ err = -EPERM;
80790+ goto out;
80791+ }
80792+#endif
80793+
80794 err = do_migrate_pages(mm, old, new,
80795 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
80796
80797diff --git a/mm/migrate.c b/mm/migrate.c
80798index 2fd8b4a..d70358f 100644
80799--- a/mm/migrate.c
80800+++ b/mm/migrate.c
80801@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
80802 */
80803 tcred = __task_cred(task);
80804 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80805- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80806- !capable(CAP_SYS_NICE)) {
80807+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80808 rcu_read_unlock();
80809 err = -EPERM;
80810 goto out;
80811diff --git a/mm/mlock.c b/mm/mlock.c
80812index c9bd528..da8d069 100644
80813--- a/mm/mlock.c
80814+++ b/mm/mlock.c
80815@@ -13,6 +13,7 @@
80816 #include <linux/pagemap.h>
80817 #include <linux/mempolicy.h>
80818 #include <linux/syscalls.h>
80819+#include <linux/security.h>
80820 #include <linux/sched.h>
80821 #include <linux/export.h>
80822 #include <linux/rmap.h>
80823@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
80824 {
80825 unsigned long nstart, end, tmp;
80826 struct vm_area_struct * vma, * prev;
80827- int error;
80828+ int error = 0;
80829
80830 VM_BUG_ON(start & ~PAGE_MASK);
80831 VM_BUG_ON(len != PAGE_ALIGN(len));
80832@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
80833 return -EINVAL;
80834 if (end == start)
80835 return 0;
80836+ if (end > TASK_SIZE)
80837+ return -EINVAL;
80838+
80839 vma = find_vma(current->mm, start);
80840 if (!vma || vma->vm_start > start)
80841 return -ENOMEM;
80842@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
80843 for (nstart = start ; ; ) {
80844 vm_flags_t newflags;
80845
80846+#ifdef CONFIG_PAX_SEGMEXEC
80847+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80848+ break;
80849+#endif
80850+
80851 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
80852
80853 newflags = vma->vm_flags | VM_LOCKED;
80854@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
80855 lock_limit >>= PAGE_SHIFT;
80856
80857 /* check against resource limits */
80858+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
80859 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
80860 error = do_mlock(start, len, 1);
80861 up_write(&current->mm->mmap_sem);
80862@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
80863 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
80864 vm_flags_t newflags;
80865
80866+#ifdef CONFIG_PAX_SEGMEXEC
80867+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80868+ break;
80869+#endif
80870+
80871+ BUG_ON(vma->vm_end > TASK_SIZE);
80872 newflags = vma->vm_flags | VM_LOCKED;
80873 if (!(flags & MCL_CURRENT))
80874 newflags &= ~VM_LOCKED;
80875@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
80876 lock_limit >>= PAGE_SHIFT;
80877
80878 ret = -ENOMEM;
80879+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
80880 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
80881 capable(CAP_IPC_LOCK))
80882 ret = do_mlockall(flags);
80883diff --git a/mm/mmap.c b/mm/mmap.c
80884index 8832b87..20500c1 100644
80885--- a/mm/mmap.c
80886+++ b/mm/mmap.c
80887@@ -32,6 +32,7 @@
80888 #include <linux/khugepaged.h>
80889 #include <linux/uprobes.h>
80890 #include <linux/rbtree_augmented.h>
80891+#include <linux/random.h>
80892
80893 #include <asm/uaccess.h>
80894 #include <asm/cacheflush.h>
80895@@ -48,6 +49,16 @@
80896 #define arch_rebalance_pgtables(addr, len) (addr)
80897 #endif
80898
80899+static inline void verify_mm_writelocked(struct mm_struct *mm)
80900+{
80901+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
80902+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
80903+ up_read(&mm->mmap_sem);
80904+ BUG();
80905+ }
80906+#endif
80907+}
80908+
80909 static void unmap_region(struct mm_struct *mm,
80910 struct vm_area_struct *vma, struct vm_area_struct *prev,
80911 unsigned long start, unsigned long end);
80912@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
80913 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
80914 *
80915 */
80916-pgprot_t protection_map[16] = {
80917+pgprot_t protection_map[16] __read_only = {
80918 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
80919 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
80920 };
80921
80922-pgprot_t vm_get_page_prot(unsigned long vm_flags)
80923+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80924 {
80925- return __pgprot(pgprot_val(protection_map[vm_flags &
80926+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
80927 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
80928 pgprot_val(arch_vm_get_page_prot(vm_flags)));
80929+
80930+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80931+ if (!(__supported_pte_mask & _PAGE_NX) &&
80932+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
80933+ (vm_flags & (VM_READ | VM_WRITE)))
80934+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
80935+#endif
80936+
80937+ return prot;
80938 }
80939 EXPORT_SYMBOL(vm_get_page_prot);
80940
80941 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
80942 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
80943 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
80944+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
80945 /*
80946 * Make sure vm_committed_as in one cacheline and not cacheline shared with
80947 * other variables. It can be updated by several CPUs frequently.
80948@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
80949 struct vm_area_struct *next = vma->vm_next;
80950
80951 might_sleep();
80952+ BUG_ON(vma->vm_mirror);
80953 if (vma->vm_ops && vma->vm_ops->close)
80954 vma->vm_ops->close(vma);
80955 if (vma->vm_file)
80956@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
80957 * not page aligned -Ram Gupta
80958 */
80959 rlim = rlimit(RLIMIT_DATA);
80960+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
80961 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
80962 (mm->end_data - mm->start_data) > rlim)
80963 goto out;
80964@@ -888,6 +911,12 @@ static int
80965 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
80966 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80967 {
80968+
80969+#ifdef CONFIG_PAX_SEGMEXEC
80970+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
80971+ return 0;
80972+#endif
80973+
80974 if (is_mergeable_vma(vma, file, vm_flags) &&
80975 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80976 if (vma->vm_pgoff == vm_pgoff)
80977@@ -907,6 +936,12 @@ static int
80978 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80979 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80980 {
80981+
80982+#ifdef CONFIG_PAX_SEGMEXEC
80983+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
80984+ return 0;
80985+#endif
80986+
80987 if (is_mergeable_vma(vma, file, vm_flags) &&
80988 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80989 pgoff_t vm_pglen;
80990@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80991 struct vm_area_struct *vma_merge(struct mm_struct *mm,
80992 struct vm_area_struct *prev, unsigned long addr,
80993 unsigned long end, unsigned long vm_flags,
80994- struct anon_vma *anon_vma, struct file *file,
80995+ struct anon_vma *anon_vma, struct file *file,
80996 pgoff_t pgoff, struct mempolicy *policy)
80997 {
80998 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
80999 struct vm_area_struct *area, *next;
81000 int err;
81001
81002+#ifdef CONFIG_PAX_SEGMEXEC
81003+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
81004+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
81005+
81006+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
81007+#endif
81008+
81009 /*
81010 * We later require that vma->vm_flags == vm_flags,
81011 * so this tests vma->vm_flags & VM_SPECIAL, too.
81012@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81013 if (next && next->vm_end == end) /* cases 6, 7, 8 */
81014 next = next->vm_next;
81015
81016+#ifdef CONFIG_PAX_SEGMEXEC
81017+ if (prev)
81018+ prev_m = pax_find_mirror_vma(prev);
81019+ if (area)
81020+ area_m = pax_find_mirror_vma(area);
81021+ if (next)
81022+ next_m = pax_find_mirror_vma(next);
81023+#endif
81024+
81025 /*
81026 * Can it merge with the predecessor?
81027 */
81028@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81029 /* cases 1, 6 */
81030 err = vma_adjust(prev, prev->vm_start,
81031 next->vm_end, prev->vm_pgoff, NULL);
81032- } else /* cases 2, 5, 7 */
81033+
81034+#ifdef CONFIG_PAX_SEGMEXEC
81035+ if (!err && prev_m)
81036+ err = vma_adjust(prev_m, prev_m->vm_start,
81037+ next_m->vm_end, prev_m->vm_pgoff, NULL);
81038+#endif
81039+
81040+ } else { /* cases 2, 5, 7 */
81041 err = vma_adjust(prev, prev->vm_start,
81042 end, prev->vm_pgoff, NULL);
81043+
81044+#ifdef CONFIG_PAX_SEGMEXEC
81045+ if (!err && prev_m)
81046+ err = vma_adjust(prev_m, prev_m->vm_start,
81047+ end_m, prev_m->vm_pgoff, NULL);
81048+#endif
81049+
81050+ }
81051 if (err)
81052 return NULL;
81053 khugepaged_enter_vma_merge(prev);
81054@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81055 mpol_equal(policy, vma_policy(next)) &&
81056 can_vma_merge_before(next, vm_flags,
81057 anon_vma, file, pgoff+pglen)) {
81058- if (prev && addr < prev->vm_end) /* case 4 */
81059+ if (prev && addr < prev->vm_end) { /* case 4 */
81060 err = vma_adjust(prev, prev->vm_start,
81061 addr, prev->vm_pgoff, NULL);
81062- else /* cases 3, 8 */
81063+
81064+#ifdef CONFIG_PAX_SEGMEXEC
81065+ if (!err && prev_m)
81066+ err = vma_adjust(prev_m, prev_m->vm_start,
81067+ addr_m, prev_m->vm_pgoff, NULL);
81068+#endif
81069+
81070+ } else { /* cases 3, 8 */
81071 err = vma_adjust(area, addr, next->vm_end,
81072 next->vm_pgoff - pglen, NULL);
81073+
81074+#ifdef CONFIG_PAX_SEGMEXEC
81075+ if (!err && area_m)
81076+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
81077+ next_m->vm_pgoff - pglen, NULL);
81078+#endif
81079+
81080+ }
81081 if (err)
81082 return NULL;
81083 khugepaged_enter_vma_merge(area);
81084@@ -1120,16 +1201,13 @@ none:
81085 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
81086 struct file *file, long pages)
81087 {
81088- const unsigned long stack_flags
81089- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
81090-
81091 mm->total_vm += pages;
81092
81093 if (file) {
81094 mm->shared_vm += pages;
81095 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
81096 mm->exec_vm += pages;
81097- } else if (flags & stack_flags)
81098+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
81099 mm->stack_vm += pages;
81100 }
81101 #endif /* CONFIG_PROC_FS */
81102@@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81103 * (the exception is when the underlying filesystem is noexec
81104 * mounted, in which case we dont add PROT_EXEC.)
81105 */
81106- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81107+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81108 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
81109 prot |= PROT_EXEC;
81110
81111@@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81112 /* Obtain the address to map to. we verify (or select) it and ensure
81113 * that it represents a valid section of the address space.
81114 */
81115- addr = get_unmapped_area(file, addr, len, pgoff, flags);
81116+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
81117 if (addr & ~PAGE_MASK)
81118 return addr;
81119
81120@@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81121 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
81122 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
81123
81124+#ifdef CONFIG_PAX_MPROTECT
81125+ if (mm->pax_flags & MF_PAX_MPROTECT) {
81126+#ifndef CONFIG_PAX_MPROTECT_COMPAT
81127+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
81128+ gr_log_rwxmmap(file);
81129+
81130+#ifdef CONFIG_PAX_EMUPLT
81131+ vm_flags &= ~VM_EXEC;
81132+#else
81133+ return -EPERM;
81134+#endif
81135+
81136+ }
81137+
81138+ if (!(vm_flags & VM_EXEC))
81139+ vm_flags &= ~VM_MAYEXEC;
81140+#else
81141+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81142+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81143+#endif
81144+ else
81145+ vm_flags &= ~VM_MAYWRITE;
81146+ }
81147+#endif
81148+
81149+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81150+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
81151+ vm_flags &= ~VM_PAGEEXEC;
81152+#endif
81153+
81154 if (flags & MAP_LOCKED)
81155 if (!can_do_mlock())
81156 return -EPERM;
81157@@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81158 locked += mm->locked_vm;
81159 lock_limit = rlimit(RLIMIT_MEMLOCK);
81160 lock_limit >>= PAGE_SHIFT;
81161+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81162 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
81163 return -EAGAIN;
81164 }
81165@@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81166 }
81167 }
81168
81169+ if (!gr_acl_handle_mmap(file, prot))
81170+ return -EACCES;
81171+
81172 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
81173 }
81174
81175@@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
81176 vm_flags_t vm_flags = vma->vm_flags;
81177
81178 /* If it was private or non-writable, the write bit is already clear */
81179- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
81180+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
81181 return 0;
81182
81183 /* The backer wishes to know when pages are first written to? */
81184@@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
81185 unsigned long charged = 0;
81186 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
81187
81188+#ifdef CONFIG_PAX_SEGMEXEC
81189+ struct vm_area_struct *vma_m = NULL;
81190+#endif
81191+
81192+ /*
81193+ * mm->mmap_sem is required to protect against another thread
81194+ * changing the mappings in case we sleep.
81195+ */
81196+ verify_mm_writelocked(mm);
81197+
81198 /* Clear old maps */
81199 error = -ENOMEM;
81200-munmap_back:
81201 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81202 if (do_munmap(mm, addr, len))
81203 return -ENOMEM;
81204- goto munmap_back;
81205+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81206 }
81207
81208 /* Check against address space limit. */
81209@@ -1460,6 +1581,16 @@ munmap_back:
81210 goto unacct_error;
81211 }
81212
81213+#ifdef CONFIG_PAX_SEGMEXEC
81214+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
81215+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81216+ if (!vma_m) {
81217+ error = -ENOMEM;
81218+ goto free_vma;
81219+ }
81220+ }
81221+#endif
81222+
81223 vma->vm_mm = mm;
81224 vma->vm_start = addr;
81225 vma->vm_end = addr + len;
81226@@ -1484,6 +1615,13 @@ munmap_back:
81227 if (error)
81228 goto unmap_and_free_vma;
81229
81230+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81231+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
81232+ vma->vm_flags |= VM_PAGEEXEC;
81233+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
81234+ }
81235+#endif
81236+
81237 /* Can addr have changed??
81238 *
81239 * Answer: Yes, several device drivers can do it in their
81240@@ -1522,6 +1660,11 @@ munmap_back:
81241 vma_link(mm, vma, prev, rb_link, rb_parent);
81242 file = vma->vm_file;
81243
81244+#ifdef CONFIG_PAX_SEGMEXEC
81245+ if (vma_m)
81246+ BUG_ON(pax_mirror_vma(vma_m, vma));
81247+#endif
81248+
81249 /* Once vma denies write, undo our temporary denial count */
81250 if (correct_wcount)
81251 atomic_inc(&inode->i_writecount);
81252@@ -1529,6 +1672,7 @@ out:
81253 perf_event_mmap(vma);
81254
81255 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
81256+ track_exec_limit(mm, addr, addr + len, vm_flags);
81257 if (vm_flags & VM_LOCKED) {
81258 if (!mlock_vma_pages_range(vma, addr, addr + len))
81259 mm->locked_vm += (len >> PAGE_SHIFT);
81260@@ -1550,6 +1694,12 @@ unmap_and_free_vma:
81261 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
81262 charged = 0;
81263 free_vma:
81264+
81265+#ifdef CONFIG_PAX_SEGMEXEC
81266+ if (vma_m)
81267+ kmem_cache_free(vm_area_cachep, vma_m);
81268+#endif
81269+
81270 kmem_cache_free(vm_area_cachep, vma);
81271 unacct_error:
81272 if (charged)
81273@@ -1557,6 +1707,62 @@ unacct_error:
81274 return error;
81275 }
81276
81277+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81278+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81279+{
81280+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
81281+ return (random32() & 0xFF) << PAGE_SHIFT;
81282+
81283+ return 0;
81284+}
81285+#endif
81286+
81287+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
81288+{
81289+ if (!vma) {
81290+#ifdef CONFIG_STACK_GROWSUP
81291+ if (addr > sysctl_heap_stack_gap)
81292+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
81293+ else
81294+ vma = find_vma(current->mm, 0);
81295+ if (vma && (vma->vm_flags & VM_GROWSUP))
81296+ return false;
81297+#endif
81298+ return true;
81299+ }
81300+
81301+ if (addr + len > vma->vm_start)
81302+ return false;
81303+
81304+ if (vma->vm_flags & VM_GROWSDOWN)
81305+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
81306+#ifdef CONFIG_STACK_GROWSUP
81307+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
81308+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
81309+#endif
81310+ else if (offset)
81311+ return offset <= vma->vm_start - addr - len;
81312+
81313+ return true;
81314+}
81315+
81316+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
81317+{
81318+ if (vma->vm_start < len)
81319+ return -ENOMEM;
81320+
81321+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
81322+ if (offset <= vma->vm_start - len)
81323+ return vma->vm_start - len - offset;
81324+ else
81325+ return -ENOMEM;
81326+ }
81327+
81328+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
81329+ return vma->vm_start - len - sysctl_heap_stack_gap;
81330+ return -ENOMEM;
81331+}
81332+
81333 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
81334 {
81335 /*
81336@@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81337 struct mm_struct *mm = current->mm;
81338 struct vm_area_struct *vma;
81339 struct vm_unmapped_area_info info;
81340+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
81341
81342 if (len > TASK_SIZE)
81343 return -ENOMEM;
81344@@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81345 if (flags & MAP_FIXED)
81346 return addr;
81347
81348+#ifdef CONFIG_PAX_RANDMMAP
81349+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
81350+#endif
81351+
81352 if (addr) {
81353 addr = PAGE_ALIGN(addr);
81354 vma = find_vma(mm, addr);
81355- if (TASK_SIZE - len >= addr &&
81356- (!vma || addr + len <= vma->vm_start))
81357+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
81358 return addr;
81359 }
81360
81361 info.flags = 0;
81362 info.length = len;
81363 info.low_limit = TASK_UNMAPPED_BASE;
81364+
81365+#ifdef CONFIG_PAX_RANDMMAP
81366+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81367+ info.low_limit += mm->delta_mmap;
81368+#endif
81369+
81370 info.high_limit = TASK_SIZE;
81371 info.align_mask = 0;
81372 return vm_unmapped_area(&info);
81373@@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
81374
81375 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
81376 {
81377+
81378+#ifdef CONFIG_PAX_SEGMEXEC
81379+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
81380+ return;
81381+#endif
81382+
81383 /*
81384 * Is this a new hole at the lowest possible address?
81385 */
81386- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
81387+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
81388 mm->free_area_cache = addr;
81389 }
81390
81391@@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81392 struct mm_struct *mm = current->mm;
81393 unsigned long addr = addr0;
81394 struct vm_unmapped_area_info info;
81395+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
81396
81397 /* requested length too big for entire address space */
81398 if (len > TASK_SIZE)
81399@@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81400 if (flags & MAP_FIXED)
81401 return addr;
81402
81403+#ifdef CONFIG_PAX_RANDMMAP
81404+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
81405+#endif
81406+
81407 /* requesting a specific address */
81408 if (addr) {
81409 addr = PAGE_ALIGN(addr);
81410 vma = find_vma(mm, addr);
81411- if (TASK_SIZE - len >= addr &&
81412- (!vma || addr + len <= vma->vm_start))
81413+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
81414 return addr;
81415 }
81416
81417@@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81418 VM_BUG_ON(addr != -ENOMEM);
81419 info.flags = 0;
81420 info.low_limit = TASK_UNMAPPED_BASE;
81421+
81422+#ifdef CONFIG_PAX_RANDMMAP
81423+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81424+ info.low_limit += mm->delta_mmap;
81425+#endif
81426+
81427 info.high_limit = TASK_SIZE;
81428 addr = vm_unmapped_area(&info);
81429 }
81430@@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
81431
81432 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
81433 {
81434+
81435+#ifdef CONFIG_PAX_SEGMEXEC
81436+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
81437+ return;
81438+#endif
81439+
81440 /*
81441 * Is this a new hole at the highest possible address?
81442 */
81443@@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
81444 mm->free_area_cache = addr;
81445
81446 /* dont allow allocations above current base */
81447- if (mm->free_area_cache > mm->mmap_base)
81448+ if (mm->free_area_cache > mm->mmap_base) {
81449 mm->free_area_cache = mm->mmap_base;
81450+ mm->cached_hole_size = ~0UL;
81451+ }
81452 }
81453
81454 unsigned long
81455@@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
81456 return vma;
81457 }
81458
81459+#ifdef CONFIG_PAX_SEGMEXEC
81460+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
81461+{
81462+ struct vm_area_struct *vma_m;
81463+
81464+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
81465+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
81466+ BUG_ON(vma->vm_mirror);
81467+ return NULL;
81468+ }
81469+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
81470+ vma_m = vma->vm_mirror;
81471+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
81472+ BUG_ON(vma->vm_file != vma_m->vm_file);
81473+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
81474+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
81475+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
81476+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
81477+ return vma_m;
81478+}
81479+#endif
81480+
81481 /*
81482 * Verify that the stack growth is acceptable and
81483 * update accounting. This is shared with both the
81484@@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81485 return -ENOMEM;
81486
81487 /* Stack limit test */
81488+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
81489 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
81490 return -ENOMEM;
81491
81492@@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81493 locked = mm->locked_vm + grow;
81494 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
81495 limit >>= PAGE_SHIFT;
81496+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81497 if (locked > limit && !capable(CAP_IPC_LOCK))
81498 return -ENOMEM;
81499 }
81500@@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
81501 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
81502 * vma is the last one with address > vma->vm_end. Have to extend vma.
81503 */
81504+#ifndef CONFIG_IA64
81505+static
81506+#endif
81507 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
81508 {
81509 int error;
81510+ bool locknext;
81511
81512 if (!(vma->vm_flags & VM_GROWSUP))
81513 return -EFAULT;
81514
81515+ /* Also guard against wrapping around to address 0. */
81516+ if (address < PAGE_ALIGN(address+1))
81517+ address = PAGE_ALIGN(address+1);
81518+ else
81519+ return -ENOMEM;
81520+
81521 /*
81522 * We must make sure the anon_vma is allocated
81523 * so that the anon_vma locking is not a noop.
81524 */
81525 if (unlikely(anon_vma_prepare(vma)))
81526 return -ENOMEM;
81527+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
81528+ if (locknext && anon_vma_prepare(vma->vm_next))
81529+ return -ENOMEM;
81530 vma_lock_anon_vma(vma);
81531+ if (locknext)
81532+ vma_lock_anon_vma(vma->vm_next);
81533
81534 /*
81535 * vma->vm_start/vm_end cannot change under us because the caller
81536 * is required to hold the mmap_sem in read mode. We need the
81537- * anon_vma lock to serialize against concurrent expand_stacks.
81538- * Also guard against wrapping around to address 0.
81539+ * anon_vma locks to serialize against concurrent expand_stacks
81540+ * and expand_upwards.
81541 */
81542- if (address < PAGE_ALIGN(address+4))
81543- address = PAGE_ALIGN(address+4);
81544- else {
81545- vma_unlock_anon_vma(vma);
81546- return -ENOMEM;
81547- }
81548 error = 0;
81549
81550 /* Somebody else might have raced and expanded it already */
81551- if (address > vma->vm_end) {
81552+ 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)
81553+ error = -ENOMEM;
81554+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
81555 unsigned long size, grow;
81556
81557 size = address - vma->vm_start;
81558@@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
81559 }
81560 }
81561 }
81562+ if (locknext)
81563+ vma_unlock_anon_vma(vma->vm_next);
81564 vma_unlock_anon_vma(vma);
81565 khugepaged_enter_vma_merge(vma);
81566 validate_mm(vma->vm_mm);
81567@@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
81568 unsigned long address)
81569 {
81570 int error;
81571+ bool lockprev = false;
81572+ struct vm_area_struct *prev;
81573
81574 /*
81575 * We must make sure the anon_vma is allocated
81576@@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
81577 if (error)
81578 return error;
81579
81580+ prev = vma->vm_prev;
81581+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
81582+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
81583+#endif
81584+ if (lockprev && anon_vma_prepare(prev))
81585+ return -ENOMEM;
81586+ if (lockprev)
81587+ vma_lock_anon_vma(prev);
81588+
81589 vma_lock_anon_vma(vma);
81590
81591 /*
81592@@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
81593 */
81594
81595 /* Somebody else might have raced and expanded it already */
81596- if (address < vma->vm_start) {
81597+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
81598+ error = -ENOMEM;
81599+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
81600 unsigned long size, grow;
81601
81602+#ifdef CONFIG_PAX_SEGMEXEC
81603+ struct vm_area_struct *vma_m;
81604+
81605+ vma_m = pax_find_mirror_vma(vma);
81606+#endif
81607+
81608 size = vma->vm_end - address;
81609 grow = (vma->vm_start - address) >> PAGE_SHIFT;
81610
81611@@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
81612 vma->vm_pgoff -= grow;
81613 anon_vma_interval_tree_post_update_vma(vma);
81614 vma_gap_update(vma);
81615+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
81616+
81617+#ifdef CONFIG_PAX_SEGMEXEC
81618+ if (vma_m) {
81619+ anon_vma_interval_tree_pre_update_vma(vma_m);
81620+ vma_m->vm_start -= grow << PAGE_SHIFT;
81621+ vma_m->vm_pgoff -= grow;
81622+ anon_vma_interval_tree_post_update_vma(vma_m);
81623+ vma_gap_update(vma_m);
81624+ }
81625+#endif
81626+
81627 spin_unlock(&vma->vm_mm->page_table_lock);
81628
81629 perf_event_mmap(vma);
81630@@ -2263,6 +2571,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
81631 do {
81632 long nrpages = vma_pages(vma);
81633
81634+#ifdef CONFIG_PAX_SEGMEXEC
81635+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
81636+ vma = remove_vma(vma);
81637+ continue;
81638+ }
81639+#endif
81640+
81641 if (vma->vm_flags & VM_ACCOUNT)
81642 nr_accounted += nrpages;
81643 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
81644@@ -2308,6 +2623,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
81645 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
81646 vma->vm_prev = NULL;
81647 do {
81648+
81649+#ifdef CONFIG_PAX_SEGMEXEC
81650+ if (vma->vm_mirror) {
81651+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
81652+ vma->vm_mirror->vm_mirror = NULL;
81653+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
81654+ vma->vm_mirror = NULL;
81655+ }
81656+#endif
81657+
81658 vma_rb_erase(vma, &mm->mm_rb);
81659 mm->map_count--;
81660 tail_vma = vma;
81661@@ -2339,14 +2664,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81662 struct vm_area_struct *new;
81663 int err = -ENOMEM;
81664
81665+#ifdef CONFIG_PAX_SEGMEXEC
81666+ struct vm_area_struct *vma_m, *new_m = NULL;
81667+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
81668+#endif
81669+
81670 if (is_vm_hugetlb_page(vma) && (addr &
81671 ~(huge_page_mask(hstate_vma(vma)))))
81672 return -EINVAL;
81673
81674+#ifdef CONFIG_PAX_SEGMEXEC
81675+ vma_m = pax_find_mirror_vma(vma);
81676+#endif
81677+
81678 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81679 if (!new)
81680 goto out_err;
81681
81682+#ifdef CONFIG_PAX_SEGMEXEC
81683+ if (vma_m) {
81684+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81685+ if (!new_m) {
81686+ kmem_cache_free(vm_area_cachep, new);
81687+ goto out_err;
81688+ }
81689+ }
81690+#endif
81691+
81692 /* most fields are the same, copy all, and then fixup */
81693 *new = *vma;
81694
81695@@ -2359,6 +2703,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81696 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
81697 }
81698
81699+#ifdef CONFIG_PAX_SEGMEXEC
81700+ if (vma_m) {
81701+ *new_m = *vma_m;
81702+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
81703+ new_m->vm_mirror = new;
81704+ new->vm_mirror = new_m;
81705+
81706+ if (new_below)
81707+ new_m->vm_end = addr_m;
81708+ else {
81709+ new_m->vm_start = addr_m;
81710+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
81711+ }
81712+ }
81713+#endif
81714+
81715 pol = mpol_dup(vma_policy(vma));
81716 if (IS_ERR(pol)) {
81717 err = PTR_ERR(pol);
81718@@ -2381,6 +2741,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81719 else
81720 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
81721
81722+#ifdef CONFIG_PAX_SEGMEXEC
81723+ if (!err && vma_m) {
81724+ if (anon_vma_clone(new_m, vma_m))
81725+ goto out_free_mpol;
81726+
81727+ mpol_get(pol);
81728+ vma_set_policy(new_m, pol);
81729+
81730+ if (new_m->vm_file)
81731+ get_file(new_m->vm_file);
81732+
81733+ if (new_m->vm_ops && new_m->vm_ops->open)
81734+ new_m->vm_ops->open(new_m);
81735+
81736+ if (new_below)
81737+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
81738+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
81739+ else
81740+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
81741+
81742+ if (err) {
81743+ if (new_m->vm_ops && new_m->vm_ops->close)
81744+ new_m->vm_ops->close(new_m);
81745+ if (new_m->vm_file)
81746+ fput(new_m->vm_file);
81747+ mpol_put(pol);
81748+ }
81749+ }
81750+#endif
81751+
81752 /* Success. */
81753 if (!err)
81754 return 0;
81755@@ -2390,10 +2780,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81756 new->vm_ops->close(new);
81757 if (new->vm_file)
81758 fput(new->vm_file);
81759- unlink_anon_vmas(new);
81760 out_free_mpol:
81761 mpol_put(pol);
81762 out_free_vma:
81763+
81764+#ifdef CONFIG_PAX_SEGMEXEC
81765+ if (new_m) {
81766+ unlink_anon_vmas(new_m);
81767+ kmem_cache_free(vm_area_cachep, new_m);
81768+ }
81769+#endif
81770+
81771+ unlink_anon_vmas(new);
81772 kmem_cache_free(vm_area_cachep, new);
81773 out_err:
81774 return err;
81775@@ -2406,6 +2804,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81776 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81777 unsigned long addr, int new_below)
81778 {
81779+
81780+#ifdef CONFIG_PAX_SEGMEXEC
81781+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81782+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
81783+ if (mm->map_count >= sysctl_max_map_count-1)
81784+ return -ENOMEM;
81785+ } else
81786+#endif
81787+
81788 if (mm->map_count >= sysctl_max_map_count)
81789 return -ENOMEM;
81790
81791@@ -2417,11 +2824,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81792 * work. This now handles partial unmappings.
81793 * Jeremy Fitzhardinge <jeremy@goop.org>
81794 */
81795+#ifdef CONFIG_PAX_SEGMEXEC
81796 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81797 {
81798+ int ret = __do_munmap(mm, start, len);
81799+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
81800+ return ret;
81801+
81802+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
81803+}
81804+
81805+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81806+#else
81807+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81808+#endif
81809+{
81810 unsigned long end;
81811 struct vm_area_struct *vma, *prev, *last;
81812
81813+ /*
81814+ * mm->mmap_sem is required to protect against another thread
81815+ * changing the mappings in case we sleep.
81816+ */
81817+ verify_mm_writelocked(mm);
81818+
81819 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
81820 return -EINVAL;
81821
81822@@ -2496,6 +2922,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81823 /* Fix up all other VM information */
81824 remove_vma_list(mm, vma);
81825
81826+ track_exec_limit(mm, start, end, 0UL);
81827+
81828 return 0;
81829 }
81830
81831@@ -2504,6 +2932,13 @@ int vm_munmap(unsigned long start, size_t len)
81832 int ret;
81833 struct mm_struct *mm = current->mm;
81834
81835+
81836+#ifdef CONFIG_PAX_SEGMEXEC
81837+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
81838+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
81839+ return -EINVAL;
81840+#endif
81841+
81842 down_write(&mm->mmap_sem);
81843 ret = do_munmap(mm, start, len);
81844 up_write(&mm->mmap_sem);
81845@@ -2517,16 +2952,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
81846 return vm_munmap(addr, len);
81847 }
81848
81849-static inline void verify_mm_writelocked(struct mm_struct *mm)
81850-{
81851-#ifdef CONFIG_DEBUG_VM
81852- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81853- WARN_ON(1);
81854- up_read(&mm->mmap_sem);
81855- }
81856-#endif
81857-}
81858-
81859 /*
81860 * this is really a simplified "do_mmap". it only handles
81861 * anonymous maps. eventually we may be able to do some
81862@@ -2540,6 +2965,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81863 struct rb_node ** rb_link, * rb_parent;
81864 pgoff_t pgoff = addr >> PAGE_SHIFT;
81865 int error;
81866+ unsigned long charged;
81867
81868 len = PAGE_ALIGN(len);
81869 if (!len)
81870@@ -2547,16 +2973,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81871
81872 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
81873
81874+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
81875+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
81876+ flags &= ~VM_EXEC;
81877+
81878+#ifdef CONFIG_PAX_MPROTECT
81879+ if (mm->pax_flags & MF_PAX_MPROTECT)
81880+ flags &= ~VM_MAYEXEC;
81881+#endif
81882+
81883+ }
81884+#endif
81885+
81886 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
81887 if (error & ~PAGE_MASK)
81888 return error;
81889
81890+ charged = len >> PAGE_SHIFT;
81891+
81892 /*
81893 * mlock MCL_FUTURE?
81894 */
81895 if (mm->def_flags & VM_LOCKED) {
81896 unsigned long locked, lock_limit;
81897- locked = len >> PAGE_SHIFT;
81898+ locked = charged;
81899 locked += mm->locked_vm;
81900 lock_limit = rlimit(RLIMIT_MEMLOCK);
81901 lock_limit >>= PAGE_SHIFT;
81902@@ -2573,21 +3013,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81903 /*
81904 * Clear old maps. this also does some error checking for us
81905 */
81906- munmap_back:
81907 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81908 if (do_munmap(mm, addr, len))
81909 return -ENOMEM;
81910- goto munmap_back;
81911+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81912 }
81913
81914 /* Check against address space limits *after* clearing old maps... */
81915- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
81916+ if (!may_expand_vm(mm, charged))
81917 return -ENOMEM;
81918
81919 if (mm->map_count > sysctl_max_map_count)
81920 return -ENOMEM;
81921
81922- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
81923+ if (security_vm_enough_memory_mm(mm, charged))
81924 return -ENOMEM;
81925
81926 /* Can we just expand an old private anonymous mapping? */
81927@@ -2601,7 +3040,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81928 */
81929 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81930 if (!vma) {
81931- vm_unacct_memory(len >> PAGE_SHIFT);
81932+ vm_unacct_memory(charged);
81933 return -ENOMEM;
81934 }
81935
81936@@ -2615,11 +3054,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81937 vma_link(mm, vma, prev, rb_link, rb_parent);
81938 out:
81939 perf_event_mmap(vma);
81940- mm->total_vm += len >> PAGE_SHIFT;
81941+ mm->total_vm += charged;
81942 if (flags & VM_LOCKED) {
81943 if (!mlock_vma_pages_range(vma, addr, addr + len))
81944- mm->locked_vm += (len >> PAGE_SHIFT);
81945+ mm->locked_vm += charged;
81946 }
81947+ track_exec_limit(mm, addr, addr + len, flags);
81948 return addr;
81949 }
81950
81951@@ -2677,6 +3117,7 @@ void exit_mmap(struct mm_struct *mm)
81952 while (vma) {
81953 if (vma->vm_flags & VM_ACCOUNT)
81954 nr_accounted += vma_pages(vma);
81955+ vma->vm_mirror = NULL;
81956 vma = remove_vma(vma);
81957 }
81958 vm_unacct_memory(nr_accounted);
81959@@ -2693,6 +3134,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81960 struct vm_area_struct *prev;
81961 struct rb_node **rb_link, *rb_parent;
81962
81963+#ifdef CONFIG_PAX_SEGMEXEC
81964+ struct vm_area_struct *vma_m = NULL;
81965+#endif
81966+
81967+ if (security_mmap_addr(vma->vm_start))
81968+ return -EPERM;
81969+
81970 /*
81971 * The vm_pgoff of a purely anonymous vma should be irrelevant
81972 * until its first write fault, when page's anon_vma and index
81973@@ -2716,7 +3164,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81974 security_vm_enough_memory_mm(mm, vma_pages(vma)))
81975 return -ENOMEM;
81976
81977+#ifdef CONFIG_PAX_SEGMEXEC
81978+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
81979+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81980+ if (!vma_m)
81981+ return -ENOMEM;
81982+ }
81983+#endif
81984+
81985 vma_link(mm, vma, prev, rb_link, rb_parent);
81986+
81987+#ifdef CONFIG_PAX_SEGMEXEC
81988+ if (vma_m)
81989+ BUG_ON(pax_mirror_vma(vma_m, vma));
81990+#endif
81991+
81992 return 0;
81993 }
81994
81995@@ -2736,6 +3198,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81996 struct mempolicy *pol;
81997 bool faulted_in_anon_vma = true;
81998
81999+ BUG_ON(vma->vm_mirror);
82000+
82001 /*
82002 * If anonymous vma has not yet been faulted, update new pgoff
82003 * to match new location, to increase its chance of merging.
82004@@ -2802,6 +3266,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82005 return NULL;
82006 }
82007
82008+#ifdef CONFIG_PAX_SEGMEXEC
82009+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
82010+{
82011+ struct vm_area_struct *prev_m;
82012+ struct rb_node **rb_link_m, *rb_parent_m;
82013+ struct mempolicy *pol_m;
82014+
82015+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
82016+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
82017+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
82018+ *vma_m = *vma;
82019+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
82020+ if (anon_vma_clone(vma_m, vma))
82021+ return -ENOMEM;
82022+ pol_m = vma_policy(vma_m);
82023+ mpol_get(pol_m);
82024+ vma_set_policy(vma_m, pol_m);
82025+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
82026+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
82027+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
82028+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
82029+ if (vma_m->vm_file)
82030+ get_file(vma_m->vm_file);
82031+ if (vma_m->vm_ops && vma_m->vm_ops->open)
82032+ vma_m->vm_ops->open(vma_m);
82033+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
82034+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
82035+ vma_m->vm_mirror = vma;
82036+ vma->vm_mirror = vma_m;
82037+ return 0;
82038+}
82039+#endif
82040+
82041 /*
82042 * Return true if the calling process may expand its vm space by the passed
82043 * number of pages
82044@@ -2813,6 +3310,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
82045
82046 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
82047
82048+#ifdef CONFIG_PAX_RANDMMAP
82049+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82050+ cur -= mm->aslr_gap;
82051+#endif
82052+
82053+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
82054 if (cur + npages > lim)
82055 return 0;
82056 return 1;
82057@@ -2883,6 +3386,22 @@ int install_special_mapping(struct mm_struct *mm,
82058 vma->vm_start = addr;
82059 vma->vm_end = addr + len;
82060
82061+#ifdef CONFIG_PAX_MPROTECT
82062+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82063+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82064+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
82065+ return -EPERM;
82066+ if (!(vm_flags & VM_EXEC))
82067+ vm_flags &= ~VM_MAYEXEC;
82068+#else
82069+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82070+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82071+#endif
82072+ else
82073+ vm_flags &= ~VM_MAYWRITE;
82074+ }
82075+#endif
82076+
82077 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
82078 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82079
82080diff --git a/mm/mprotect.c b/mm/mprotect.c
82081index 94722a4..9837984 100644
82082--- a/mm/mprotect.c
82083+++ b/mm/mprotect.c
82084@@ -23,10 +23,17 @@
82085 #include <linux/mmu_notifier.h>
82086 #include <linux/migrate.h>
82087 #include <linux/perf_event.h>
82088+
82089+#ifdef CONFIG_PAX_MPROTECT
82090+#include <linux/elf.h>
82091+#include <linux/binfmts.h>
82092+#endif
82093+
82094 #include <asm/uaccess.h>
82095 #include <asm/pgtable.h>
82096 #include <asm/cacheflush.h>
82097 #include <asm/tlbflush.h>
82098+#include <asm/mmu_context.h>
82099
82100 #ifndef pgprot_modify
82101 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
82102@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
82103 return pages;
82104 }
82105
82106+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82107+/* called while holding the mmap semaphor for writing except stack expansion */
82108+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
82109+{
82110+ unsigned long oldlimit, newlimit = 0UL;
82111+
82112+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
82113+ return;
82114+
82115+ spin_lock(&mm->page_table_lock);
82116+ oldlimit = mm->context.user_cs_limit;
82117+ if ((prot & VM_EXEC) && oldlimit < end)
82118+ /* USER_CS limit moved up */
82119+ newlimit = end;
82120+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
82121+ /* USER_CS limit moved down */
82122+ newlimit = start;
82123+
82124+ if (newlimit) {
82125+ mm->context.user_cs_limit = newlimit;
82126+
82127+#ifdef CONFIG_SMP
82128+ wmb();
82129+ cpus_clear(mm->context.cpu_user_cs_mask);
82130+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
82131+#endif
82132+
82133+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
82134+ }
82135+ spin_unlock(&mm->page_table_lock);
82136+ if (newlimit == end) {
82137+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
82138+
82139+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
82140+ if (is_vm_hugetlb_page(vma))
82141+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
82142+ else
82143+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
82144+ }
82145+}
82146+#endif
82147+
82148 int
82149 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82150 unsigned long start, unsigned long end, unsigned long newflags)
82151@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82152 int error;
82153 int dirty_accountable = 0;
82154
82155+#ifdef CONFIG_PAX_SEGMEXEC
82156+ struct vm_area_struct *vma_m = NULL;
82157+ unsigned long start_m, end_m;
82158+
82159+ start_m = start + SEGMEXEC_TASK_SIZE;
82160+ end_m = end + SEGMEXEC_TASK_SIZE;
82161+#endif
82162+
82163 if (newflags == oldflags) {
82164 *pprev = vma;
82165 return 0;
82166 }
82167
82168+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
82169+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
82170+
82171+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
82172+ return -ENOMEM;
82173+
82174+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
82175+ return -ENOMEM;
82176+ }
82177+
82178 /*
82179 * If we make a private mapping writable we increase our commit;
82180 * but (without finer accounting) cannot reduce our commit if we
82181@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82182 }
82183 }
82184
82185+#ifdef CONFIG_PAX_SEGMEXEC
82186+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
82187+ if (start != vma->vm_start) {
82188+ error = split_vma(mm, vma, start, 1);
82189+ if (error)
82190+ goto fail;
82191+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
82192+ *pprev = (*pprev)->vm_next;
82193+ }
82194+
82195+ if (end != vma->vm_end) {
82196+ error = split_vma(mm, vma, end, 0);
82197+ if (error)
82198+ goto fail;
82199+ }
82200+
82201+ if (pax_find_mirror_vma(vma)) {
82202+ error = __do_munmap(mm, start_m, end_m - start_m);
82203+ if (error)
82204+ goto fail;
82205+ } else {
82206+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82207+ if (!vma_m) {
82208+ error = -ENOMEM;
82209+ goto fail;
82210+ }
82211+ vma->vm_flags = newflags;
82212+ error = pax_mirror_vma(vma_m, vma);
82213+ if (error) {
82214+ vma->vm_flags = oldflags;
82215+ goto fail;
82216+ }
82217+ }
82218+ }
82219+#endif
82220+
82221 /*
82222 * First try to merge with previous and/or next vma.
82223 */
82224@@ -296,9 +399,21 @@ success:
82225 * vm_flags and vm_page_prot are protected by the mmap_sem
82226 * held in write mode.
82227 */
82228+
82229+#ifdef CONFIG_PAX_SEGMEXEC
82230+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
82231+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
82232+#endif
82233+
82234 vma->vm_flags = newflags;
82235+
82236+#ifdef CONFIG_PAX_MPROTECT
82237+ if (mm->binfmt && mm->binfmt->handle_mprotect)
82238+ mm->binfmt->handle_mprotect(vma, newflags);
82239+#endif
82240+
82241 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
82242- vm_get_page_prot(newflags));
82243+ vm_get_page_prot(vma->vm_flags));
82244
82245 if (vma_wants_writenotify(vma)) {
82246 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
82247@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82248 end = start + len;
82249 if (end <= start)
82250 return -ENOMEM;
82251+
82252+#ifdef CONFIG_PAX_SEGMEXEC
82253+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
82254+ if (end > SEGMEXEC_TASK_SIZE)
82255+ return -EINVAL;
82256+ } else
82257+#endif
82258+
82259+ if (end > TASK_SIZE)
82260+ return -EINVAL;
82261+
82262 if (!arch_validate_prot(prot))
82263 return -EINVAL;
82264
82265@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82266 /*
82267 * Does the application expect PROT_READ to imply PROT_EXEC:
82268 */
82269- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82270+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82271 prot |= PROT_EXEC;
82272
82273 vm_flags = calc_vm_prot_bits(prot);
82274@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82275 if (start > vma->vm_start)
82276 prev = vma;
82277
82278+#ifdef CONFIG_PAX_MPROTECT
82279+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
82280+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
82281+#endif
82282+
82283 for (nstart = start ; ; ) {
82284 unsigned long newflags;
82285
82286@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82287
82288 /* newflags >> 4 shift VM_MAY% in place of VM_% */
82289 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
82290+ if (prot & (PROT_WRITE | PROT_EXEC))
82291+ gr_log_rwxmprotect(vma->vm_file);
82292+
82293+ error = -EACCES;
82294+ goto out;
82295+ }
82296+
82297+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
82298 error = -EACCES;
82299 goto out;
82300 }
82301@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
82302 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
82303 if (error)
82304 goto out;
82305+
82306+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
82307+
82308 nstart = tmp;
82309
82310 if (nstart < prev->vm_end)
82311diff --git a/mm/mremap.c b/mm/mremap.c
82312index e1031e1..1f2a0a1 100644
82313--- a/mm/mremap.c
82314+++ b/mm/mremap.c
82315@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
82316 continue;
82317 pte = ptep_get_and_clear(mm, old_addr, old_pte);
82318 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
82319+
82320+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82321+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
82322+ pte = pte_exprotect(pte);
82323+#endif
82324+
82325 set_pte_at(mm, new_addr, new_pte, pte);
82326 }
82327
82328@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
82329 if (is_vm_hugetlb_page(vma))
82330 goto Einval;
82331
82332+#ifdef CONFIG_PAX_SEGMEXEC
82333+ if (pax_find_mirror_vma(vma))
82334+ goto Einval;
82335+#endif
82336+
82337 /* We can't remap across vm area boundaries */
82338 if (old_len > vma->vm_end - addr)
82339 goto Efault;
82340@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
82341 unsigned long ret = -EINVAL;
82342 unsigned long charged = 0;
82343 unsigned long map_flags;
82344+ unsigned long pax_task_size = TASK_SIZE;
82345
82346 if (new_addr & ~PAGE_MASK)
82347 goto out;
82348
82349- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
82350+#ifdef CONFIG_PAX_SEGMEXEC
82351+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
82352+ pax_task_size = SEGMEXEC_TASK_SIZE;
82353+#endif
82354+
82355+ pax_task_size -= PAGE_SIZE;
82356+
82357+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
82358 goto out;
82359
82360 /* Check if the location we're moving into overlaps the
82361 * old location at all, and fail if it does.
82362 */
82363- if ((new_addr <= addr) && (new_addr+new_len) > addr)
82364- goto out;
82365-
82366- if ((addr <= new_addr) && (addr+old_len) > new_addr)
82367+ if (addr + old_len > new_addr && new_addr + new_len > addr)
82368 goto out;
82369
82370 ret = do_munmap(mm, new_addr, new_len);
82371@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82372 struct vm_area_struct *vma;
82373 unsigned long ret = -EINVAL;
82374 unsigned long charged = 0;
82375+ unsigned long pax_task_size = TASK_SIZE;
82376
82377 down_write(&current->mm->mmap_sem);
82378
82379@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82380 if (!new_len)
82381 goto out;
82382
82383+#ifdef CONFIG_PAX_SEGMEXEC
82384+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
82385+ pax_task_size = SEGMEXEC_TASK_SIZE;
82386+#endif
82387+
82388+ pax_task_size -= PAGE_SIZE;
82389+
82390+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
82391+ old_len > pax_task_size || addr > pax_task_size-old_len)
82392+ goto out;
82393+
82394 if (flags & MREMAP_FIXED) {
82395 if (flags & MREMAP_MAYMOVE)
82396 ret = mremap_to(addr, old_len, new_addr, new_len);
82397@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82398 addr + new_len);
82399 }
82400 ret = addr;
82401+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
82402 goto out;
82403 }
82404 }
82405@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
82406 goto out;
82407 }
82408
82409+ map_flags = vma->vm_flags;
82410 ret = move_vma(vma, addr, old_len, new_len, new_addr);
82411+ if (!(ret & ~PAGE_MASK)) {
82412+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
82413+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
82414+ }
82415 }
82416 out:
82417 if (ret & ~PAGE_MASK)
82418diff --git a/mm/nommu.c b/mm/nommu.c
82419index 79c3cac..4d357e0 100644
82420--- a/mm/nommu.c
82421+++ b/mm/nommu.c
82422@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
82423 int sysctl_overcommit_ratio = 50; /* default is 50% */
82424 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
82425 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
82426-int heap_stack_gap = 0;
82427
82428 atomic_long_t mmap_pages_allocated;
82429
82430@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
82431 EXPORT_SYMBOL(find_vma);
82432
82433 /*
82434- * find a VMA
82435- * - we don't extend stack VMAs under NOMMU conditions
82436- */
82437-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
82438-{
82439- return find_vma(mm, addr);
82440-}
82441-
82442-/*
82443 * expand a stack to a given address
82444 * - not supported under NOMMU conditions
82445 */
82446@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82447
82448 /* most fields are the same, copy all, and then fixup */
82449 *new = *vma;
82450+ INIT_LIST_HEAD(&new->anon_vma_chain);
82451 *region = *vma->vm_region;
82452 new->vm_region = region;
82453
82454diff --git a/mm/page-writeback.c b/mm/page-writeback.c
82455index 0713bfb..b95bb87 100644
82456--- a/mm/page-writeback.c
82457+++ b/mm/page-writeback.c
82458@@ -655,7 +655,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
82459 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
82460 * - the bdi dirty thresh drops quickly due to change of JBOD workload
82461 */
82462-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
82463+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
82464 unsigned long thresh,
82465 unsigned long bg_thresh,
82466 unsigned long dirty,
82467@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
82468 }
82469 }
82470
82471-static struct notifier_block __cpuinitdata ratelimit_nb = {
82472+static struct notifier_block ratelimit_nb = {
82473 .notifier_call = ratelimit_handler,
82474 .next = NULL,
82475 };
82476diff --git a/mm/page_alloc.c b/mm/page_alloc.c
82477index 6a83cd3..3ab04ef 100644
82478--- a/mm/page_alloc.c
82479+++ b/mm/page_alloc.c
82480@@ -58,6 +58,7 @@
82481 #include <linux/prefetch.h>
82482 #include <linux/migrate.h>
82483 #include <linux/page-debug-flags.h>
82484+#include <linux/random.h>
82485
82486 #include <asm/tlbflush.h>
82487 #include <asm/div64.h>
82488@@ -338,7 +339,7 @@ out:
82489 * This usage means that zero-order pages may not be compound.
82490 */
82491
82492-static void free_compound_page(struct page *page)
82493+void free_compound_page(struct page *page)
82494 {
82495 __free_pages_ok(page, compound_order(page));
82496 }
82497@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
82498 int i;
82499 int bad = 0;
82500
82501+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82502+ unsigned long index = 1UL << order;
82503+#endif
82504+
82505 trace_mm_page_free(page, order);
82506 kmemcheck_free_shadow(page, order);
82507
82508@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
82509 debug_check_no_obj_freed(page_address(page),
82510 PAGE_SIZE << order);
82511 }
82512+
82513+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82514+ for (; index; --index)
82515+ sanitize_highpage(page + index - 1);
82516+#endif
82517+
82518 arch_free_page(page, order);
82519 kernel_map_pages(page, 1 << order, 0);
82520
82521@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
82522 local_irq_restore(flags);
82523 }
82524
82525+#ifdef CONFIG_PAX_LATENT_ENTROPY
82526+bool __meminitdata extra_latent_entropy;
82527+
82528+static int __init setup_pax_extra_latent_entropy(char *str)
82529+{
82530+ extra_latent_entropy = true;
82531+ return 0;
82532+}
82533+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
82534+
82535+volatile u64 latent_entropy;
82536+#endif
82537+
82538 /*
82539 * Read access to zone->managed_pages is safe because it's unsigned long,
82540 * but we still need to serialize writers. Currently all callers of
82541@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
82542 set_page_count(p, 0);
82543 }
82544
82545+#ifdef CONFIG_PAX_LATENT_ENTROPY
82546+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
82547+ u64 hash = 0;
82548+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
82549+ const u64 *data = lowmem_page_address(page);
82550+
82551+ for (index = 0; index < end; index++)
82552+ hash ^= hash + data[index];
82553+ latent_entropy ^= hash;
82554+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
82555+ }
82556+#endif
82557+
82558 page_zone(page)->managed_pages += 1 << order;
82559 set_page_refcounted(page);
82560 __free_pages(page, order);
82561@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
82562 arch_alloc_page(page, order);
82563 kernel_map_pages(page, 1 << order, 1);
82564
82565+#ifndef CONFIG_PAX_MEMORY_SANITIZE
82566 if (gfp_flags & __GFP_ZERO)
82567 prep_zero_page(page, order, gfp_flags);
82568+#endif
82569
82570 if (order && (gfp_flags & __GFP_COMP))
82571 prep_compound_page(page, order);
82572@@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
82573 unsigned long pfn;
82574
82575 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
82576+#ifdef CONFIG_X86_32
82577+ /* boot failures in VMware 8 on 32bit vanilla since
82578+ this change */
82579+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
82580+#else
82581 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
82582+#endif
82583 return 1;
82584 }
82585 return 0;
82586diff --git a/mm/percpu.c b/mm/percpu.c
82587index 8c8e08f..73a5cda 100644
82588--- a/mm/percpu.c
82589+++ b/mm/percpu.c
82590@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
82591 static unsigned int pcpu_high_unit_cpu __read_mostly;
82592
82593 /* the address of the first chunk which starts with the kernel static area */
82594-void *pcpu_base_addr __read_mostly;
82595+void *pcpu_base_addr __read_only;
82596 EXPORT_SYMBOL_GPL(pcpu_base_addr);
82597
82598 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
82599diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
82600index fd26d04..0cea1b0 100644
82601--- a/mm/process_vm_access.c
82602+++ b/mm/process_vm_access.c
82603@@ -13,6 +13,7 @@
82604 #include <linux/uio.h>
82605 #include <linux/sched.h>
82606 #include <linux/highmem.h>
82607+#include <linux/security.h>
82608 #include <linux/ptrace.h>
82609 #include <linux/slab.h>
82610 #include <linux/syscalls.h>
82611@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
82612 size_t iov_l_curr_offset = 0;
82613 ssize_t iov_len;
82614
82615+ return -ENOSYS; // PaX: until properly audited
82616+
82617 /*
82618 * Work out how many pages of struct pages we're going to need
82619 * when eventually calling get_user_pages
82620 */
82621 for (i = 0; i < riovcnt; i++) {
82622 iov_len = rvec[i].iov_len;
82623- if (iov_len > 0) {
82624- nr_pages_iov = ((unsigned long)rvec[i].iov_base
82625- + iov_len)
82626- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
82627- / PAGE_SIZE + 1;
82628- nr_pages = max(nr_pages, nr_pages_iov);
82629- }
82630+ if (iov_len <= 0)
82631+ continue;
82632+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
82633+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
82634+ nr_pages = max(nr_pages, nr_pages_iov);
82635 }
82636
82637 if (nr_pages == 0)
82638@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
82639 goto free_proc_pages;
82640 }
82641
82642+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
82643+ rc = -EPERM;
82644+ goto put_task_struct;
82645+ }
82646+
82647 mm = mm_access(task, PTRACE_MODE_ATTACH);
82648 if (!mm || IS_ERR(mm)) {
82649 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
82650diff --git a/mm/rmap.c b/mm/rmap.c
82651index 2c78f8c..9e9c624 100644
82652--- a/mm/rmap.c
82653+++ b/mm/rmap.c
82654@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82655 struct anon_vma *anon_vma = vma->anon_vma;
82656 struct anon_vma_chain *avc;
82657
82658+#ifdef CONFIG_PAX_SEGMEXEC
82659+ struct anon_vma_chain *avc_m = NULL;
82660+#endif
82661+
82662 might_sleep();
82663 if (unlikely(!anon_vma)) {
82664 struct mm_struct *mm = vma->vm_mm;
82665@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82666 if (!avc)
82667 goto out_enomem;
82668
82669+#ifdef CONFIG_PAX_SEGMEXEC
82670+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
82671+ if (!avc_m)
82672+ goto out_enomem_free_avc;
82673+#endif
82674+
82675 anon_vma = find_mergeable_anon_vma(vma);
82676 allocated = NULL;
82677 if (!anon_vma) {
82678@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82679 /* page_table_lock to protect against threads */
82680 spin_lock(&mm->page_table_lock);
82681 if (likely(!vma->anon_vma)) {
82682+
82683+#ifdef CONFIG_PAX_SEGMEXEC
82684+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
82685+
82686+ if (vma_m) {
82687+ BUG_ON(vma_m->anon_vma);
82688+ vma_m->anon_vma = anon_vma;
82689+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
82690+ avc_m = NULL;
82691+ }
82692+#endif
82693+
82694 vma->anon_vma = anon_vma;
82695 anon_vma_chain_link(vma, avc, anon_vma);
82696 allocated = NULL;
82697@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82698
82699 if (unlikely(allocated))
82700 put_anon_vma(allocated);
82701+
82702+#ifdef CONFIG_PAX_SEGMEXEC
82703+ if (unlikely(avc_m))
82704+ anon_vma_chain_free(avc_m);
82705+#endif
82706+
82707 if (unlikely(avc))
82708 anon_vma_chain_free(avc);
82709 }
82710 return 0;
82711
82712 out_enomem_free_avc:
82713+
82714+#ifdef CONFIG_PAX_SEGMEXEC
82715+ if (avc_m)
82716+ anon_vma_chain_free(avc_m);
82717+#endif
82718+
82719 anon_vma_chain_free(avc);
82720 out_enomem:
82721 return -ENOMEM;
82722@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
82723 * Attach the anon_vmas from src to dst.
82724 * Returns 0 on success, -ENOMEM on failure.
82725 */
82726-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82727+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
82728 {
82729 struct anon_vma_chain *avc, *pavc;
82730 struct anon_vma *root = NULL;
82731@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82732 * the corresponding VMA in the parent process is attached to.
82733 * Returns 0 on success, non-zero on failure.
82734 */
82735-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
82736+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
82737 {
82738 struct anon_vma_chain *avc;
82739 struct anon_vma *anon_vma;
82740diff --git a/mm/shmem.c b/mm/shmem.c
82741index efd0b3a..994b702 100644
82742--- a/mm/shmem.c
82743+++ b/mm/shmem.c
82744@@ -31,7 +31,7 @@
82745 #include <linux/export.h>
82746 #include <linux/swap.h>
82747
82748-static struct vfsmount *shm_mnt;
82749+struct vfsmount *shm_mnt;
82750
82751 #ifdef CONFIG_SHMEM
82752 /*
82753@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
82754 #define BOGO_DIRENT_SIZE 20
82755
82756 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
82757-#define SHORT_SYMLINK_LEN 128
82758+#define SHORT_SYMLINK_LEN 64
82759
82760 /*
82761 * shmem_fallocate and shmem_writepage communicate via inode->i_private
82762@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
82763 static int shmem_xattr_validate(const char *name)
82764 {
82765 struct { const char *prefix; size_t len; } arr[] = {
82766+
82767+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82768+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
82769+#endif
82770+
82771 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
82772 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
82773 };
82774@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
82775 if (err)
82776 return err;
82777
82778+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82779+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
82780+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
82781+ return -EOPNOTSUPP;
82782+ if (size > 8)
82783+ return -EINVAL;
82784+ }
82785+#endif
82786+
82787 return simple_xattr_set(&info->xattrs, name, value, size, flags);
82788 }
82789
82790@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
82791 int err = -ENOMEM;
82792
82793 /* Round up to L1_CACHE_BYTES to resist false sharing */
82794- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
82795- L1_CACHE_BYTES), GFP_KERNEL);
82796+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
82797 if (!sbinfo)
82798 return -ENOMEM;
82799
82800diff --git a/mm/slab.c b/mm/slab.c
82801index e7667a3..b62c169 100644
82802--- a/mm/slab.c
82803+++ b/mm/slab.c
82804@@ -306,7 +306,7 @@ struct kmem_list3 {
82805 * Need this for bootstrapping a per node allocator.
82806 */
82807 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
82808-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
82809+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
82810 #define CACHE_CACHE 0
82811 #define SIZE_AC MAX_NUMNODES
82812 #define SIZE_L3 (2 * MAX_NUMNODES)
82813@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
82814 if ((x)->max_freeable < i) \
82815 (x)->max_freeable = i; \
82816 } while (0)
82817-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
82818-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
82819-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
82820-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
82821+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
82822+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
82823+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
82824+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
82825 #else
82826 #define STATS_INC_ACTIVE(x) do { } while (0)
82827 #define STATS_DEC_ACTIVE(x) do { } while (0)
82828@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
82829 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
82830 */
82831 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
82832- const struct slab *slab, void *obj)
82833+ const struct slab *slab, const void *obj)
82834 {
82835 u32 offset = (obj - slab->s_mem);
82836 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
82837@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
82838 struct cache_names {
82839 char *name;
82840 char *name_dma;
82841+ char *name_usercopy;
82842 };
82843
82844 static struct cache_names __initdata cache_names[] = {
82845-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
82846+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
82847 #include <linux/kmalloc_sizes.h>
82848- {NULL,}
82849+ {NULL}
82850 #undef CACHE
82851 };
82852
82853@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
82854 if (unlikely(gfpflags & GFP_DMA))
82855 return csizep->cs_dmacachep;
82856 #endif
82857+
82858+#ifdef CONFIG_PAX_USERCOPY_SLABS
82859+ if (unlikely(gfpflags & GFP_USERCOPY))
82860+ return csizep->cs_usercopycachep;
82861+#endif
82862+
82863 return csizep->cs_cachep;
82864 }
82865
82866@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
82867 return notifier_from_errno(err);
82868 }
82869
82870-static struct notifier_block __cpuinitdata cpucache_notifier = {
82871+static struct notifier_block cpucache_notifier = {
82872 &cpuup_callback, NULL, 0
82873 };
82874
82875@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
82876 */
82877
82878 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
82879- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
82880+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82881
82882 if (INDEX_AC != INDEX_L3)
82883 sizes[INDEX_L3].cs_cachep =
82884 create_kmalloc_cache(names[INDEX_L3].name,
82885- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
82886+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82887
82888 slab_early_init = 0;
82889
82890@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
82891 */
82892 if (!sizes->cs_cachep)
82893 sizes->cs_cachep = create_kmalloc_cache(names->name,
82894- sizes->cs_size, ARCH_KMALLOC_FLAGS);
82895+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82896
82897 #ifdef CONFIG_ZONE_DMA
82898 sizes->cs_dmacachep = create_kmalloc_cache(
82899 names->name_dma, sizes->cs_size,
82900 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
82901 #endif
82902+
82903+#ifdef CONFIG_PAX_USERCOPY_SLABS
82904+ sizes->cs_usercopycachep = create_kmalloc_cache(
82905+ names->name_usercopy, sizes->cs_size,
82906+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82907+#endif
82908+
82909 sizes++;
82910 names++;
82911 }
82912@@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
82913 }
82914 /* cpu stats */
82915 {
82916- unsigned long allochit = atomic_read(&cachep->allochit);
82917- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
82918- unsigned long freehit = atomic_read(&cachep->freehit);
82919- unsigned long freemiss = atomic_read(&cachep->freemiss);
82920+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
82921+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
82922+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
82923+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
82924
82925 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
82926 allochit, allocmiss, freehit, freemiss);
82927@@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
82928 static int __init slab_proc_init(void)
82929 {
82930 #ifdef CONFIG_DEBUG_SLAB_LEAK
82931- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
82932+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
82933 #endif
82934 return 0;
82935 }
82936 module_init(slab_proc_init);
82937 #endif
82938
82939+bool is_usercopy_object(const void *ptr)
82940+{
82941+ struct page *page;
82942+ struct kmem_cache *cachep;
82943+
82944+ if (ZERO_OR_NULL_PTR(ptr))
82945+ return false;
82946+
82947+ if (!slab_is_available())
82948+ return false;
82949+
82950+ if (!virt_addr_valid(ptr))
82951+ return false;
82952+
82953+ page = virt_to_head_page(ptr);
82954+
82955+ if (!PageSlab(page))
82956+ return false;
82957+
82958+ cachep = page->slab_cache;
82959+ return cachep->flags & SLAB_USERCOPY;
82960+}
82961+
82962+#ifdef CONFIG_PAX_USERCOPY
82963+const char *check_heap_object(const void *ptr, unsigned long n)
82964+{
82965+ struct page *page;
82966+ struct kmem_cache *cachep;
82967+ struct slab *slabp;
82968+ unsigned int objnr;
82969+ unsigned long offset;
82970+
82971+ if (ZERO_OR_NULL_PTR(ptr))
82972+ return "<null>";
82973+
82974+ if (!virt_addr_valid(ptr))
82975+ return NULL;
82976+
82977+ page = virt_to_head_page(ptr);
82978+
82979+ if (!PageSlab(page))
82980+ return NULL;
82981+
82982+ cachep = page->slab_cache;
82983+ if (!(cachep->flags & SLAB_USERCOPY))
82984+ return cachep->name;
82985+
82986+ slabp = page->slab_page;
82987+ objnr = obj_to_index(cachep, slabp, ptr);
82988+ BUG_ON(objnr >= cachep->num);
82989+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
82990+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
82991+ return NULL;
82992+
82993+ return cachep->name;
82994+}
82995+#endif
82996+
82997 /**
82998 * ksize - get the actual amount of memory allocated for a given object
82999 * @objp: Pointer to the object
83000diff --git a/mm/slab.h b/mm/slab.h
83001index 34a98d6..73633d1 100644
83002--- a/mm/slab.h
83003+++ b/mm/slab.h
83004@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83005
83006 /* Legal flag mask for kmem_cache_create(), for various configurations */
83007 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
83008- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
83009+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
83010
83011 #if defined(CONFIG_DEBUG_SLAB)
83012 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
83013@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
83014 return s;
83015
83016 page = virt_to_head_page(x);
83017+
83018+ BUG_ON(!PageSlab(page));
83019+
83020 cachep = page->slab_cache;
83021 if (slab_equal_or_root(cachep, s))
83022 return cachep;
83023diff --git a/mm/slab_common.c b/mm/slab_common.c
83024index 3f3cd97..93b0236 100644
83025--- a/mm/slab_common.c
83026+++ b/mm/slab_common.c
83027@@ -22,7 +22,7 @@
83028
83029 #include "slab.h"
83030
83031-enum slab_state slab_state;
83032+enum slab_state slab_state __read_only;
83033 LIST_HEAD(slab_caches);
83034 DEFINE_MUTEX(slab_mutex);
83035 struct kmem_cache *kmem_cache;
83036@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
83037
83038 err = __kmem_cache_create(s, flags);
83039 if (!err) {
83040- s->refcount = 1;
83041+ atomic_set(&s->refcount, 1);
83042 list_add(&s->list, &slab_caches);
83043 memcg_cache_list_add(memcg, s);
83044 } else {
83045@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
83046
83047 get_online_cpus();
83048 mutex_lock(&slab_mutex);
83049- s->refcount--;
83050- if (!s->refcount) {
83051+ if (atomic_dec_and_test(&s->refcount)) {
83052 list_del(&s->list);
83053
83054 if (!__kmem_cache_shutdown(s)) {
83055@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
83056 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
83057 name, size, err);
83058
83059- s->refcount = -1; /* Exempt from merging for now */
83060+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
83061 }
83062
83063 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83064@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83065
83066 create_boot_cache(s, name, size, flags);
83067 list_add(&s->list, &slab_caches);
83068- s->refcount = 1;
83069+ atomic_set(&s->refcount, 1);
83070 return s;
83071 }
83072
83073diff --git a/mm/slob.c b/mm/slob.c
83074index a99fdf7..f5b6577 100644
83075--- a/mm/slob.c
83076+++ b/mm/slob.c
83077@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
83078 /*
83079 * Return the size of a slob block.
83080 */
83081-static slobidx_t slob_units(slob_t *s)
83082+static slobidx_t slob_units(const slob_t *s)
83083 {
83084 if (s->units > 0)
83085 return s->units;
83086@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
83087 /*
83088 * Return the next free slob block pointer after this one.
83089 */
83090-static slob_t *slob_next(slob_t *s)
83091+static slob_t *slob_next(const slob_t *s)
83092 {
83093 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
83094 slobidx_t next;
83095@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
83096 /*
83097 * Returns true if s is the last free block in its page.
83098 */
83099-static int slob_last(slob_t *s)
83100+static int slob_last(const slob_t *s)
83101 {
83102 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
83103 }
83104
83105-static void *slob_new_pages(gfp_t gfp, int order, int node)
83106+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
83107 {
83108- void *page;
83109+ struct page *page;
83110
83111 #ifdef CONFIG_NUMA
83112 if (node != NUMA_NO_NODE)
83113@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
83114 if (!page)
83115 return NULL;
83116
83117- return page_address(page);
83118+ __SetPageSlab(page);
83119+ return page;
83120 }
83121
83122-static void slob_free_pages(void *b, int order)
83123+static void slob_free_pages(struct page *sp, int order)
83124 {
83125 if (current->reclaim_state)
83126 current->reclaim_state->reclaimed_slab += 1 << order;
83127- free_pages((unsigned long)b, order);
83128+ __ClearPageSlab(sp);
83129+ reset_page_mapcount(sp);
83130+ sp->private = 0;
83131+ __free_pages(sp, order);
83132 }
83133
83134 /*
83135@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
83136
83137 /* Not enough space: must allocate a new page */
83138 if (!b) {
83139- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83140- if (!b)
83141+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83142+ if (!sp)
83143 return NULL;
83144- sp = virt_to_page(b);
83145- __SetPageSlab(sp);
83146+ b = page_address(sp);
83147
83148 spin_lock_irqsave(&slob_lock, flags);
83149 sp->units = SLOB_UNITS(PAGE_SIZE);
83150 sp->freelist = b;
83151+ sp->private = 0;
83152 INIT_LIST_HEAD(&sp->list);
83153 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
83154 set_slob_page_free(sp, slob_list);
83155@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
83156 if (slob_page_free(sp))
83157 clear_slob_page_free(sp);
83158 spin_unlock_irqrestore(&slob_lock, flags);
83159- __ClearPageSlab(sp);
83160- reset_page_mapcount(sp);
83161- slob_free_pages(b, 0);
83162+ slob_free_pages(sp, 0);
83163 return;
83164 }
83165
83166@@ -424,11 +426,10 @@ out:
83167 */
83168
83169 static __always_inline void *
83170-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83171+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
83172 {
83173- unsigned int *m;
83174- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83175- void *ret;
83176+ slob_t *m;
83177+ void *ret = NULL;
83178
83179 gfp &= gfp_allowed_mask;
83180
83181@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83182
83183 if (!m)
83184 return NULL;
83185- *m = size;
83186+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
83187+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
83188+ m[0].units = size;
83189+ m[1].units = align;
83190 ret = (void *)m + align;
83191
83192 trace_kmalloc_node(caller, ret,
83193 size, size + align, gfp, node);
83194 } else {
83195 unsigned int order = get_order(size);
83196+ struct page *page;
83197
83198 if (likely(order))
83199 gfp |= __GFP_COMP;
83200- ret = slob_new_pages(gfp, order, node);
83201+ page = slob_new_pages(gfp, order, node);
83202+ if (page) {
83203+ ret = page_address(page);
83204+ page->private = size;
83205+ }
83206
83207 trace_kmalloc_node(caller, ret,
83208 size, PAGE_SIZE << order, gfp, node);
83209 }
83210
83211- kmemleak_alloc(ret, size, 1, gfp);
83212+ return ret;
83213+}
83214+
83215+static __always_inline void *
83216+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83217+{
83218+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83219+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
83220+
83221+ if (!ZERO_OR_NULL_PTR(ret))
83222+ kmemleak_alloc(ret, size, 1, gfp);
83223 return ret;
83224 }
83225
83226@@ -494,33 +513,110 @@ void kfree(const void *block)
83227 kmemleak_free(block);
83228
83229 sp = virt_to_page(block);
83230- if (PageSlab(sp)) {
83231+ VM_BUG_ON(!PageSlab(sp));
83232+ if (!sp->private) {
83233 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83234- unsigned int *m = (unsigned int *)(block - align);
83235- slob_free(m, *m + align);
83236- } else
83237+ slob_t *m = (slob_t *)(block - align);
83238+ slob_free(m, m[0].units + align);
83239+ } else {
83240+ __ClearPageSlab(sp);
83241+ reset_page_mapcount(sp);
83242+ sp->private = 0;
83243 __free_pages(sp, compound_order(sp));
83244+ }
83245 }
83246 EXPORT_SYMBOL(kfree);
83247
83248+bool is_usercopy_object(const void *ptr)
83249+{
83250+ if (!slab_is_available())
83251+ return false;
83252+
83253+ // PAX: TODO
83254+
83255+ return false;
83256+}
83257+
83258+#ifdef CONFIG_PAX_USERCOPY
83259+const char *check_heap_object(const void *ptr, unsigned long n)
83260+{
83261+ struct page *page;
83262+ const slob_t *free;
83263+ const void *base;
83264+ unsigned long flags;
83265+
83266+ if (ZERO_OR_NULL_PTR(ptr))
83267+ return "<null>";
83268+
83269+ if (!virt_addr_valid(ptr))
83270+ return NULL;
83271+
83272+ page = virt_to_head_page(ptr);
83273+ if (!PageSlab(page))
83274+ return NULL;
83275+
83276+ if (page->private) {
83277+ base = page;
83278+ if (base <= ptr && n <= page->private - (ptr - base))
83279+ return NULL;
83280+ return "<slob>";
83281+ }
83282+
83283+ /* some tricky double walking to find the chunk */
83284+ spin_lock_irqsave(&slob_lock, flags);
83285+ base = (void *)((unsigned long)ptr & PAGE_MASK);
83286+ free = page->freelist;
83287+
83288+ while (!slob_last(free) && (void *)free <= ptr) {
83289+ base = free + slob_units(free);
83290+ free = slob_next(free);
83291+ }
83292+
83293+ while (base < (void *)free) {
83294+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
83295+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
83296+ int offset;
83297+
83298+ if (ptr < base + align)
83299+ break;
83300+
83301+ offset = ptr - base - align;
83302+ if (offset >= m) {
83303+ base += size;
83304+ continue;
83305+ }
83306+
83307+ if (n > m - offset)
83308+ break;
83309+
83310+ spin_unlock_irqrestore(&slob_lock, flags);
83311+ return NULL;
83312+ }
83313+
83314+ spin_unlock_irqrestore(&slob_lock, flags);
83315+ return "<slob>";
83316+}
83317+#endif
83318+
83319 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
83320 size_t ksize(const void *block)
83321 {
83322 struct page *sp;
83323 int align;
83324- unsigned int *m;
83325+ slob_t *m;
83326
83327 BUG_ON(!block);
83328 if (unlikely(block == ZERO_SIZE_PTR))
83329 return 0;
83330
83331 sp = virt_to_page(block);
83332- if (unlikely(!PageSlab(sp)))
83333- return PAGE_SIZE << compound_order(sp);
83334+ VM_BUG_ON(!PageSlab(sp));
83335+ if (sp->private)
83336+ return sp->private;
83337
83338 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
83339- m = (unsigned int *)(block - align);
83340- return SLOB_UNITS(*m) * SLOB_UNIT;
83341+ m = (slob_t *)(block - align);
83342+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
83343 }
83344 EXPORT_SYMBOL(ksize);
83345
83346@@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
83347
83348 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
83349 {
83350- void *b;
83351+ void *b = NULL;
83352
83353 flags &= gfp_allowed_mask;
83354
83355 lockdep_trace_alloc(flags);
83356
83357+#ifdef CONFIG_PAX_USERCOPY_SLABS
83358+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
83359+#else
83360 if (c->size < PAGE_SIZE) {
83361 b = slob_alloc(c->size, flags, c->align, node);
83362 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
83363 SLOB_UNITS(c->size) * SLOB_UNIT,
83364 flags, node);
83365 } else {
83366- b = slob_new_pages(flags, get_order(c->size), node);
83367+ struct page *sp;
83368+
83369+ sp = slob_new_pages(flags, get_order(c->size), node);
83370+ if (sp) {
83371+ b = page_address(sp);
83372+ sp->private = c->size;
83373+ }
83374 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
83375 PAGE_SIZE << get_order(c->size),
83376 flags, node);
83377 }
83378+#endif
83379
83380 if (c->ctor)
83381 c->ctor(b);
83382@@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
83383
83384 static void __kmem_cache_free(void *b, int size)
83385 {
83386- if (size < PAGE_SIZE)
83387+ struct page *sp;
83388+
83389+ sp = virt_to_page(b);
83390+ BUG_ON(!PageSlab(sp));
83391+ if (!sp->private)
83392 slob_free(b, size);
83393 else
83394- slob_free_pages(b, get_order(size));
83395+ slob_free_pages(sp, get_order(size));
83396 }
83397
83398 static void kmem_rcu_free(struct rcu_head *head)
83399@@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
83400
83401 void kmem_cache_free(struct kmem_cache *c, void *b)
83402 {
83403+ int size = c->size;
83404+
83405+#ifdef CONFIG_PAX_USERCOPY_SLABS
83406+ if (size + c->align < PAGE_SIZE) {
83407+ size += c->align;
83408+ b -= c->align;
83409+ }
83410+#endif
83411+
83412 kmemleak_free_recursive(b, c->flags);
83413 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
83414 struct slob_rcu *slob_rcu;
83415- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
83416- slob_rcu->size = c->size;
83417+ slob_rcu = b + (size - sizeof(struct slob_rcu));
83418+ slob_rcu->size = size;
83419 call_rcu(&slob_rcu->head, kmem_rcu_free);
83420 } else {
83421- __kmem_cache_free(b, c->size);
83422+ __kmem_cache_free(b, size);
83423 }
83424
83425+#ifdef CONFIG_PAX_USERCOPY_SLABS
83426+ trace_kfree(_RET_IP_, b);
83427+#else
83428 trace_kmem_cache_free(_RET_IP_, b);
83429+#endif
83430+
83431 }
83432 EXPORT_SYMBOL(kmem_cache_free);
83433
83434diff --git a/mm/slub.c b/mm/slub.c
83435index ba2ca53..00b1f4e 100644
83436--- a/mm/slub.c
83437+++ b/mm/slub.c
83438@@ -197,7 +197,7 @@ struct track {
83439
83440 enum track_item { TRACK_ALLOC, TRACK_FREE };
83441
83442-#ifdef CONFIG_SYSFS
83443+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83444 static int sysfs_slab_add(struct kmem_cache *);
83445 static int sysfs_slab_alias(struct kmem_cache *, const char *);
83446 static void sysfs_slab_remove(struct kmem_cache *);
83447@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
83448 if (!t->addr)
83449 return;
83450
83451- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
83452+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
83453 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
83454 #ifdef CONFIG_STACKTRACE
83455 {
83456@@ -2653,7 +2653,7 @@ static int slub_min_objects;
83457 * Merge control. If this is set then no merging of slab caches will occur.
83458 * (Could be removed. This was introduced to pacify the merge skeptics.)
83459 */
83460-static int slub_nomerge;
83461+static int slub_nomerge = 1;
83462
83463 /*
83464 * Calculate the order of allocation given an slab object size.
83465@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
83466 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
83467 #endif
83468
83469+#ifdef CONFIG_PAX_USERCOPY_SLABS
83470+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
83471+#endif
83472+
83473 static int __init setup_slub_min_order(char *str)
83474 {
83475 get_option(&str, &slub_min_order);
83476@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
83477 return kmalloc_dma_caches[index];
83478
83479 #endif
83480+
83481+#ifdef CONFIG_PAX_USERCOPY_SLABS
83482+ if (flags & SLAB_USERCOPY)
83483+ return kmalloc_usercopy_caches[index];
83484+
83485+#endif
83486+
83487 return kmalloc_caches[index];
83488 }
83489
83490@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
83491 EXPORT_SYMBOL(__kmalloc_node);
83492 #endif
83493
83494+bool is_usercopy_object(const void *ptr)
83495+{
83496+ struct page *page;
83497+ struct kmem_cache *s;
83498+
83499+ if (ZERO_OR_NULL_PTR(ptr))
83500+ return false;
83501+
83502+ if (!slab_is_available())
83503+ return false;
83504+
83505+ if (!virt_addr_valid(ptr))
83506+ return false;
83507+
83508+ page = virt_to_head_page(ptr);
83509+
83510+ if (!PageSlab(page))
83511+ return false;
83512+
83513+ s = page->slab_cache;
83514+ return s->flags & SLAB_USERCOPY;
83515+}
83516+
83517+#ifdef CONFIG_PAX_USERCOPY
83518+const char *check_heap_object(const void *ptr, unsigned long n)
83519+{
83520+ struct page *page;
83521+ struct kmem_cache *s;
83522+ unsigned long offset;
83523+
83524+ if (ZERO_OR_NULL_PTR(ptr))
83525+ return "<null>";
83526+
83527+ if (!virt_addr_valid(ptr))
83528+ return NULL;
83529+
83530+ page = virt_to_head_page(ptr);
83531+
83532+ if (!PageSlab(page))
83533+ return NULL;
83534+
83535+ s = page->slab_cache;
83536+ if (!(s->flags & SLAB_USERCOPY))
83537+ return s->name;
83538+
83539+ offset = (ptr - page_address(page)) % s->size;
83540+ if (offset <= s->object_size && n <= s->object_size - offset)
83541+ return NULL;
83542+
83543+ return s->name;
83544+}
83545+#endif
83546+
83547 size_t ksize(const void *object)
83548 {
83549 struct page *page;
83550@@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
83551
83552 /* Caches that are not of the two-to-the-power-of size */
83553 if (KMALLOC_MIN_SIZE <= 32) {
83554- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
83555+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
83556 caches++;
83557 }
83558
83559 if (KMALLOC_MIN_SIZE <= 64) {
83560- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
83561+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
83562 caches++;
83563 }
83564
83565 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
83566- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
83567+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
83568 caches++;
83569 }
83570
83571@@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
83572 }
83573 }
83574 #endif
83575+
83576+#ifdef CONFIG_PAX_USERCOPY_SLABS
83577+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
83578+ struct kmem_cache *s = kmalloc_caches[i];
83579+
83580+ if (s && s->size) {
83581+ char *name = kasprintf(GFP_NOWAIT,
83582+ "usercopy-kmalloc-%d", s->object_size);
83583+
83584+ BUG_ON(!name);
83585+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
83586+ s->object_size, SLAB_USERCOPY);
83587+ }
83588+ }
83589+#endif
83590+
83591 printk(KERN_INFO
83592 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
83593 " CPUs=%d, Nodes=%d\n",
83594@@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
83595 /*
83596 * We may have set a slab to be unmergeable during bootstrap.
83597 */
83598- if (s->refcount < 0)
83599+ if (atomic_read(&s->refcount) < 0)
83600 return 1;
83601
83602 return 0;
83603@@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83604
83605 s = find_mergeable(memcg, size, align, flags, name, ctor);
83606 if (s) {
83607- s->refcount++;
83608+ atomic_inc(&s->refcount);
83609 /*
83610 * Adjust the object sizes so that we clear
83611 * the complete object on kzalloc.
83612@@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83613 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
83614
83615 if (sysfs_slab_alias(s, name)) {
83616- s->refcount--;
83617+ atomic_dec(&s->refcount);
83618 s = NULL;
83619 }
83620 }
83621@@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
83622 return NOTIFY_OK;
83623 }
83624
83625-static struct notifier_block __cpuinitdata slab_notifier = {
83626+static struct notifier_block slab_notifier = {
83627 .notifier_call = slab_cpuup_callback
83628 };
83629
83630@@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
83631 }
83632 #endif
83633
83634-#ifdef CONFIG_SYSFS
83635+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83636 static int count_inuse(struct page *page)
83637 {
83638 return page->inuse;
83639@@ -4364,12 +4444,12 @@ static void resiliency_test(void)
83640 validate_slab_cache(kmalloc_caches[9]);
83641 }
83642 #else
83643-#ifdef CONFIG_SYSFS
83644+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83645 static void resiliency_test(void) {};
83646 #endif
83647 #endif
83648
83649-#ifdef CONFIG_SYSFS
83650+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83651 enum slab_stat_type {
83652 SL_ALL, /* All slabs */
83653 SL_PARTIAL, /* Only partially allocated slabs */
83654@@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
83655
83656 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
83657 {
83658- return sprintf(buf, "%d\n", s->refcount - 1);
83659+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
83660 }
83661 SLAB_ATTR_RO(aliases);
83662
83663@@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
83664 return name;
83665 }
83666
83667+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83668 static int sysfs_slab_add(struct kmem_cache *s)
83669 {
83670 int err;
83671@@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
83672 kobject_del(&s->kobj);
83673 kobject_put(&s->kobj);
83674 }
83675+#endif
83676
83677 /*
83678 * Need to buffer aliases during bootup until sysfs becomes
83679@@ -5336,6 +5418,7 @@ struct saved_alias {
83680
83681 static struct saved_alias *alias_list;
83682
83683+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83684 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83685 {
83686 struct saved_alias *al;
83687@@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83688 alias_list = al;
83689 return 0;
83690 }
83691+#endif
83692
83693 static int __init slab_sysfs_init(void)
83694 {
83695diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
83696index 1b7e22a..3fcd4f3 100644
83697--- a/mm/sparse-vmemmap.c
83698+++ b/mm/sparse-vmemmap.c
83699@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
83700 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83701 if (!p)
83702 return NULL;
83703- pud_populate(&init_mm, pud, p);
83704+ pud_populate_kernel(&init_mm, pud, p);
83705 }
83706 return pud;
83707 }
83708@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
83709 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83710 if (!p)
83711 return NULL;
83712- pgd_populate(&init_mm, pgd, p);
83713+ pgd_populate_kernel(&init_mm, pgd, p);
83714 }
83715 return pgd;
83716 }
83717diff --git a/mm/sparse.c b/mm/sparse.c
83718index 6b5fb76..db0c190 100644
83719--- a/mm/sparse.c
83720+++ b/mm/sparse.c
83721@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
83722
83723 for (i = 0; i < PAGES_PER_SECTION; i++) {
83724 if (PageHWPoison(&memmap[i])) {
83725- atomic_long_sub(1, &mce_bad_pages);
83726+ atomic_long_sub_unchecked(1, &mce_bad_pages);
83727 ClearPageHWPoison(&memmap[i]);
83728 }
83729 }
83730diff --git a/mm/swap.c b/mm/swap.c
83731index 6310dc2..3662b3f 100644
83732--- a/mm/swap.c
83733+++ b/mm/swap.c
83734@@ -30,6 +30,7 @@
83735 #include <linux/backing-dev.h>
83736 #include <linux/memcontrol.h>
83737 #include <linux/gfp.h>
83738+#include <linux/hugetlb.h>
83739
83740 #include "internal.h"
83741
83742@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
83743
83744 __page_cache_release(page);
83745 dtor = get_compound_page_dtor(page);
83746+ if (!PageHuge(page))
83747+ BUG_ON(dtor != free_compound_page);
83748 (*dtor)(page);
83749 }
83750
83751diff --git a/mm/swapfile.c b/mm/swapfile.c
83752index e97a0e5..b50e796 100644
83753--- a/mm/swapfile.c
83754+++ b/mm/swapfile.c
83755@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
83756
83757 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
83758 /* Activity counter to indicate that a swapon or swapoff has occurred */
83759-static atomic_t proc_poll_event = ATOMIC_INIT(0);
83760+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
83761
83762 static inline unsigned char swap_count(unsigned char ent)
83763 {
83764@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
83765 }
83766 filp_close(swap_file, NULL);
83767 err = 0;
83768- atomic_inc(&proc_poll_event);
83769+ atomic_inc_unchecked(&proc_poll_event);
83770 wake_up_interruptible(&proc_poll_wait);
83771
83772 out_dput:
83773@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
83774
83775 poll_wait(file, &proc_poll_wait, wait);
83776
83777- if (seq->poll_event != atomic_read(&proc_poll_event)) {
83778- seq->poll_event = atomic_read(&proc_poll_event);
83779+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
83780+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83781 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
83782 }
83783
83784@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
83785 return ret;
83786
83787 seq = file->private_data;
83788- seq->poll_event = atomic_read(&proc_poll_event);
83789+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83790 return 0;
83791 }
83792
83793@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
83794 (frontswap_map) ? "FS" : "");
83795
83796 mutex_unlock(&swapon_mutex);
83797- atomic_inc(&proc_poll_event);
83798+ atomic_inc_unchecked(&proc_poll_event);
83799 wake_up_interruptible(&proc_poll_wait);
83800
83801 if (S_ISREG(inode->i_mode))
83802diff --git a/mm/util.c b/mm/util.c
83803index c55e26b..3f913a9 100644
83804--- a/mm/util.c
83805+++ b/mm/util.c
83806@@ -292,6 +292,12 @@ done:
83807 void arch_pick_mmap_layout(struct mm_struct *mm)
83808 {
83809 mm->mmap_base = TASK_UNMAPPED_BASE;
83810+
83811+#ifdef CONFIG_PAX_RANDMMAP
83812+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83813+ mm->mmap_base += mm->delta_mmap;
83814+#endif
83815+
83816 mm->get_unmapped_area = arch_get_unmapped_area;
83817 mm->unmap_area = arch_unmap_area;
83818 }
83819diff --git a/mm/vmalloc.c b/mm/vmalloc.c
83820index 5123a16..f234a48 100644
83821--- a/mm/vmalloc.c
83822+++ b/mm/vmalloc.c
83823@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
83824
83825 pte = pte_offset_kernel(pmd, addr);
83826 do {
83827- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83828- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83829+
83830+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83831+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
83832+ BUG_ON(!pte_exec(*pte));
83833+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
83834+ continue;
83835+ }
83836+#endif
83837+
83838+ {
83839+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83840+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83841+ }
83842 } while (pte++, addr += PAGE_SIZE, addr != end);
83843 }
83844
83845@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
83846 pte = pte_alloc_kernel(pmd, addr);
83847 if (!pte)
83848 return -ENOMEM;
83849+
83850+ pax_open_kernel();
83851 do {
83852 struct page *page = pages[*nr];
83853
83854- if (WARN_ON(!pte_none(*pte)))
83855+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83856+ if (pgprot_val(prot) & _PAGE_NX)
83857+#endif
83858+
83859+ if (!pte_none(*pte)) {
83860+ pax_close_kernel();
83861+ WARN_ON(1);
83862 return -EBUSY;
83863- if (WARN_ON(!page))
83864+ }
83865+ if (!page) {
83866+ pax_close_kernel();
83867+ WARN_ON(1);
83868 return -ENOMEM;
83869+ }
83870 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
83871 (*nr)++;
83872 } while (pte++, addr += PAGE_SIZE, addr != end);
83873+ pax_close_kernel();
83874 return 0;
83875 }
83876
83877@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
83878 pmd_t *pmd;
83879 unsigned long next;
83880
83881- pmd = pmd_alloc(&init_mm, pud, addr);
83882+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
83883 if (!pmd)
83884 return -ENOMEM;
83885 do {
83886@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
83887 pud_t *pud;
83888 unsigned long next;
83889
83890- pud = pud_alloc(&init_mm, pgd, addr);
83891+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
83892 if (!pud)
83893 return -ENOMEM;
83894 do {
83895@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
83896 * and fall back on vmalloc() if that fails. Others
83897 * just put it in the vmalloc space.
83898 */
83899-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
83900+#ifdef CONFIG_MODULES
83901+#ifdef MODULES_VADDR
83902 unsigned long addr = (unsigned long)x;
83903 if (addr >= MODULES_VADDR && addr < MODULES_END)
83904 return 1;
83905 #endif
83906+
83907+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83908+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
83909+ return 1;
83910+#endif
83911+
83912+#endif
83913+
83914 return is_vmalloc_addr(x);
83915 }
83916
83917@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
83918
83919 if (!pgd_none(*pgd)) {
83920 pud_t *pud = pud_offset(pgd, addr);
83921+#ifdef CONFIG_X86
83922+ if (!pud_large(*pud))
83923+#endif
83924 if (!pud_none(*pud)) {
83925 pmd_t *pmd = pmd_offset(pud, addr);
83926+#ifdef CONFIG_X86
83927+ if (!pmd_large(*pmd))
83928+#endif
83929 if (!pmd_none(*pmd)) {
83930 pte_t *ptep, pte;
83931
83932@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
83933 * Allocate a region of KVA of the specified size and alignment, within the
83934 * vstart and vend.
83935 */
83936-static struct vmap_area *alloc_vmap_area(unsigned long size,
83937+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
83938 unsigned long align,
83939 unsigned long vstart, unsigned long vend,
83940 int node, gfp_t gfp_mask)
83941@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
83942 struct vm_struct *area;
83943
83944 BUG_ON(in_interrupt());
83945+
83946+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83947+ if (flags & VM_KERNEXEC) {
83948+ if (start != VMALLOC_START || end != VMALLOC_END)
83949+ return NULL;
83950+ start = (unsigned long)MODULES_EXEC_VADDR;
83951+ end = (unsigned long)MODULES_EXEC_END;
83952+ }
83953+#endif
83954+
83955 if (flags & VM_IOREMAP) {
83956 int bit = fls(size);
83957
83958@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
83959 if (count > totalram_pages)
83960 return NULL;
83961
83962+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83963+ if (!(pgprot_val(prot) & _PAGE_NX))
83964+ flags |= VM_KERNEXEC;
83965+#endif
83966+
83967 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
83968 __builtin_return_address(0));
83969 if (!area)
83970@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
83971 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
83972 goto fail;
83973
83974+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83975+ if (!(pgprot_val(prot) & _PAGE_NX))
83976+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
83977+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
83978+ else
83979+#endif
83980+
83981 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
83982 start, end, node, gfp_mask, caller);
83983 if (!area)
83984@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
83985 * For tight control over page level allocator and protection flags
83986 * use __vmalloc() instead.
83987 */
83988-
83989 void *vmalloc_exec(unsigned long size)
83990 {
83991- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
83992+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
83993 -1, __builtin_return_address(0));
83994 }
83995
83996@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
83997 unsigned long uaddr = vma->vm_start;
83998 unsigned long usize = vma->vm_end - vma->vm_start;
83999
84000+ BUG_ON(vma->vm_mirror);
84001+
84002 if ((PAGE_SIZE-1) & (unsigned long)addr)
84003 return -EINVAL;
84004
84005@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
84006 v->addr, v->addr + v->size, v->size);
84007
84008 if (v->caller)
84009+#ifdef CONFIG_GRKERNSEC_HIDESYM
84010+ seq_printf(m, " %pK", v->caller);
84011+#else
84012 seq_printf(m, " %pS", v->caller);
84013+#endif
84014
84015 if (v->nr_pages)
84016 seq_printf(m, " pages=%d", v->nr_pages);
84017diff --git a/mm/vmstat.c b/mm/vmstat.c
84018index 9800306..76b4b27 100644
84019--- a/mm/vmstat.c
84020+++ b/mm/vmstat.c
84021@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
84022 *
84023 * vm_stat contains the global counters
84024 */
84025-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84026+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84027 EXPORT_SYMBOL(vm_stat);
84028
84029 #ifdef CONFIG_SMP
84030@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
84031 v = p->vm_stat_diff[i];
84032 p->vm_stat_diff[i] = 0;
84033 local_irq_restore(flags);
84034- atomic_long_add(v, &zone->vm_stat[i]);
84035+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84036 global_diff[i] += v;
84037 #ifdef CONFIG_NUMA
84038 /* 3 seconds idle till flush */
84039@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
84040
84041 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
84042 if (global_diff[i])
84043- atomic_long_add(global_diff[i], &vm_stat[i]);
84044+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
84045 }
84046
84047 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84048@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84049 if (pset->vm_stat_diff[i]) {
84050 int v = pset->vm_stat_diff[i];
84051 pset->vm_stat_diff[i] = 0;
84052- atomic_long_add(v, &zone->vm_stat[i]);
84053- atomic_long_add(v, &vm_stat[i]);
84054+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84055+ atomic_long_add_unchecked(v, &vm_stat[i]);
84056 }
84057 }
84058 #endif
84059@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
84060 return NOTIFY_OK;
84061 }
84062
84063-static struct notifier_block __cpuinitdata vmstat_notifier =
84064+static struct notifier_block vmstat_notifier =
84065 { &vmstat_cpuup_callback, NULL, 0 };
84066 #endif
84067
84068@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
84069 start_cpu_timer(cpu);
84070 #endif
84071 #ifdef CONFIG_PROC_FS
84072- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
84073- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
84074- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
84075- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
84076+ {
84077+ mode_t gr_mode = S_IRUGO;
84078+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84079+ gr_mode = S_IRUSR;
84080+#endif
84081+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
84082+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
84083+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84084+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
84085+#else
84086+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
84087+#endif
84088+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
84089+ }
84090 #endif
84091 return 0;
84092 }
84093diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
84094index a292e80..785ee68 100644
84095--- a/net/8021q/vlan.c
84096+++ b/net/8021q/vlan.c
84097@@ -485,7 +485,7 @@ out:
84098 return NOTIFY_DONE;
84099 }
84100
84101-static struct notifier_block vlan_notifier_block __read_mostly = {
84102+static struct notifier_block vlan_notifier_block = {
84103 .notifier_call = vlan_device_event,
84104 };
84105
84106@@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
84107 err = -EPERM;
84108 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
84109 break;
84110- if ((args.u.name_type >= 0) &&
84111- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
84112+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
84113 struct vlan_net *vn;
84114
84115 vn = net_generic(net, vlan_net_id);
84116diff --git a/net/9p/mod.c b/net/9p/mod.c
84117index 6ab36ae..6f1841b 100644
84118--- a/net/9p/mod.c
84119+++ b/net/9p/mod.c
84120@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
84121 void v9fs_register_trans(struct p9_trans_module *m)
84122 {
84123 spin_lock(&v9fs_trans_lock);
84124- list_add_tail(&m->list, &v9fs_trans_list);
84125+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
84126 spin_unlock(&v9fs_trans_lock);
84127 }
84128 EXPORT_SYMBOL(v9fs_register_trans);
84129@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
84130 void v9fs_unregister_trans(struct p9_trans_module *m)
84131 {
84132 spin_lock(&v9fs_trans_lock);
84133- list_del_init(&m->list);
84134+ pax_list_del_init((struct list_head *)&m->list);
84135 spin_unlock(&v9fs_trans_lock);
84136 }
84137 EXPORT_SYMBOL(v9fs_unregister_trans);
84138diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
84139index 02efb25..41541a9 100644
84140--- a/net/9p/trans_fd.c
84141+++ b/net/9p/trans_fd.c
84142@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
84143 oldfs = get_fs();
84144 set_fs(get_ds());
84145 /* The cast to a user pointer is valid due to the set_fs() */
84146- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
84147+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
84148 set_fs(oldfs);
84149
84150 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
84151diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
84152index 876fbe8..8bbea9f 100644
84153--- a/net/atm/atm_misc.c
84154+++ b/net/atm/atm_misc.c
84155@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
84156 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
84157 return 1;
84158 atm_return(vcc, truesize);
84159- atomic_inc(&vcc->stats->rx_drop);
84160+ atomic_inc_unchecked(&vcc->stats->rx_drop);
84161 return 0;
84162 }
84163 EXPORT_SYMBOL(atm_charge);
84164@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
84165 }
84166 }
84167 atm_return(vcc, guess);
84168- atomic_inc(&vcc->stats->rx_drop);
84169+ atomic_inc_unchecked(&vcc->stats->rx_drop);
84170 return NULL;
84171 }
84172 EXPORT_SYMBOL(atm_alloc_charge);
84173@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
84174
84175 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
84176 {
84177-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
84178+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
84179 __SONET_ITEMS
84180 #undef __HANDLE_ITEM
84181 }
84182@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
84183
84184 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
84185 {
84186-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
84187+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
84188 __SONET_ITEMS
84189 #undef __HANDLE_ITEM
84190 }
84191diff --git a/net/atm/lec.h b/net/atm/lec.h
84192index a86aff9..3a0d6f6 100644
84193--- a/net/atm/lec.h
84194+++ b/net/atm/lec.h
84195@@ -48,7 +48,7 @@ struct lane2_ops {
84196 const u8 *tlvs, u32 sizeoftlvs);
84197 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
84198 const u8 *tlvs, u32 sizeoftlvs);
84199-};
84200+} __no_const;
84201
84202 /*
84203 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
84204diff --git a/net/atm/proc.c b/net/atm/proc.c
84205index 0d020de..011c7bb 100644
84206--- a/net/atm/proc.c
84207+++ b/net/atm/proc.c
84208@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
84209 const struct k_atm_aal_stats *stats)
84210 {
84211 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
84212- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
84213- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
84214- atomic_read(&stats->rx_drop));
84215+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
84216+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
84217+ atomic_read_unchecked(&stats->rx_drop));
84218 }
84219
84220 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
84221diff --git a/net/atm/resources.c b/net/atm/resources.c
84222index 0447d5d..3cf4728 100644
84223--- a/net/atm/resources.c
84224+++ b/net/atm/resources.c
84225@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
84226 static void copy_aal_stats(struct k_atm_aal_stats *from,
84227 struct atm_aal_stats *to)
84228 {
84229-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
84230+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
84231 __AAL_STAT_ITEMS
84232 #undef __HANDLE_ITEM
84233 }
84234@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
84235 static void subtract_aal_stats(struct k_atm_aal_stats *from,
84236 struct atm_aal_stats *to)
84237 {
84238-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
84239+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
84240 __AAL_STAT_ITEMS
84241 #undef __HANDLE_ITEM
84242 }
84243diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
84244index d5744b7..506bae3 100644
84245--- a/net/ax25/sysctl_net_ax25.c
84246+++ b/net/ax25/sysctl_net_ax25.c
84247@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
84248 {
84249 char path[sizeof("net/ax25/") + IFNAMSIZ];
84250 int k;
84251- struct ctl_table *table;
84252+ ctl_table_no_const *table;
84253
84254 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
84255 if (!table)
84256diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
84257index 7d02ebd..4d4cc01 100644
84258--- a/net/batman-adv/bat_iv_ogm.c
84259+++ b/net/batman-adv/bat_iv_ogm.c
84260@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
84261
84262 /* randomize initial seqno to avoid collision */
84263 get_random_bytes(&random_seqno, sizeof(random_seqno));
84264- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
84265+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
84266
84267 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
84268 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
84269@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
84270 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
84271
84272 /* change sequence number to network order */
84273- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
84274+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
84275 batadv_ogm_packet->seqno = htonl(seqno);
84276- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
84277+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
84278
84279 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
84280 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
84281@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
84282 return;
84283
84284 /* could be changed by schedule_own_packet() */
84285- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
84286+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
84287
84288 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
84289 has_directlink_flag = 1;
84290diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
84291index f1d37cd..4190879 100644
84292--- a/net/batman-adv/hard-interface.c
84293+++ b/net/batman-adv/hard-interface.c
84294@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
84295 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
84296 dev_add_pack(&hard_iface->batman_adv_ptype);
84297
84298- atomic_set(&hard_iface->frag_seqno, 1);
84299+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
84300 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
84301 hard_iface->net_dev->name);
84302
84303@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
84304 /* This can't be called via a bat_priv callback because
84305 * we have no bat_priv yet.
84306 */
84307- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
84308+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
84309 hard_iface->bat_iv.ogm_buff = NULL;
84310
84311 return hard_iface;
84312diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
84313index 6b548fd..fc32c8d 100644
84314--- a/net/batman-adv/soft-interface.c
84315+++ b/net/batman-adv/soft-interface.c
84316@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
84317 primary_if->net_dev->dev_addr, ETH_ALEN);
84318
84319 /* set broadcast sequence number */
84320- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
84321+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
84322 bcast_packet->seqno = htonl(seqno);
84323
84324 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
84325@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
84326 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
84327
84328 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
84329- atomic_set(&bat_priv->bcast_seqno, 1);
84330+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
84331 atomic_set(&bat_priv->tt.vn, 0);
84332 atomic_set(&bat_priv->tt.local_changes, 0);
84333 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
84334diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
84335index ae9ac9a..11e0fe7 100644
84336--- a/net/batman-adv/types.h
84337+++ b/net/batman-adv/types.h
84338@@ -48,7 +48,7 @@
84339 struct batadv_hard_iface_bat_iv {
84340 unsigned char *ogm_buff;
84341 int ogm_buff_len;
84342- atomic_t ogm_seqno;
84343+ atomic_unchecked_t ogm_seqno;
84344 };
84345
84346 struct batadv_hard_iface {
84347@@ -56,7 +56,7 @@ struct batadv_hard_iface {
84348 int16_t if_num;
84349 char if_status;
84350 struct net_device *net_dev;
84351- atomic_t frag_seqno;
84352+ atomic_unchecked_t frag_seqno;
84353 struct kobject *hardif_obj;
84354 atomic_t refcount;
84355 struct packet_type batman_adv_ptype;
84356@@ -284,7 +284,7 @@ struct batadv_priv {
84357 atomic_t orig_interval; /* uint */
84358 atomic_t hop_penalty; /* uint */
84359 atomic_t log_level; /* uint */
84360- atomic_t bcast_seqno;
84361+ atomic_unchecked_t bcast_seqno;
84362 atomic_t bcast_queue_left;
84363 atomic_t batman_queue_left;
84364 char num_ifaces;
84365diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
84366index 10aff49..ea8e021 100644
84367--- a/net/batman-adv/unicast.c
84368+++ b/net/batman-adv/unicast.c
84369@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
84370 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
84371 frag2->flags = large_tail;
84372
84373- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
84374+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
84375 frag1->seqno = htons(seqno - 1);
84376 frag2->seqno = htons(seqno);
84377
84378diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
84379index 07f0739..3c42e34 100644
84380--- a/net/bluetooth/hci_sock.c
84381+++ b/net/bluetooth/hci_sock.c
84382@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
84383 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
84384 }
84385
84386- len = min_t(unsigned int, len, sizeof(uf));
84387+ len = min((size_t)len, sizeof(uf));
84388 if (copy_from_user(&uf, optval, len)) {
84389 err = -EFAULT;
84390 break;
84391diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
84392index 22e6583..426e2f3 100644
84393--- a/net/bluetooth/l2cap_core.c
84394+++ b/net/bluetooth/l2cap_core.c
84395@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
84396 break;
84397
84398 case L2CAP_CONF_RFC:
84399- if (olen == sizeof(rfc))
84400- memcpy(&rfc, (void *)val, olen);
84401+ if (olen != sizeof(rfc))
84402+ break;
84403+
84404+ memcpy(&rfc, (void *)val, olen);
84405
84406 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
84407 rfc.mode != chan->mode)
84408diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
84409index 1bcfb84..dad9f98 100644
84410--- a/net/bluetooth/l2cap_sock.c
84411+++ b/net/bluetooth/l2cap_sock.c
84412@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
84413 struct sock *sk = sock->sk;
84414 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
84415 struct l2cap_options opts;
84416- int len, err = 0;
84417+ int err = 0;
84418+ size_t len = optlen;
84419 u32 opt;
84420
84421 BT_DBG("sk %p", sk);
84422@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
84423 opts.max_tx = chan->max_tx;
84424 opts.txwin_size = chan->tx_win;
84425
84426- len = min_t(unsigned int, sizeof(opts), optlen);
84427+ len = min(sizeof(opts), len);
84428 if (copy_from_user((char *) &opts, optval, len)) {
84429 err = -EFAULT;
84430 break;
84431@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84432 struct bt_security sec;
84433 struct bt_power pwr;
84434 struct l2cap_conn *conn;
84435- int len, err = 0;
84436+ int err = 0;
84437+ size_t len = optlen;
84438 u32 opt;
84439
84440 BT_DBG("sk %p", sk);
84441@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84442
84443 sec.level = BT_SECURITY_LOW;
84444
84445- len = min_t(unsigned int, sizeof(sec), optlen);
84446+ len = min(sizeof(sec), len);
84447 if (copy_from_user((char *) &sec, optval, len)) {
84448 err = -EFAULT;
84449 break;
84450@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
84451
84452 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
84453
84454- len = min_t(unsigned int, sizeof(pwr), optlen);
84455+ len = min(sizeof(pwr), len);
84456 if (copy_from_user((char *) &pwr, optval, len)) {
84457 err = -EFAULT;
84458 break;
84459diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
84460index ce3f665..2c7d08f 100644
84461--- a/net/bluetooth/rfcomm/sock.c
84462+++ b/net/bluetooth/rfcomm/sock.c
84463@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
84464 struct sock *sk = sock->sk;
84465 struct bt_security sec;
84466 int err = 0;
84467- size_t len;
84468+ size_t len = optlen;
84469 u32 opt;
84470
84471 BT_DBG("sk %p", sk);
84472@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
84473
84474 sec.level = BT_SECURITY_LOW;
84475
84476- len = min_t(unsigned int, sizeof(sec), optlen);
84477+ len = min(sizeof(sec), len);
84478 if (copy_from_user((char *) &sec, optval, len)) {
84479 err = -EFAULT;
84480 break;
84481diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
84482index bd6fd0f..6492cba 100644
84483--- a/net/bluetooth/rfcomm/tty.c
84484+++ b/net/bluetooth/rfcomm/tty.c
84485@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
84486 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
84487
84488 spin_lock_irqsave(&dev->port.lock, flags);
84489- if (dev->port.count > 0) {
84490+ if (atomic_read(&dev->port.count) > 0) {
84491 spin_unlock_irqrestore(&dev->port.lock, flags);
84492 return;
84493 }
84494@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
84495 return -ENODEV;
84496
84497 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
84498- dev->channel, dev->port.count);
84499+ dev->channel, atomic_read(&dev->port.count));
84500
84501 spin_lock_irqsave(&dev->port.lock, flags);
84502- if (++dev->port.count > 1) {
84503+ if (atomic_inc_return(&dev->port.count) > 1) {
84504 spin_unlock_irqrestore(&dev->port.lock, flags);
84505 return 0;
84506 }
84507@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
84508 return;
84509
84510 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
84511- dev->port.count);
84512+ atomic_read(&dev->port.count));
84513
84514 spin_lock_irqsave(&dev->port.lock, flags);
84515- if (!--dev->port.count) {
84516+ if (!atomic_dec_return(&dev->port.count)) {
84517 spin_unlock_irqrestore(&dev->port.lock, flags);
84518 if (dev->tty_dev->parent)
84519 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
84520diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
84521index acc9f4c..2897e40 100644
84522--- a/net/bridge/br_mdb.c
84523+++ b/net/bridge/br_mdb.c
84524@@ -82,6 +82,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
84525 port = p->port;
84526 if (port) {
84527 struct br_mdb_entry e;
84528+ memset(&e, 0, sizeof(e));
84529 e.ifindex = port->dev->ifindex;
84530 e.state = p->state;
84531 if (p->addr.proto == htons(ETH_P_IP))
84532@@ -138,6 +139,7 @@ static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
84533 break;
84534
84535 bpm = nlmsg_data(nlh);
84536+ memset(bpm, 0, sizeof(*bpm));
84537 bpm->ifindex = dev->ifindex;
84538 if (br_mdb_fill_info(skb, cb, dev) < 0)
84539 goto out;
84540@@ -173,6 +175,7 @@ static int nlmsg_populate_mdb_fill(struct sk_buff *skb,
84541 return -EMSGSIZE;
84542
84543 bpm = nlmsg_data(nlh);
84544+ memset(bpm, 0, sizeof(*bpm));
84545 bpm->family = AF_BRIDGE;
84546 bpm->ifindex = dev->ifindex;
84547 nest = nla_nest_start(skb, MDBA_MDB);
84548@@ -230,6 +233,7 @@ void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
84549 {
84550 struct br_mdb_entry entry;
84551
84552+ memset(&entry, 0, sizeof(entry));
84553 entry.ifindex = port->dev->ifindex;
84554 entry.addr.proto = group->proto;
84555 entry.addr.u.ip4 = group->u.ip4;
84556diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
84557index 5fe2ff3..121d696 100644
84558--- a/net/bridge/netfilter/ebtables.c
84559+++ b/net/bridge/netfilter/ebtables.c
84560@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
84561 tmp.valid_hooks = t->table->valid_hooks;
84562 }
84563 mutex_unlock(&ebt_mutex);
84564- if (copy_to_user(user, &tmp, *len) != 0){
84565+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
84566 BUGPRINT("c2u Didn't work\n");
84567 ret = -EFAULT;
84568 break;
84569@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
84570 goto out;
84571 tmp.valid_hooks = t->valid_hooks;
84572
84573- if (copy_to_user(user, &tmp, *len) != 0) {
84574+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
84575 ret = -EFAULT;
84576 break;
84577 }
84578@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
84579 tmp.entries_size = t->table->entries_size;
84580 tmp.valid_hooks = t->table->valid_hooks;
84581
84582- if (copy_to_user(user, &tmp, *len) != 0) {
84583+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
84584 ret = -EFAULT;
84585 break;
84586 }
84587diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
84588index a376ec1..1fbd6be 100644
84589--- a/net/caif/cfctrl.c
84590+++ b/net/caif/cfctrl.c
84591@@ -10,6 +10,7 @@
84592 #include <linux/spinlock.h>
84593 #include <linux/slab.h>
84594 #include <linux/pkt_sched.h>
84595+#include <linux/sched.h>
84596 #include <net/caif/caif_layer.h>
84597 #include <net/caif/cfpkt.h>
84598 #include <net/caif/cfctrl.h>
84599@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
84600 memset(&dev_info, 0, sizeof(dev_info));
84601 dev_info.id = 0xff;
84602 cfsrvl_init(&this->serv, 0, &dev_info, false);
84603- atomic_set(&this->req_seq_no, 1);
84604- atomic_set(&this->rsp_seq_no, 1);
84605+ atomic_set_unchecked(&this->req_seq_no, 1);
84606+ atomic_set_unchecked(&this->rsp_seq_no, 1);
84607 this->serv.layer.receive = cfctrl_recv;
84608 sprintf(this->serv.layer.name, "ctrl");
84609 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
84610@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
84611 struct cfctrl_request_info *req)
84612 {
84613 spin_lock_bh(&ctrl->info_list_lock);
84614- atomic_inc(&ctrl->req_seq_no);
84615- req->sequence_no = atomic_read(&ctrl->req_seq_no);
84616+ atomic_inc_unchecked(&ctrl->req_seq_no);
84617+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
84618 list_add_tail(&req->list, &ctrl->list);
84619 spin_unlock_bh(&ctrl->info_list_lock);
84620 }
84621@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
84622 if (p != first)
84623 pr_warn("Requests are not received in order\n");
84624
84625- atomic_set(&ctrl->rsp_seq_no,
84626+ atomic_set_unchecked(&ctrl->rsp_seq_no,
84627 p->sequence_no);
84628 list_del(&p->list);
84629 goto out;
84630diff --git a/net/can/af_can.c b/net/can/af_can.c
84631index ddac1ee..3ee0a78 100644
84632--- a/net/can/af_can.c
84633+++ b/net/can/af_can.c
84634@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
84635 };
84636
84637 /* notifier block for netdevice event */
84638-static struct notifier_block can_netdev_notifier __read_mostly = {
84639+static struct notifier_block can_netdev_notifier = {
84640 .notifier_call = can_notifier,
84641 };
84642
84643diff --git a/net/can/gw.c b/net/can/gw.c
84644index 574dda78e..3d2b3da 100644
84645--- a/net/can/gw.c
84646+++ b/net/can/gw.c
84647@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
84648 MODULE_ALIAS("can-gw");
84649
84650 static HLIST_HEAD(cgw_list);
84651-static struct notifier_block notifier;
84652
84653 static struct kmem_cache *cgw_cache __read_mostly;
84654
84655@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
84656 return err;
84657 }
84658
84659+static struct notifier_block notifier = {
84660+ .notifier_call = cgw_notifier
84661+};
84662+
84663 static __init int cgw_module_init(void)
84664 {
84665 printk(banner);
84666@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
84667 return -ENOMEM;
84668
84669 /* set notifier */
84670- notifier.notifier_call = cgw_notifier;
84671 register_netdevice_notifier(&notifier);
84672
84673 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
84674diff --git a/net/compat.c b/net/compat.c
84675index 79ae884..17c5c09 100644
84676--- a/net/compat.c
84677+++ b/net/compat.c
84678@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
84679 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
84680 __get_user(kmsg->msg_flags, &umsg->msg_flags))
84681 return -EFAULT;
84682- kmsg->msg_name = compat_ptr(tmp1);
84683- kmsg->msg_iov = compat_ptr(tmp2);
84684- kmsg->msg_control = compat_ptr(tmp3);
84685+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
84686+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
84687+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
84688 return 0;
84689 }
84690
84691@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84692
84693 if (kern_msg->msg_namelen) {
84694 if (mode == VERIFY_READ) {
84695- int err = move_addr_to_kernel(kern_msg->msg_name,
84696+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
84697 kern_msg->msg_namelen,
84698 kern_address);
84699 if (err < 0)
84700@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84701 kern_msg->msg_name = NULL;
84702
84703 tot_len = iov_from_user_compat_to_kern(kern_iov,
84704- (struct compat_iovec __user *)kern_msg->msg_iov,
84705+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
84706 kern_msg->msg_iovlen);
84707 if (tot_len >= 0)
84708 kern_msg->msg_iov = kern_iov;
84709@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84710
84711 #define CMSG_COMPAT_FIRSTHDR(msg) \
84712 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
84713- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
84714+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
84715 (struct compat_cmsghdr __user *)NULL)
84716
84717 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
84718 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
84719 (ucmlen) <= (unsigned long) \
84720 ((mhdr)->msg_controllen - \
84721- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
84722+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
84723
84724 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
84725 struct compat_cmsghdr __user *cmsg, int cmsg_len)
84726 {
84727 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
84728- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
84729+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
84730 msg->msg_controllen)
84731 return NULL;
84732 return (struct compat_cmsghdr __user *)ptr;
84733@@ -219,7 +219,7 @@ Efault:
84734
84735 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
84736 {
84737- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84738+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84739 struct compat_cmsghdr cmhdr;
84740 struct compat_timeval ctv;
84741 struct compat_timespec cts[3];
84742@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
84743
84744 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
84745 {
84746- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84747+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84748 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
84749 int fdnum = scm->fp->count;
84750 struct file **fp = scm->fp->fp;
84751@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
84752 return -EFAULT;
84753 old_fs = get_fs();
84754 set_fs(KERNEL_DS);
84755- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
84756+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
84757 set_fs(old_fs);
84758
84759 return err;
84760@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
84761 len = sizeof(ktime);
84762 old_fs = get_fs();
84763 set_fs(KERNEL_DS);
84764- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
84765+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
84766 set_fs(old_fs);
84767
84768 if (!err) {
84769@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84770 case MCAST_JOIN_GROUP:
84771 case MCAST_LEAVE_GROUP:
84772 {
84773- struct compat_group_req __user *gr32 = (void *)optval;
84774+ struct compat_group_req __user *gr32 = (void __user *)optval;
84775 struct group_req __user *kgr =
84776 compat_alloc_user_space(sizeof(struct group_req));
84777 u32 interface;
84778@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84779 case MCAST_BLOCK_SOURCE:
84780 case MCAST_UNBLOCK_SOURCE:
84781 {
84782- struct compat_group_source_req __user *gsr32 = (void *)optval;
84783+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
84784 struct group_source_req __user *kgsr = compat_alloc_user_space(
84785 sizeof(struct group_source_req));
84786 u32 interface;
84787@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84788 }
84789 case MCAST_MSFILTER:
84790 {
84791- struct compat_group_filter __user *gf32 = (void *)optval;
84792+ struct compat_group_filter __user *gf32 = (void __user *)optval;
84793 struct group_filter __user *kgf;
84794 u32 interface, fmode, numsrc;
84795
84796@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
84797 char __user *optval, int __user *optlen,
84798 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
84799 {
84800- struct compat_group_filter __user *gf32 = (void *)optval;
84801+ struct compat_group_filter __user *gf32 = (void __user *)optval;
84802 struct group_filter __user *kgf;
84803 int __user *koptlen;
84804 u32 interface, fmode, numsrc;
84805@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
84806
84807 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
84808 return -EINVAL;
84809- if (copy_from_user(a, args, nas[call]))
84810+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
84811 return -EFAULT;
84812 a0 = a[0];
84813 a1 = a[1];
84814diff --git a/net/core/datagram.c b/net/core/datagram.c
84815index 368f9c3..f82d4a3 100644
84816--- a/net/core/datagram.c
84817+++ b/net/core/datagram.c
84818@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
84819 }
84820
84821 kfree_skb(skb);
84822- atomic_inc(&sk->sk_drops);
84823+ atomic_inc_unchecked(&sk->sk_drops);
84824 sk_mem_reclaim_partial(sk);
84825
84826 return err;
84827diff --git a/net/core/dev.c b/net/core/dev.c
84828index f64e439..8f959e6 100644
84829--- a/net/core/dev.c
84830+++ b/net/core/dev.c
84831@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
84832 if (no_module && capable(CAP_NET_ADMIN))
84833 no_module = request_module("netdev-%s", name);
84834 if (no_module && capable(CAP_SYS_MODULE)) {
84835+#ifdef CONFIG_GRKERNSEC_MODHARDEN
84836+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
84837+#else
84838 if (!request_module("%s", name))
84839 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
84840 name);
84841+#endif
84842 }
84843 }
84844 EXPORT_SYMBOL(dev_load);
84845@@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84846 {
84847 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
84848 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
84849- atomic_long_inc(&dev->rx_dropped);
84850+ atomic_long_inc_unchecked(&dev->rx_dropped);
84851 kfree_skb(skb);
84852 return NET_RX_DROP;
84853 }
84854@@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84855 nf_reset(skb);
84856
84857 if (unlikely(!is_skb_forwardable(dev, skb))) {
84858- atomic_long_inc(&dev->rx_dropped);
84859+ atomic_long_inc_unchecked(&dev->rx_dropped);
84860 kfree_skb(skb);
84861 return NET_RX_DROP;
84862 }
84863@@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
84864
84865 struct dev_gso_cb {
84866 void (*destructor)(struct sk_buff *skb);
84867-};
84868+} __no_const;
84869
84870 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
84871
84872@@ -3053,7 +3057,7 @@ enqueue:
84873
84874 local_irq_restore(flags);
84875
84876- atomic_long_inc(&skb->dev->rx_dropped);
84877+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84878 kfree_skb(skb);
84879 return NET_RX_DROP;
84880 }
84881@@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
84882 }
84883 EXPORT_SYMBOL(netif_rx_ni);
84884
84885-static void net_tx_action(struct softirq_action *h)
84886+static void net_tx_action(void)
84887 {
84888 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84889
84890@@ -3456,7 +3460,7 @@ ncls:
84891 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
84892 } else {
84893 drop:
84894- atomic_long_inc(&skb->dev->rx_dropped);
84895+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84896 kfree_skb(skb);
84897 /* Jamal, now you will not able to escape explaining
84898 * me how you were going to use this. :-)
84899@@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
84900 }
84901 EXPORT_SYMBOL(netif_napi_del);
84902
84903-static void net_rx_action(struct softirq_action *h)
84904+static void net_rx_action(void)
84905 {
84906 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84907 unsigned long time_limit = jiffies + 2;
84908@@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
84909 else
84910 seq_printf(seq, "%04x", ntohs(pt->type));
84911
84912+#ifdef CONFIG_GRKERNSEC_HIDESYM
84913+ seq_printf(seq, " %-8s %p\n",
84914+ pt->dev ? pt->dev->name : "", NULL);
84915+#else
84916 seq_printf(seq, " %-8s %pF\n",
84917 pt->dev ? pt->dev->name : "", pt->func);
84918+#endif
84919 }
84920
84921 return 0;
84922@@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
84923 } else {
84924 netdev_stats_to_stats64(storage, &dev->stats);
84925 }
84926- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
84927+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
84928 return storage;
84929 }
84930 EXPORT_SYMBOL(dev_get_stats);
84931diff --git a/net/core/flow.c b/net/core/flow.c
84932index b0901ee..7d3c2ca 100644
84933--- a/net/core/flow.c
84934+++ b/net/core/flow.c
84935@@ -61,7 +61,7 @@ struct flow_cache {
84936 struct timer_list rnd_timer;
84937 };
84938
84939-atomic_t flow_cache_genid = ATOMIC_INIT(0);
84940+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
84941 EXPORT_SYMBOL(flow_cache_genid);
84942 static struct flow_cache flow_cache_global;
84943 static struct kmem_cache *flow_cachep __read_mostly;
84944@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
84945
84946 static int flow_entry_valid(struct flow_cache_entry *fle)
84947 {
84948- if (atomic_read(&flow_cache_genid) != fle->genid)
84949+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
84950 return 0;
84951 if (fle->object && !fle->object->ops->check(fle->object))
84952 return 0;
84953@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
84954 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
84955 fcp->hash_count++;
84956 }
84957- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
84958+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
84959 flo = fle->object;
84960 if (!flo)
84961 goto ret_object;
84962@@ -280,7 +280,7 @@ nocache:
84963 }
84964 flo = resolver(net, key, family, dir, flo, ctx);
84965 if (fle) {
84966- fle->genid = atomic_read(&flow_cache_genid);
84967+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
84968 if (!IS_ERR(flo))
84969 fle->object = flo;
84970 else
84971diff --git a/net/core/iovec.c b/net/core/iovec.c
84972index 7e7aeb0..2a998cb 100644
84973--- a/net/core/iovec.c
84974+++ b/net/core/iovec.c
84975@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84976 if (m->msg_namelen) {
84977 if (mode == VERIFY_READ) {
84978 void __user *namep;
84979- namep = (void __user __force *) m->msg_name;
84980+ namep = (void __force_user *) m->msg_name;
84981 err = move_addr_to_kernel(namep, m->msg_namelen,
84982 address);
84983 if (err < 0)
84984@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84985 }
84986
84987 size = m->msg_iovlen * sizeof(struct iovec);
84988- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
84989+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
84990 return -EFAULT;
84991
84992 m->msg_iov = iov;
84993diff --git a/net/core/neighbour.c b/net/core/neighbour.c
84994index c815f28..e6403f2 100644
84995--- a/net/core/neighbour.c
84996+++ b/net/core/neighbour.c
84997@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
84998 size_t *lenp, loff_t *ppos)
84999 {
85000 int size, ret;
85001- ctl_table tmp = *ctl;
85002+ ctl_table_no_const tmp = *ctl;
85003
85004 tmp.extra1 = &zero;
85005 tmp.extra2 = &unres_qlen_max;
85006diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
85007index 28c5f5a..7edf2e2 100644
85008--- a/net/core/net-sysfs.c
85009+++ b/net/core/net-sysfs.c
85010@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
85011 }
85012 EXPORT_SYMBOL(netdev_class_remove_file);
85013
85014-int netdev_kobject_init(void)
85015+int __init netdev_kobject_init(void)
85016 {
85017 kobj_ns_type_register(&net_ns_type_operations);
85018 return class_register(&net_class);
85019diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
85020index 8acce01..2e306bb 100644
85021--- a/net/core/net_namespace.c
85022+++ b/net/core/net_namespace.c
85023@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
85024 int error;
85025 LIST_HEAD(net_exit_list);
85026
85027- list_add_tail(&ops->list, list);
85028+ pax_list_add_tail((struct list_head *)&ops->list, list);
85029 if (ops->init || (ops->id && ops->size)) {
85030 for_each_net(net) {
85031 error = ops_init(ops, net);
85032@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
85033
85034 out_undo:
85035 /* If I have an error cleanup all namespaces I initialized */
85036- list_del(&ops->list);
85037+ pax_list_del((struct list_head *)&ops->list);
85038 ops_exit_list(ops, &net_exit_list);
85039 ops_free_list(ops, &net_exit_list);
85040 return error;
85041@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
85042 struct net *net;
85043 LIST_HEAD(net_exit_list);
85044
85045- list_del(&ops->list);
85046+ pax_list_del((struct list_head *)&ops->list);
85047 for_each_net(net)
85048 list_add_tail(&net->exit_list, &net_exit_list);
85049 ops_exit_list(ops, &net_exit_list);
85050@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
85051 mutex_lock(&net_mutex);
85052 error = register_pernet_operations(&pernet_list, ops);
85053 if (!error && (first_device == &pernet_list))
85054- first_device = &ops->list;
85055+ first_device = (struct list_head *)&ops->list;
85056 mutex_unlock(&net_mutex);
85057 return error;
85058 }
85059diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
85060index 1868625..e2261f5 100644
85061--- a/net/core/rtnetlink.c
85062+++ b/net/core/rtnetlink.c
85063@@ -58,7 +58,7 @@ struct rtnl_link {
85064 rtnl_doit_func doit;
85065 rtnl_dumpit_func dumpit;
85066 rtnl_calcit_func calcit;
85067-};
85068+} __no_const;
85069
85070 static DEFINE_MUTEX(rtnl_mutex);
85071
85072@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
85073 if (rtnl_link_ops_get(ops->kind))
85074 return -EEXIST;
85075
85076- if (!ops->dellink)
85077- ops->dellink = unregister_netdevice_queue;
85078+ if (!ops->dellink) {
85079+ pax_open_kernel();
85080+ *(void **)&ops->dellink = unregister_netdevice_queue;
85081+ pax_close_kernel();
85082+ }
85083
85084- list_add_tail(&ops->list, &link_ops);
85085+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
85086 return 0;
85087 }
85088 EXPORT_SYMBOL_GPL(__rtnl_link_register);
85089@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
85090 for_each_net(net) {
85091 __rtnl_kill_links(net, ops);
85092 }
85093- list_del(&ops->list);
85094+ pax_list_del((struct list_head *)&ops->list);
85095 }
85096 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
85097
85098@@ -976,6 +979,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
85099 * report anything.
85100 */
85101 ivi.spoofchk = -1;
85102+ memset(ivi.mac, 0, sizeof(ivi.mac));
85103 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
85104 break;
85105 vf_mac.vf =
85106diff --git a/net/core/scm.c b/net/core/scm.c
85107index 905dcc6..14ee2d6 100644
85108--- a/net/core/scm.c
85109+++ b/net/core/scm.c
85110@@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
85111 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85112 {
85113 struct cmsghdr __user *cm
85114- = (__force struct cmsghdr __user *)msg->msg_control;
85115+ = (struct cmsghdr __force_user *)msg->msg_control;
85116 struct cmsghdr cmhdr;
85117 int cmlen = CMSG_LEN(len);
85118 int err;
85119@@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85120 err = -EFAULT;
85121 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
85122 goto out;
85123- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
85124+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
85125 goto out;
85126 cmlen = CMSG_SPACE(len);
85127 if (msg->msg_controllen < cmlen)
85128@@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
85129 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85130 {
85131 struct cmsghdr __user *cm
85132- = (__force struct cmsghdr __user*)msg->msg_control;
85133+ = (struct cmsghdr __force_user *)msg->msg_control;
85134
85135 int fdmax = 0;
85136 int fdnum = scm->fp->count;
85137@@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85138 if (fdnum < fdmax)
85139 fdmax = fdnum;
85140
85141- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
85142+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
85143 i++, cmfptr++)
85144 {
85145 struct socket *sock;
85146diff --git a/net/core/sock.c b/net/core/sock.c
85147index bc131d4..029e378 100644
85148--- a/net/core/sock.c
85149+++ b/net/core/sock.c
85150@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85151 struct sk_buff_head *list = &sk->sk_receive_queue;
85152
85153 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
85154- atomic_inc(&sk->sk_drops);
85155+ atomic_inc_unchecked(&sk->sk_drops);
85156 trace_sock_rcvqueue_full(sk, skb);
85157 return -ENOMEM;
85158 }
85159@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85160 return err;
85161
85162 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
85163- atomic_inc(&sk->sk_drops);
85164+ atomic_inc_unchecked(&sk->sk_drops);
85165 return -ENOBUFS;
85166 }
85167
85168@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85169 skb_dst_force(skb);
85170
85171 spin_lock_irqsave(&list->lock, flags);
85172- skb->dropcount = atomic_read(&sk->sk_drops);
85173+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
85174 __skb_queue_tail(list, skb);
85175 spin_unlock_irqrestore(&list->lock, flags);
85176
85177@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
85178 skb->dev = NULL;
85179
85180 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
85181- atomic_inc(&sk->sk_drops);
85182+ atomic_inc_unchecked(&sk->sk_drops);
85183 goto discard_and_relse;
85184 }
85185 if (nested)
85186@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
85187 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
85188 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
85189 bh_unlock_sock(sk);
85190- atomic_inc(&sk->sk_drops);
85191+ atomic_inc_unchecked(&sk->sk_drops);
85192 goto discard_and_relse;
85193 }
85194
85195@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85196 struct timeval tm;
85197 } v;
85198
85199- int lv = sizeof(int);
85200- int len;
85201+ unsigned int lv = sizeof(int);
85202+ unsigned int len;
85203
85204 if (get_user(len, optlen))
85205 return -EFAULT;
85206- if (len < 0)
85207+ if (len > INT_MAX)
85208 return -EINVAL;
85209
85210 memset(&v, 0, sizeof(v));
85211@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85212
85213 case SO_PEERNAME:
85214 {
85215- char address[128];
85216+ char address[_K_SS_MAXSIZE];
85217
85218 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
85219 return -ENOTCONN;
85220- if (lv < len)
85221+ if (lv < len || sizeof address < len)
85222 return -EINVAL;
85223 if (copy_to_user(optval, address, len))
85224 return -EFAULT;
85225@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
85226
85227 if (len > lv)
85228 len = lv;
85229- if (copy_to_user(optval, &v, len))
85230+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
85231 return -EFAULT;
85232 lenout:
85233 if (put_user(len, optlen))
85234@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
85235 */
85236 smp_wmb();
85237 atomic_set(&sk->sk_refcnt, 1);
85238- atomic_set(&sk->sk_drops, 0);
85239+ atomic_set_unchecked(&sk->sk_drops, 0);
85240 }
85241 EXPORT_SYMBOL(sock_init_data);
85242
85243diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
85244index 750f44f..922399c 100644
85245--- a/net/core/sock_diag.c
85246+++ b/net/core/sock_diag.c
85247@@ -9,26 +9,33 @@
85248 #include <linux/inet_diag.h>
85249 #include <linux/sock_diag.h>
85250
85251-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
85252+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
85253 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
85254 static DEFINE_MUTEX(sock_diag_table_mutex);
85255
85256 int sock_diag_check_cookie(void *sk, __u32 *cookie)
85257 {
85258+#ifndef CONFIG_GRKERNSEC_HIDESYM
85259 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
85260 cookie[1] != INET_DIAG_NOCOOKIE) &&
85261 ((u32)(unsigned long)sk != cookie[0] ||
85262 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
85263 return -ESTALE;
85264 else
85265+#endif
85266 return 0;
85267 }
85268 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
85269
85270 void sock_diag_save_cookie(void *sk, __u32 *cookie)
85271 {
85272+#ifdef CONFIG_GRKERNSEC_HIDESYM
85273+ cookie[0] = 0;
85274+ cookie[1] = 0;
85275+#else
85276 cookie[0] = (u32)(unsigned long)sk;
85277 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
85278+#endif
85279 }
85280 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
85281
85282@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
85283 mutex_lock(&sock_diag_table_mutex);
85284 if (sock_diag_handlers[hndl->family])
85285 err = -EBUSY;
85286- else
85287+ else {
85288+ pax_open_kernel();
85289 sock_diag_handlers[hndl->family] = hndl;
85290+ pax_close_kernel();
85291+ }
85292 mutex_unlock(&sock_diag_table_mutex);
85293
85294 return err;
85295@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
85296
85297 mutex_lock(&sock_diag_table_mutex);
85298 BUG_ON(sock_diag_handlers[family] != hnld);
85299+ pax_open_kernel();
85300 sock_diag_handlers[family] = NULL;
85301+ pax_close_kernel();
85302 mutex_unlock(&sock_diag_table_mutex);
85303 }
85304 EXPORT_SYMBOL_GPL(sock_diag_unregister);
85305
85306-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
85307-{
85308- if (sock_diag_handlers[family] == NULL)
85309- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
85310- NETLINK_SOCK_DIAG, family);
85311-
85312- mutex_lock(&sock_diag_table_mutex);
85313- return sock_diag_handlers[family];
85314-}
85315-
85316-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
85317-{
85318- mutex_unlock(&sock_diag_table_mutex);
85319-}
85320-
85321 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85322 {
85323 int err;
85324@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85325 if (req->sdiag_family >= AF_MAX)
85326 return -EINVAL;
85327
85328- hndl = sock_diag_lock_handler(req->sdiag_family);
85329+ if (sock_diag_handlers[req->sdiag_family] == NULL)
85330+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
85331+ NETLINK_SOCK_DIAG, req->sdiag_family);
85332+
85333+ mutex_lock(&sock_diag_table_mutex);
85334+ hndl = sock_diag_handlers[req->sdiag_family];
85335 if (hndl == NULL)
85336 err = -ENOENT;
85337 else
85338 err = hndl->dump(skb, nlh);
85339- sock_diag_unlock_handler(hndl);
85340+ mutex_unlock(&sock_diag_table_mutex);
85341
85342 return err;
85343 }
85344diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
85345index d1b0804..4aed0a5 100644
85346--- a/net/core/sysctl_net_core.c
85347+++ b/net/core/sysctl_net_core.c
85348@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
85349 {
85350 unsigned int orig_size, size;
85351 int ret, i;
85352- ctl_table tmp = {
85353+ ctl_table_no_const tmp = {
85354 .data = &size,
85355 .maxlen = sizeof(size),
85356 .mode = table->mode
85357@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
85358
85359 static __net_init int sysctl_core_net_init(struct net *net)
85360 {
85361- struct ctl_table *tbl;
85362+ ctl_table_no_const *tbl = NULL;
85363
85364 net->core.sysctl_somaxconn = SOMAXCONN;
85365
85366- tbl = netns_core_table;
85367 if (!net_eq(net, &init_net)) {
85368- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
85369+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
85370 if (tbl == NULL)
85371 goto err_dup;
85372
85373@@ -221,16 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
85374 if (net->user_ns != &init_user_ns) {
85375 tbl[0].procname = NULL;
85376 }
85377- }
85378-
85379- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
85380+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
85381+ } else
85382+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
85383 if (net->core.sysctl_hdr == NULL)
85384 goto err_reg;
85385
85386 return 0;
85387
85388 err_reg:
85389- if (tbl != netns_core_table)
85390+ if (tbl)
85391 kfree(tbl);
85392 err_dup:
85393 return -ENOMEM;
85394@@ -246,7 +245,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
85395 kfree(tbl);
85396 }
85397
85398-static __net_initdata struct pernet_operations sysctl_core_ops = {
85399+static __net_initconst struct pernet_operations sysctl_core_ops = {
85400 .init = sysctl_core_net_init,
85401 .exit = sysctl_core_net_exit,
85402 };
85403diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
85404index 1b588e2..21291f1 100644
85405--- a/net/dcb/dcbnl.c
85406+++ b/net/dcb/dcbnl.c
85407@@ -284,6 +284,7 @@ static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh,
85408 if (!netdev->dcbnl_ops->getpermhwaddr)
85409 return -EOPNOTSUPP;
85410
85411+ memset(perm_addr, 0, sizeof(perm_addr));
85412 netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
85413
85414 return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr);
85415@@ -1042,6 +1043,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
85416
85417 if (ops->ieee_getets) {
85418 struct ieee_ets ets;
85419+ memset(&ets, 0, sizeof(ets));
85420 err = ops->ieee_getets(netdev, &ets);
85421 if (!err &&
85422 nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets))
85423@@ -1050,6 +1052,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
85424
85425 if (ops->ieee_getmaxrate) {
85426 struct ieee_maxrate maxrate;
85427+ memset(&maxrate, 0, sizeof(maxrate));
85428 err = ops->ieee_getmaxrate(netdev, &maxrate);
85429 if (!err) {
85430 err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE,
85431@@ -1061,6 +1064,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
85432
85433 if (ops->ieee_getpfc) {
85434 struct ieee_pfc pfc;
85435+ memset(&pfc, 0, sizeof(pfc));
85436 err = ops->ieee_getpfc(netdev, &pfc);
85437 if (!err &&
85438 nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc))
85439@@ -1094,6 +1098,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
85440 /* get peer info if available */
85441 if (ops->ieee_peer_getets) {
85442 struct ieee_ets ets;
85443+ memset(&ets, 0, sizeof(ets));
85444 err = ops->ieee_peer_getets(netdev, &ets);
85445 if (!err &&
85446 nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets))
85447@@ -1102,6 +1107,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
85448
85449 if (ops->ieee_peer_getpfc) {
85450 struct ieee_pfc pfc;
85451+ memset(&pfc, 0, sizeof(pfc));
85452 err = ops->ieee_peer_getpfc(netdev, &pfc);
85453 if (!err &&
85454 nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc))
85455@@ -1280,6 +1286,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
85456 /* peer info if available */
85457 if (ops->cee_peer_getpg) {
85458 struct cee_pg pg;
85459+ memset(&pg, 0, sizeof(pg));
85460 err = ops->cee_peer_getpg(netdev, &pg);
85461 if (!err &&
85462 nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg))
85463@@ -1288,6 +1295,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
85464
85465 if (ops->cee_peer_getpfc) {
85466 struct cee_pfc pfc;
85467+ memset(&pfc, 0, sizeof(pfc));
85468 err = ops->cee_peer_getpfc(netdev, &pfc);
85469 if (!err &&
85470 nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc))
85471diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
85472index 307c322..78a4c6f 100644
85473--- a/net/decnet/af_decnet.c
85474+++ b/net/decnet/af_decnet.c
85475@@ -468,6 +468,7 @@ static struct proto dn_proto = {
85476 .sysctl_rmem = sysctl_decnet_rmem,
85477 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
85478 .obj_size = sizeof(struct dn_sock),
85479+ .slab_flags = SLAB_USERCOPY,
85480 };
85481
85482 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
85483diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
85484index a55eecc..dd8428c 100644
85485--- a/net/decnet/sysctl_net_decnet.c
85486+++ b/net/decnet/sysctl_net_decnet.c
85487@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
85488
85489 if (len > *lenp) len = *lenp;
85490
85491- if (copy_to_user(buffer, addr, len))
85492+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
85493 return -EFAULT;
85494
85495 *lenp = len;
85496@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
85497
85498 if (len > *lenp) len = *lenp;
85499
85500- if (copy_to_user(buffer, devname, len))
85501+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
85502 return -EFAULT;
85503
85504 *lenp = len;
85505diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
85506index fcf104e..95552d4 100644
85507--- a/net/ipv4/af_inet.c
85508+++ b/net/ipv4/af_inet.c
85509@@ -1717,13 +1717,9 @@ static int __init inet_init(void)
85510
85511 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
85512
85513- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
85514- if (!sysctl_local_reserved_ports)
85515- goto out;
85516-
85517 rc = proto_register(&tcp_prot, 1);
85518 if (rc)
85519- goto out_free_reserved_ports;
85520+ goto out;
85521
85522 rc = proto_register(&udp_prot, 1);
85523 if (rc)
85524@@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
85525 proto_unregister(&udp_prot);
85526 out_unregister_tcp_proto:
85527 proto_unregister(&tcp_prot);
85528-out_free_reserved_ports:
85529- kfree(sysctl_local_reserved_ports);
85530 goto out;
85531 }
85532
85533diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
85534index a69b4e4..dbccba5 100644
85535--- a/net/ipv4/ah4.c
85536+++ b/net/ipv4/ah4.c
85537@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
85538 return;
85539
85540 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85541- atomic_inc(&flow_cache_genid);
85542+ atomic_inc_unchecked(&flow_cache_genid);
85543 rt_genid_bump(net);
85544
85545 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
85546diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
85547index a8e4f26..25e5f40 100644
85548--- a/net/ipv4/devinet.c
85549+++ b/net/ipv4/devinet.c
85550@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
85551 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
85552 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
85553
85554-static struct devinet_sysctl_table {
85555+static const struct devinet_sysctl_table {
85556 struct ctl_table_header *sysctl_header;
85557 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
85558 } devinet_sysctl = {
85559@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
85560 int err;
85561 struct ipv4_devconf *all, *dflt;
85562 #ifdef CONFIG_SYSCTL
85563- struct ctl_table *tbl = ctl_forward_entry;
85564+ ctl_table_no_const *tbl = NULL;
85565 struct ctl_table_header *forw_hdr;
85566 #endif
85567
85568@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
85569 goto err_alloc_dflt;
85570
85571 #ifdef CONFIG_SYSCTL
85572- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
85573+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
85574 if (tbl == NULL)
85575 goto err_alloc_ctl;
85576
85577@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
85578 goto err_reg_dflt;
85579
85580 err = -ENOMEM;
85581- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
85582+ if (!net_eq(net, &init_net))
85583+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
85584+ else
85585+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
85586 if (forw_hdr == NULL)
85587 goto err_reg_ctl;
85588 net->ipv4.forw_hdr = forw_hdr;
85589@@ -1935,8 +1938,7 @@ err_reg_ctl:
85590 err_reg_dflt:
85591 __devinet_sysctl_unregister(all);
85592 err_reg_all:
85593- if (tbl != ctl_forward_entry)
85594- kfree(tbl);
85595+ kfree(tbl);
85596 err_alloc_ctl:
85597 #endif
85598 if (dflt != &ipv4_devconf_dflt)
85599diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
85600index 3b4f0cd..8cb864c 100644
85601--- a/net/ipv4/esp4.c
85602+++ b/net/ipv4/esp4.c
85603@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
85604 return;
85605
85606 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85607- atomic_inc(&flow_cache_genid);
85608+ atomic_inc_unchecked(&flow_cache_genid);
85609 rt_genid_bump(net);
85610
85611 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
85612diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
85613index 5cd75e2..f57ef39 100644
85614--- a/net/ipv4/fib_frontend.c
85615+++ b/net/ipv4/fib_frontend.c
85616@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
85617 #ifdef CONFIG_IP_ROUTE_MULTIPATH
85618 fib_sync_up(dev);
85619 #endif
85620- atomic_inc(&net->ipv4.dev_addr_genid);
85621+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85622 rt_cache_flush(dev_net(dev));
85623 break;
85624 case NETDEV_DOWN:
85625 fib_del_ifaddr(ifa, NULL);
85626- atomic_inc(&net->ipv4.dev_addr_genid);
85627+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85628 if (ifa->ifa_dev->ifa_list == NULL) {
85629 /* Last address was deleted from this interface.
85630 * Disable IP.
85631@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
85632 #ifdef CONFIG_IP_ROUTE_MULTIPATH
85633 fib_sync_up(dev);
85634 #endif
85635- atomic_inc(&net->ipv4.dev_addr_genid);
85636+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
85637 rt_cache_flush(net);
85638 break;
85639 case NETDEV_DOWN:
85640diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
85641index 4797a80..2bd54e9 100644
85642--- a/net/ipv4/fib_semantics.c
85643+++ b/net/ipv4/fib_semantics.c
85644@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
85645 nh->nh_saddr = inet_select_addr(nh->nh_dev,
85646 nh->nh_gw,
85647 nh->nh_parent->fib_scope);
85648- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
85649+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
85650
85651 return nh->nh_saddr;
85652 }
85653diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
85654index d0670f0..744ac80 100644
85655--- a/net/ipv4/inet_connection_sock.c
85656+++ b/net/ipv4/inet_connection_sock.c
85657@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
85658 .range = { 32768, 61000 },
85659 };
85660
85661-unsigned long *sysctl_local_reserved_ports;
85662+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
85663 EXPORT_SYMBOL(sysctl_local_reserved_ports);
85664
85665 void inet_get_local_port_range(int *low, int *high)
85666diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
85667index fa3ae81..0dbe6b8 100644
85668--- a/net/ipv4/inet_hashtables.c
85669+++ b/net/ipv4/inet_hashtables.c
85670@@ -18,12 +18,15 @@
85671 #include <linux/sched.h>
85672 #include <linux/slab.h>
85673 #include <linux/wait.h>
85674+#include <linux/security.h>
85675
85676 #include <net/inet_connection_sock.h>
85677 #include <net/inet_hashtables.h>
85678 #include <net/secure_seq.h>
85679 #include <net/ip.h>
85680
85681+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
85682+
85683 /*
85684 * Allocate and initialize a new local port bind bucket.
85685 * The bindhash mutex for snum's hash chain must be held here.
85686@@ -540,6 +543,8 @@ ok:
85687 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
85688 spin_unlock(&head->lock);
85689
85690+ gr_update_task_in_ip_table(current, inet_sk(sk));
85691+
85692 if (tw) {
85693 inet_twsk_deschedule(tw, death_row);
85694 while (twrefcnt) {
85695diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
85696index 000e3d2..5472da3 100644
85697--- a/net/ipv4/inetpeer.c
85698+++ b/net/ipv4/inetpeer.c
85699@@ -503,8 +503,8 @@ relookup:
85700 if (p) {
85701 p->daddr = *daddr;
85702 atomic_set(&p->refcnt, 1);
85703- atomic_set(&p->rid, 0);
85704- atomic_set(&p->ip_id_count,
85705+ atomic_set_unchecked(&p->rid, 0);
85706+ atomic_set_unchecked(&p->ip_id_count,
85707 (daddr->family == AF_INET) ?
85708 secure_ip_id(daddr->addr.a4) :
85709 secure_ipv6_id(daddr->addr.a6));
85710diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
85711index eb9d63a..31c5372 100644
85712--- a/net/ipv4/ip_fragment.c
85713+++ b/net/ipv4/ip_fragment.c
85714@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
85715 return 0;
85716
85717 start = qp->rid;
85718- end = atomic_inc_return(&peer->rid);
85719+ end = atomic_inc_return_unchecked(&peer->rid);
85720 qp->rid = end;
85721
85722 rc = qp->q.fragments && (end - start) > max;
85723@@ -789,12 +789,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
85724
85725 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85726 {
85727- struct ctl_table *table;
85728+ ctl_table_no_const *table = NULL;
85729 struct ctl_table_header *hdr;
85730
85731- table = ip4_frags_ns_ctl_table;
85732 if (!net_eq(net, &init_net)) {
85733- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85734+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85735 if (table == NULL)
85736 goto err_alloc;
85737
85738@@ -805,9 +804,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85739 /* Don't export sysctls to unprivileged users */
85740 if (net->user_ns != &init_user_ns)
85741 table[0].procname = NULL;
85742- }
85743+ hdr = register_net_sysctl(net, "net/ipv4", table);
85744+ } else
85745+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
85746
85747- hdr = register_net_sysctl(net, "net/ipv4", table);
85748 if (hdr == NULL)
85749 goto err_reg;
85750
85751@@ -815,8 +815,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85752 return 0;
85753
85754 err_reg:
85755- if (!net_eq(net, &init_net))
85756- kfree(table);
85757+ kfree(table);
85758 err_alloc:
85759 return -ENOMEM;
85760 }
85761diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
85762index e81b1ca..6f3b5b9 100644
85763--- a/net/ipv4/ip_gre.c
85764+++ b/net/ipv4/ip_gre.c
85765@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
85766 module_param(log_ecn_error, bool, 0644);
85767 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
85768
85769-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
85770+static struct rtnl_link_ops ipgre_link_ops;
85771 static int ipgre_tunnel_init(struct net_device *dev);
85772 static void ipgre_tunnel_setup(struct net_device *dev);
85773 static int ipgre_tunnel_bind_dev(struct net_device *dev);
85774@@ -1756,7 +1756,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
85775 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
85776 };
85777
85778-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85779+static struct rtnl_link_ops ipgre_link_ops = {
85780 .kind = "gre",
85781 .maxtype = IFLA_GRE_MAX,
85782 .policy = ipgre_policy,
85783@@ -1769,7 +1769,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85784 .fill_info = ipgre_fill_info,
85785 };
85786
85787-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
85788+static struct rtnl_link_ops ipgre_tap_ops = {
85789 .kind = "gretap",
85790 .maxtype = IFLA_GRE_MAX,
85791 .policy = ipgre_policy,
85792diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
85793index d9c4f11..02b82db 100644
85794--- a/net/ipv4/ip_sockglue.c
85795+++ b/net/ipv4/ip_sockglue.c
85796@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85797 len = min_t(unsigned int, len, opt->optlen);
85798 if (put_user(len, optlen))
85799 return -EFAULT;
85800- if (copy_to_user(optval, opt->__data, len))
85801+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
85802+ copy_to_user(optval, opt->__data, len))
85803 return -EFAULT;
85804 return 0;
85805 }
85806@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85807 if (sk->sk_type != SOCK_STREAM)
85808 return -ENOPROTOOPT;
85809
85810- msg.msg_control = optval;
85811+ msg.msg_control = (void __force_kernel *)optval;
85812 msg.msg_controllen = len;
85813 msg.msg_flags = flags;
85814
85815diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
85816index c3a4233..1412161 100644
85817--- a/net/ipv4/ip_vti.c
85818+++ b/net/ipv4/ip_vti.c
85819@@ -47,7 +47,7 @@
85820 #define HASH_SIZE 16
85821 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
85822
85823-static struct rtnl_link_ops vti_link_ops __read_mostly;
85824+static struct rtnl_link_ops vti_link_ops;
85825
85826 static int vti_net_id __read_mostly;
85827 struct vti_net {
85828@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
85829 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
85830 };
85831
85832-static struct rtnl_link_ops vti_link_ops __read_mostly = {
85833+static struct rtnl_link_ops vti_link_ops = {
85834 .kind = "vti",
85835 .maxtype = IFLA_VTI_MAX,
85836 .policy = vti_policy,
85837diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
85838index 9a46dae..5f793a0 100644
85839--- a/net/ipv4/ipcomp.c
85840+++ b/net/ipv4/ipcomp.c
85841@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
85842 return;
85843
85844 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85845- atomic_inc(&flow_cache_genid);
85846+ atomic_inc_unchecked(&flow_cache_genid);
85847 rt_genid_bump(net);
85848
85849 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
85850diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
85851index a2e50ae..e152b7c 100644
85852--- a/net/ipv4/ipconfig.c
85853+++ b/net/ipv4/ipconfig.c
85854@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
85855
85856 mm_segment_t oldfs = get_fs();
85857 set_fs(get_ds());
85858- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85859+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85860 set_fs(oldfs);
85861 return res;
85862 }
85863@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
85864
85865 mm_segment_t oldfs = get_fs();
85866 set_fs(get_ds());
85867- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85868+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85869 set_fs(oldfs);
85870 return res;
85871 }
85872@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
85873
85874 mm_segment_t oldfs = get_fs();
85875 set_fs(get_ds());
85876- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
85877+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
85878 set_fs(oldfs);
85879 return res;
85880 }
85881diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
85882index 191fc24..1b3b804 100644
85883--- a/net/ipv4/ipip.c
85884+++ b/net/ipv4/ipip.c
85885@@ -138,7 +138,7 @@ struct ipip_net {
85886 static int ipip_tunnel_init(struct net_device *dev);
85887 static void ipip_tunnel_setup(struct net_device *dev);
85888 static void ipip_dev_free(struct net_device *dev);
85889-static struct rtnl_link_ops ipip_link_ops __read_mostly;
85890+static struct rtnl_link_ops ipip_link_ops;
85891
85892 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
85893 struct rtnl_link_stats64 *tot)
85894@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
85895 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
85896 };
85897
85898-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
85899+static struct rtnl_link_ops ipip_link_ops = {
85900 .kind = "ipip",
85901 .maxtype = IFLA_IPTUN_MAX,
85902 .policy = ipip_policy,
85903diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
85904index 3ea4127..849297b 100644
85905--- a/net/ipv4/netfilter/arp_tables.c
85906+++ b/net/ipv4/netfilter/arp_tables.c
85907@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
85908 #endif
85909
85910 static int get_info(struct net *net, void __user *user,
85911- const int *len, int compat)
85912+ int len, int compat)
85913 {
85914 char name[XT_TABLE_MAXNAMELEN];
85915 struct xt_table *t;
85916 int ret;
85917
85918- if (*len != sizeof(struct arpt_getinfo)) {
85919- duprintf("length %u != %Zu\n", *len,
85920+ if (len != sizeof(struct arpt_getinfo)) {
85921+ duprintf("length %u != %Zu\n", len,
85922 sizeof(struct arpt_getinfo));
85923 return -EINVAL;
85924 }
85925@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
85926 info.size = private->size;
85927 strcpy(info.name, name);
85928
85929- if (copy_to_user(user, &info, *len) != 0)
85930+ if (copy_to_user(user, &info, len) != 0)
85931 ret = -EFAULT;
85932 else
85933 ret = 0;
85934@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
85935
85936 switch (cmd) {
85937 case ARPT_SO_GET_INFO:
85938- ret = get_info(sock_net(sk), user, len, 1);
85939+ ret = get_info(sock_net(sk), user, *len, 1);
85940 break;
85941 case ARPT_SO_GET_ENTRIES:
85942 ret = compat_get_entries(sock_net(sk), user, len);
85943@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
85944
85945 switch (cmd) {
85946 case ARPT_SO_GET_INFO:
85947- ret = get_info(sock_net(sk), user, len, 0);
85948+ ret = get_info(sock_net(sk), user, *len, 0);
85949 break;
85950
85951 case ARPT_SO_GET_ENTRIES:
85952diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
85953index 17c5e06..1b91206 100644
85954--- a/net/ipv4/netfilter/ip_tables.c
85955+++ b/net/ipv4/netfilter/ip_tables.c
85956@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
85957 #endif
85958
85959 static int get_info(struct net *net, void __user *user,
85960- const int *len, int compat)
85961+ int len, int compat)
85962 {
85963 char name[XT_TABLE_MAXNAMELEN];
85964 struct xt_table *t;
85965 int ret;
85966
85967- if (*len != sizeof(struct ipt_getinfo)) {
85968- duprintf("length %u != %zu\n", *len,
85969+ if (len != sizeof(struct ipt_getinfo)) {
85970+ duprintf("length %u != %zu\n", len,
85971 sizeof(struct ipt_getinfo));
85972 return -EINVAL;
85973 }
85974@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
85975 info.size = private->size;
85976 strcpy(info.name, name);
85977
85978- if (copy_to_user(user, &info, *len) != 0)
85979+ if (copy_to_user(user, &info, len) != 0)
85980 ret = -EFAULT;
85981 else
85982 ret = 0;
85983@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85984
85985 switch (cmd) {
85986 case IPT_SO_GET_INFO:
85987- ret = get_info(sock_net(sk), user, len, 1);
85988+ ret = get_info(sock_net(sk), user, *len, 1);
85989 break;
85990 case IPT_SO_GET_ENTRIES:
85991 ret = compat_get_entries(sock_net(sk), user, len);
85992@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85993
85994 switch (cmd) {
85995 case IPT_SO_GET_INFO:
85996- ret = get_info(sock_net(sk), user, len, 0);
85997+ ret = get_info(sock_net(sk), user, *len, 0);
85998 break;
85999
86000 case IPT_SO_GET_ENTRIES:
86001diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
86002index dc454cc..5bb917f 100644
86003--- a/net/ipv4/ping.c
86004+++ b/net/ipv4/ping.c
86005@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
86006 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
86007 0, sock_i_ino(sp),
86008 atomic_read(&sp->sk_refcnt), sp,
86009- atomic_read(&sp->sk_drops), len);
86010+ atomic_read_unchecked(&sp->sk_drops), len);
86011 }
86012
86013 static int ping_seq_show(struct seq_file *seq, void *v)
86014diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
86015index 6f08991..55867ad 100644
86016--- a/net/ipv4/raw.c
86017+++ b/net/ipv4/raw.c
86018@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
86019 int raw_rcv(struct sock *sk, struct sk_buff *skb)
86020 {
86021 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
86022- atomic_inc(&sk->sk_drops);
86023+ atomic_inc_unchecked(&sk->sk_drops);
86024 kfree_skb(skb);
86025 return NET_RX_DROP;
86026 }
86027@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
86028
86029 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
86030 {
86031+ struct icmp_filter filter;
86032+
86033 if (optlen > sizeof(struct icmp_filter))
86034 optlen = sizeof(struct icmp_filter);
86035- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
86036+ if (copy_from_user(&filter, optval, optlen))
86037 return -EFAULT;
86038+ raw_sk(sk)->filter = filter;
86039 return 0;
86040 }
86041
86042 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
86043 {
86044 int len, ret = -EFAULT;
86045+ struct icmp_filter filter;
86046
86047 if (get_user(len, optlen))
86048 goto out;
86049@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
86050 if (len > sizeof(struct icmp_filter))
86051 len = sizeof(struct icmp_filter);
86052 ret = -EFAULT;
86053- if (put_user(len, optlen) ||
86054- copy_to_user(optval, &raw_sk(sk)->filter, len))
86055+ filter = raw_sk(sk)->filter;
86056+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
86057 goto out;
86058 ret = 0;
86059 out: return ret;
86060@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86061 0, 0L, 0,
86062 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86063 0, sock_i_ino(sp),
86064- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86065+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86066 }
86067
86068 static int raw_seq_show(struct seq_file *seq, void *v)
86069diff --git a/net/ipv4/route.c b/net/ipv4/route.c
86070index a0fcc47..32e2c89 100644
86071--- a/net/ipv4/route.c
86072+++ b/net/ipv4/route.c
86073@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
86074 .maxlen = sizeof(int),
86075 .mode = 0200,
86076 .proc_handler = ipv4_sysctl_rtcache_flush,
86077+ .extra1 = &init_net,
86078 },
86079 { },
86080 };
86081
86082 static __net_init int sysctl_route_net_init(struct net *net)
86083 {
86084- struct ctl_table *tbl;
86085+ ctl_table_no_const *tbl = NULL;
86086
86087- tbl = ipv4_route_flush_table;
86088 if (!net_eq(net, &init_net)) {
86089- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86090+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86091 if (tbl == NULL)
86092 goto err_dup;
86093
86094 /* Don't export sysctls to unprivileged users */
86095 if (net->user_ns != &init_user_ns)
86096 tbl[0].procname = NULL;
86097- }
86098- tbl[0].extra1 = net;
86099+ tbl[0].extra1 = net;
86100+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86101+ } else
86102+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
86103
86104- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86105 if (net->ipv4.route_hdr == NULL)
86106 goto err_reg;
86107 return 0;
86108
86109 err_reg:
86110- if (tbl != ipv4_route_flush_table)
86111- kfree(tbl);
86112+ kfree(tbl);
86113 err_dup:
86114 return -ENOMEM;
86115 }
86116@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
86117
86118 static __net_init int rt_genid_init(struct net *net)
86119 {
86120- atomic_set(&net->rt_genid, 0);
86121+ atomic_set_unchecked(&net->rt_genid, 0);
86122 get_random_bytes(&net->ipv4.dev_addr_genid,
86123 sizeof(net->ipv4.dev_addr_genid));
86124 return 0;
86125diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
86126index d84400b..62e066e 100644
86127--- a/net/ipv4/sysctl_net_ipv4.c
86128+++ b/net/ipv4/sysctl_net_ipv4.c
86129@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
86130 {
86131 int ret;
86132 int range[2];
86133- ctl_table tmp = {
86134+ ctl_table_no_const tmp = {
86135 .data = &range,
86136 .maxlen = sizeof(range),
86137 .mode = table->mode,
86138@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
86139 int ret;
86140 gid_t urange[2];
86141 kgid_t low, high;
86142- ctl_table tmp = {
86143+ ctl_table_no_const tmp = {
86144 .data = &urange,
86145 .maxlen = sizeof(urange),
86146 .mode = table->mode,
86147@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
86148 void __user *buffer, size_t *lenp, loff_t *ppos)
86149 {
86150 char val[TCP_CA_NAME_MAX];
86151- ctl_table tbl = {
86152+ ctl_table_no_const tbl = {
86153 .data = val,
86154 .maxlen = TCP_CA_NAME_MAX,
86155 };
86156@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
86157 void __user *buffer, size_t *lenp,
86158 loff_t *ppos)
86159 {
86160- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
86161+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
86162 int ret;
86163
86164 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86165@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
86166 void __user *buffer, size_t *lenp,
86167 loff_t *ppos)
86168 {
86169- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
86170+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
86171 int ret;
86172
86173 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86174@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86175 struct mem_cgroup *memcg;
86176 #endif
86177
86178- ctl_table tmp = {
86179+ ctl_table_no_const tmp = {
86180 .data = &vec,
86181 .maxlen = sizeof(vec),
86182 .mode = ctl->mode,
86183 };
86184
86185 if (!write) {
86186- ctl->data = &net->ipv4.sysctl_tcp_mem;
86187- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
86188+ ctl_table_no_const tcp_mem = *ctl;
86189+
86190+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
86191+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
86192 }
86193
86194 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
86195@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86196 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
86197 size_t *lenp, loff_t *ppos)
86198 {
86199- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86200+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86201 struct tcp_fastopen_context *ctxt;
86202 int ret;
86203 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
86204@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
86205 },
86206 {
86207 .procname = "ip_local_reserved_ports",
86208- .data = NULL, /* initialized in sysctl_ipv4_init */
86209+ .data = sysctl_local_reserved_ports,
86210 .maxlen = 65536,
86211 .mode = 0644,
86212 .proc_handler = proc_do_large_bitmap,
86213@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
86214
86215 static __net_init int ipv4_sysctl_init_net(struct net *net)
86216 {
86217- struct ctl_table *table;
86218+ ctl_table_no_const *table = NULL;
86219
86220- table = ipv4_net_table;
86221 if (!net_eq(net, &init_net)) {
86222- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
86223+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
86224 if (table == NULL)
86225 goto err_alloc;
86226
86227@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
86228
86229 tcp_init_mem(net);
86230
86231- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86232+ if (!net_eq(net, &init_net))
86233+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86234+ else
86235+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
86236 if (net->ipv4.ipv4_hdr == NULL)
86237 goto err_reg;
86238
86239 return 0;
86240
86241 err_reg:
86242- if (!net_eq(net, &init_net))
86243- kfree(table);
86244+ kfree(table);
86245 err_alloc:
86246 return -ENOMEM;
86247 }
86248@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
86249 static __init int sysctl_ipv4_init(void)
86250 {
86251 struct ctl_table_header *hdr;
86252- struct ctl_table *i;
86253-
86254- for (i = ipv4_table; i->procname; i++) {
86255- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
86256- i->data = sysctl_local_reserved_ports;
86257- break;
86258- }
86259- }
86260- if (!i->procname)
86261- return -EINVAL;
86262
86263 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
86264 if (hdr == NULL)
86265diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
86266index ad70a96..50cb55b 100644
86267--- a/net/ipv4/tcp_input.c
86268+++ b/net/ipv4/tcp_input.c
86269@@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
86270 * simplifies code)
86271 */
86272 static void
86273-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
86274+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
86275 struct sk_buff *head, struct sk_buff *tail,
86276 u32 start, u32 end)
86277 {
86278@@ -5850,6 +5850,7 @@ discard:
86279 tcp_paws_reject(&tp->rx_opt, 0))
86280 goto discard_and_undo;
86281
86282+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
86283 if (th->syn) {
86284 /* We see SYN without ACK. It is attempt of
86285 * simultaneous connect with crossed SYNs.
86286@@ -5900,6 +5901,7 @@ discard:
86287 goto discard;
86288 #endif
86289 }
86290+#endif
86291 /* "fifth, if neither of the SYN or RST bits is set then
86292 * drop the segment and return."
86293 */
86294@@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
86295 goto discard;
86296
86297 if (th->syn) {
86298- if (th->fin)
86299+ if (th->fin || th->urg || th->psh)
86300 goto discard;
86301 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
86302 return 1;
86303diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
86304index eadb693..e8f7251 100644
86305--- a/net/ipv4/tcp_ipv4.c
86306+++ b/net/ipv4/tcp_ipv4.c
86307@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
86308 EXPORT_SYMBOL(sysctl_tcp_low_latency);
86309
86310
86311+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86312+extern int grsec_enable_blackhole;
86313+#endif
86314+
86315 #ifdef CONFIG_TCP_MD5SIG
86316 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
86317 __be32 daddr, __be32 saddr, const struct tcphdr *th);
86318@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
86319 return 0;
86320
86321 reset:
86322+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86323+ if (!grsec_enable_blackhole)
86324+#endif
86325 tcp_v4_send_reset(rsk, skb);
86326 discard:
86327 kfree_skb(skb);
86328@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
86329 TCP_SKB_CB(skb)->sacked = 0;
86330
86331 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86332- if (!sk)
86333+ if (!sk) {
86334+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86335+ ret = 1;
86336+#endif
86337 goto no_tcp_socket;
86338-
86339+ }
86340 process:
86341- if (sk->sk_state == TCP_TIME_WAIT)
86342+ if (sk->sk_state == TCP_TIME_WAIT) {
86343+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86344+ ret = 2;
86345+#endif
86346 goto do_time_wait;
86347+ }
86348
86349 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
86350 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86351@@ -2050,6 +2064,10 @@ no_tcp_socket:
86352 bad_packet:
86353 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86354 } else {
86355+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86356+ if (!grsec_enable_blackhole || (ret == 1 &&
86357+ (skb->dev->flags & IFF_LOOPBACK)))
86358+#endif
86359 tcp_v4_send_reset(NULL, skb);
86360 }
86361
86362diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
86363index f35f2df..ccb5ca6 100644
86364--- a/net/ipv4/tcp_minisocks.c
86365+++ b/net/ipv4/tcp_minisocks.c
86366@@ -27,6 +27,10 @@
86367 #include <net/inet_common.h>
86368 #include <net/xfrm.h>
86369
86370+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86371+extern int grsec_enable_blackhole;
86372+#endif
86373+
86374 int sysctl_tcp_syncookies __read_mostly = 1;
86375 EXPORT_SYMBOL(sysctl_tcp_syncookies);
86376
86377@@ -742,7 +746,10 @@ embryonic_reset:
86378 * avoid becoming vulnerable to outside attack aiming at
86379 * resetting legit local connections.
86380 */
86381- req->rsk_ops->send_reset(sk, skb);
86382+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86383+ if (!grsec_enable_blackhole)
86384+#endif
86385+ req->rsk_ops->send_reset(sk, skb);
86386 } else if (fastopen) { /* received a valid RST pkt */
86387 reqsk_fastopen_remove(sk, req, true);
86388 tcp_reset(sk);
86389diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
86390index 4526fe6..1a34e43 100644
86391--- a/net/ipv4/tcp_probe.c
86392+++ b/net/ipv4/tcp_probe.c
86393@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
86394 if (cnt + width >= len)
86395 break;
86396
86397- if (copy_to_user(buf + cnt, tbuf, width))
86398+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
86399 return -EFAULT;
86400 cnt += width;
86401 }
86402diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
86403index b78aac3..e18230b 100644
86404--- a/net/ipv4/tcp_timer.c
86405+++ b/net/ipv4/tcp_timer.c
86406@@ -22,6 +22,10 @@
86407 #include <linux/gfp.h>
86408 #include <net/tcp.h>
86409
86410+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86411+extern int grsec_lastack_retries;
86412+#endif
86413+
86414 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
86415 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
86416 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
86417@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
86418 }
86419 }
86420
86421+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86422+ if ((sk->sk_state == TCP_LAST_ACK) &&
86423+ (grsec_lastack_retries > 0) &&
86424+ (grsec_lastack_retries < retry_until))
86425+ retry_until = grsec_lastack_retries;
86426+#endif
86427+
86428 if (retransmits_timed_out(sk, retry_until,
86429 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
86430 /* Has it gone just too far? */
86431diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
86432index 1f4d405..3524677 100644
86433--- a/net/ipv4/udp.c
86434+++ b/net/ipv4/udp.c
86435@@ -87,6 +87,7 @@
86436 #include <linux/types.h>
86437 #include <linux/fcntl.h>
86438 #include <linux/module.h>
86439+#include <linux/security.h>
86440 #include <linux/socket.h>
86441 #include <linux/sockios.h>
86442 #include <linux/igmp.h>
86443@@ -111,6 +112,10 @@
86444 #include <trace/events/skb.h>
86445 #include "udp_impl.h"
86446
86447+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86448+extern int grsec_enable_blackhole;
86449+#endif
86450+
86451 struct udp_table udp_table __read_mostly;
86452 EXPORT_SYMBOL(udp_table);
86453
86454@@ -569,6 +574,9 @@ found:
86455 return s;
86456 }
86457
86458+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
86459+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
86460+
86461 /*
86462 * This routine is called by the ICMP module when it gets some
86463 * sort of error condition. If err < 0 then the socket should
86464@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
86465 dport = usin->sin_port;
86466 if (dport == 0)
86467 return -EINVAL;
86468+
86469+ err = gr_search_udp_sendmsg(sk, usin);
86470+ if (err)
86471+ return err;
86472 } else {
86473 if (sk->sk_state != TCP_ESTABLISHED)
86474 return -EDESTADDRREQ;
86475+
86476+ err = gr_search_udp_sendmsg(sk, NULL);
86477+ if (err)
86478+ return err;
86479+
86480 daddr = inet->inet_daddr;
86481 dport = inet->inet_dport;
86482 /* Open fast path for connected socket.
86483@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
86484 udp_lib_checksum_complete(skb)) {
86485 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86486 IS_UDPLITE(sk));
86487- atomic_inc(&sk->sk_drops);
86488+ atomic_inc_unchecked(&sk->sk_drops);
86489 __skb_unlink(skb, rcvq);
86490 __skb_queue_tail(&list_kill, skb);
86491 }
86492@@ -1194,6 +1211,10 @@ try_again:
86493 if (!skb)
86494 goto out;
86495
86496+ err = gr_search_udp_recvmsg(sk, skb);
86497+ if (err)
86498+ goto out_free;
86499+
86500 ulen = skb->len - sizeof(struct udphdr);
86501 copied = len;
86502 if (copied > ulen)
86503@@ -1227,7 +1248,7 @@ try_again:
86504 if (unlikely(err)) {
86505 trace_kfree_skb(skb, udp_recvmsg);
86506 if (!peeked) {
86507- atomic_inc(&sk->sk_drops);
86508+ atomic_inc_unchecked(&sk->sk_drops);
86509 UDP_INC_STATS_USER(sock_net(sk),
86510 UDP_MIB_INERRORS, is_udplite);
86511 }
86512@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86513
86514 drop:
86515 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
86516- atomic_inc(&sk->sk_drops);
86517+ atomic_inc_unchecked(&sk->sk_drops);
86518 kfree_skb(skb);
86519 return -1;
86520 }
86521@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
86522 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
86523
86524 if (!skb1) {
86525- atomic_inc(&sk->sk_drops);
86526+ atomic_inc_unchecked(&sk->sk_drops);
86527 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
86528 IS_UDPLITE(sk));
86529 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86530@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
86531 goto csum_error;
86532
86533 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
86534+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86535+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
86536+#endif
86537 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
86538
86539 /*
86540@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
86541 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
86542 0, sock_i_ino(sp),
86543 atomic_read(&sp->sk_refcnt), sp,
86544- atomic_read(&sp->sk_drops), len);
86545+ atomic_read_unchecked(&sp->sk_drops), len);
86546 }
86547
86548 int udp4_seq_show(struct seq_file *seq, void *v)
86549diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
86550index 1b5d8cb..ffb0833 100644
86551--- a/net/ipv6/addrconf.c
86552+++ b/net/ipv6/addrconf.c
86553@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
86554 p.iph.ihl = 5;
86555 p.iph.protocol = IPPROTO_IPV6;
86556 p.iph.ttl = 64;
86557- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
86558+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
86559
86560 if (ops->ndo_do_ioctl) {
86561 mm_segment_t oldfs = get_fs();
86562@@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
86563 int *valp = ctl->data;
86564 int val = *valp;
86565 loff_t pos = *ppos;
86566- ctl_table lctl;
86567+ ctl_table_no_const lctl;
86568 int ret;
86569
86570 /*
86571@@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
86572 int *valp = ctl->data;
86573 int val = *valp;
86574 loff_t pos = *ppos;
86575- ctl_table lctl;
86576+ ctl_table_no_const lctl;
86577 int ret;
86578
86579 /*
86580diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
86581index fff5bdd..15194fb 100644
86582--- a/net/ipv6/icmp.c
86583+++ b/net/ipv6/icmp.c
86584@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
86585
86586 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
86587 {
86588- struct ctl_table *table;
86589+ ctl_table_no_const *table;
86590
86591 table = kmemdup(ipv6_icmp_table_template,
86592 sizeof(ipv6_icmp_table_template),
86593diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
86594index 131dd09..f7ed64f 100644
86595--- a/net/ipv6/ip6_gre.c
86596+++ b/net/ipv6/ip6_gre.c
86597@@ -73,7 +73,7 @@ struct ip6gre_net {
86598 struct net_device *fb_tunnel_dev;
86599 };
86600
86601-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
86602+static struct rtnl_link_ops ip6gre_link_ops;
86603 static int ip6gre_tunnel_init(struct net_device *dev);
86604 static void ip6gre_tunnel_setup(struct net_device *dev);
86605 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
86606@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
86607 }
86608
86609
86610-static struct inet6_protocol ip6gre_protocol __read_mostly = {
86611+static struct inet6_protocol ip6gre_protocol = {
86612 .handler = ip6gre_rcv,
86613 .err_handler = ip6gre_err,
86614 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
86615@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
86616 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
86617 };
86618
86619-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
86620+static struct rtnl_link_ops ip6gre_link_ops = {
86621 .kind = "ip6gre",
86622 .maxtype = IFLA_GRE_MAX,
86623 .policy = ip6gre_policy,
86624@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
86625 .fill_info = ip6gre_fill_info,
86626 };
86627
86628-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
86629+static struct rtnl_link_ops ip6gre_tap_ops = {
86630 .kind = "ip6gretap",
86631 .maxtype = IFLA_GRE_MAX,
86632 .policy = ip6gre_policy,
86633diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
86634index a14f28b..b4b8956 100644
86635--- a/net/ipv6/ip6_tunnel.c
86636+++ b/net/ipv6/ip6_tunnel.c
86637@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
86638
86639 static int ip6_tnl_dev_init(struct net_device *dev);
86640 static void ip6_tnl_dev_setup(struct net_device *dev);
86641-static struct rtnl_link_ops ip6_link_ops __read_mostly;
86642+static struct rtnl_link_ops ip6_link_ops;
86643
86644 static int ip6_tnl_net_id __read_mostly;
86645 struct ip6_tnl_net {
86646@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
86647 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
86648 };
86649
86650-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
86651+static struct rtnl_link_ops ip6_link_ops = {
86652 .kind = "ip6tnl",
86653 .maxtype = IFLA_IPTUN_MAX,
86654 .policy = ip6_tnl_policy,
86655diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
86656index d1e2e8e..51c19ae 100644
86657--- a/net/ipv6/ipv6_sockglue.c
86658+++ b/net/ipv6/ipv6_sockglue.c
86659@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
86660 if (sk->sk_type != SOCK_STREAM)
86661 return -ENOPROTOOPT;
86662
86663- msg.msg_control = optval;
86664+ msg.msg_control = (void __force_kernel *)optval;
86665 msg.msg_controllen = len;
86666 msg.msg_flags = flags;
86667
86668diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
86669index 125a90d..2a11f36 100644
86670--- a/net/ipv6/netfilter/ip6_tables.c
86671+++ b/net/ipv6/netfilter/ip6_tables.c
86672@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
86673 #endif
86674
86675 static int get_info(struct net *net, void __user *user,
86676- const int *len, int compat)
86677+ int len, int compat)
86678 {
86679 char name[XT_TABLE_MAXNAMELEN];
86680 struct xt_table *t;
86681 int ret;
86682
86683- if (*len != sizeof(struct ip6t_getinfo)) {
86684- duprintf("length %u != %zu\n", *len,
86685+ if (len != sizeof(struct ip6t_getinfo)) {
86686+ duprintf("length %u != %zu\n", len,
86687 sizeof(struct ip6t_getinfo));
86688 return -EINVAL;
86689 }
86690@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
86691 info.size = private->size;
86692 strcpy(info.name, name);
86693
86694- if (copy_to_user(user, &info, *len) != 0)
86695+ if (copy_to_user(user, &info, len) != 0)
86696 ret = -EFAULT;
86697 else
86698 ret = 0;
86699@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86700
86701 switch (cmd) {
86702 case IP6T_SO_GET_INFO:
86703- ret = get_info(sock_net(sk), user, len, 1);
86704+ ret = get_info(sock_net(sk), user, *len, 1);
86705 break;
86706 case IP6T_SO_GET_ENTRIES:
86707 ret = compat_get_entries(sock_net(sk), user, len);
86708@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86709
86710 switch (cmd) {
86711 case IP6T_SO_GET_INFO:
86712- ret = get_info(sock_net(sk), user, len, 0);
86713+ ret = get_info(sock_net(sk), user, *len, 0);
86714 break;
86715
86716 case IP6T_SO_GET_ENTRIES:
86717diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
86718index 3dacecc..2939087 100644
86719--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
86720+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
86721@@ -87,12 +87,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
86722
86723 static int nf_ct_frag6_sysctl_register(struct net *net)
86724 {
86725- struct ctl_table *table;
86726+ ctl_table_no_const *table = NULL;
86727 struct ctl_table_header *hdr;
86728
86729- table = nf_ct_frag6_sysctl_table;
86730 if (!net_eq(net, &init_net)) {
86731- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
86732+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
86733 GFP_KERNEL);
86734 if (table == NULL)
86735 goto err_alloc;
86736@@ -100,9 +99,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86737 table[0].data = &net->ipv6.frags.high_thresh;
86738 table[1].data = &net->ipv6.frags.low_thresh;
86739 table[2].data = &net->ipv6.frags.timeout;
86740- }
86741-
86742- hdr = register_net_sysctl(net, "net/netfilter", table);
86743+ hdr = register_net_sysctl(net, "net/netfilter", table);
86744+ } else
86745+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
86746 if (hdr == NULL)
86747 goto err_reg;
86748
86749@@ -110,8 +109,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86750 return 0;
86751
86752 err_reg:
86753- if (!net_eq(net, &init_net))
86754- kfree(table);
86755+ kfree(table);
86756 err_alloc:
86757 return -ENOMEM;
86758 }
86759diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
86760index 70fa814..d70c28c 100644
86761--- a/net/ipv6/raw.c
86762+++ b/net/ipv6/raw.c
86763@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
86764 {
86765 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
86766 skb_checksum_complete(skb)) {
86767- atomic_inc(&sk->sk_drops);
86768+ atomic_inc_unchecked(&sk->sk_drops);
86769 kfree_skb(skb);
86770 return NET_RX_DROP;
86771 }
86772@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86773 struct raw6_sock *rp = raw6_sk(sk);
86774
86775 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
86776- atomic_inc(&sk->sk_drops);
86777+ atomic_inc_unchecked(&sk->sk_drops);
86778 kfree_skb(skb);
86779 return NET_RX_DROP;
86780 }
86781@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86782
86783 if (inet->hdrincl) {
86784 if (skb_checksum_complete(skb)) {
86785- atomic_inc(&sk->sk_drops);
86786+ atomic_inc_unchecked(&sk->sk_drops);
86787 kfree_skb(skb);
86788 return NET_RX_DROP;
86789 }
86790@@ -604,7 +604,7 @@ out:
86791 return err;
86792 }
86793
86794-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
86795+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
86796 struct flowi6 *fl6, struct dst_entry **dstp,
86797 unsigned int flags)
86798 {
86799@@ -916,12 +916,15 @@ do_confirm:
86800 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
86801 char __user *optval, int optlen)
86802 {
86803+ struct icmp6_filter filter;
86804+
86805 switch (optname) {
86806 case ICMPV6_FILTER:
86807 if (optlen > sizeof(struct icmp6_filter))
86808 optlen = sizeof(struct icmp6_filter);
86809- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
86810+ if (copy_from_user(&filter, optval, optlen))
86811 return -EFAULT;
86812+ raw6_sk(sk)->filter = filter;
86813 return 0;
86814 default:
86815 return -ENOPROTOOPT;
86816@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86817 char __user *optval, int __user *optlen)
86818 {
86819 int len;
86820+ struct icmp6_filter filter;
86821
86822 switch (optname) {
86823 case ICMPV6_FILTER:
86824@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86825 len = sizeof(struct icmp6_filter);
86826 if (put_user(len, optlen))
86827 return -EFAULT;
86828- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
86829+ filter = raw6_sk(sk)->filter;
86830+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
86831 return -EFAULT;
86832 return 0;
86833 default:
86834@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86835 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86836 0,
86837 sock_i_ino(sp),
86838- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86839+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86840 }
86841
86842 static int raw6_seq_show(struct seq_file *seq, void *v)
86843diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
86844index e5253ec..0410257 100644
86845--- a/net/ipv6/reassembly.c
86846+++ b/net/ipv6/reassembly.c
86847@@ -604,12 +604,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
86848
86849 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86850 {
86851- struct ctl_table *table;
86852+ ctl_table_no_const *table = NULL;
86853 struct ctl_table_header *hdr;
86854
86855- table = ip6_frags_ns_ctl_table;
86856 if (!net_eq(net, &init_net)) {
86857- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86858+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86859 if (table == NULL)
86860 goto err_alloc;
86861
86862@@ -620,9 +619,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86863 /* Don't export sysctls to unprivileged users */
86864 if (net->user_ns != &init_user_ns)
86865 table[0].procname = NULL;
86866- }
86867+ hdr = register_net_sysctl(net, "net/ipv6", table);
86868+ } else
86869+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
86870
86871- hdr = register_net_sysctl(net, "net/ipv6", table);
86872 if (hdr == NULL)
86873 goto err_reg;
86874
86875@@ -630,8 +630,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86876 return 0;
86877
86878 err_reg:
86879- if (!net_eq(net, &init_net))
86880- kfree(table);
86881+ kfree(table);
86882 err_alloc:
86883 return -ENOMEM;
86884 }
86885diff --git a/net/ipv6/route.c b/net/ipv6/route.c
86886index 6f9f7b6..2306d63 100644
86887--- a/net/ipv6/route.c
86888+++ b/net/ipv6/route.c
86889@@ -2965,7 +2965,7 @@ ctl_table ipv6_route_table_template[] = {
86890
86891 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
86892 {
86893- struct ctl_table *table;
86894+ ctl_table_no_const *table;
86895
86896 table = kmemdup(ipv6_route_table_template,
86897 sizeof(ipv6_route_table_template),
86898diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
86899index cfba99b..20ca511 100644
86900--- a/net/ipv6/sit.c
86901+++ b/net/ipv6/sit.c
86902@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86903 static int ipip6_tunnel_init(struct net_device *dev);
86904 static void ipip6_tunnel_setup(struct net_device *dev);
86905 static void ipip6_dev_free(struct net_device *dev);
86906-static struct rtnl_link_ops sit_link_ops __read_mostly;
86907+static struct rtnl_link_ops sit_link_ops;
86908
86909 static int sit_net_id __read_mostly;
86910 struct sit_net {
86911@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
86912 #endif
86913 };
86914
86915-static struct rtnl_link_ops sit_link_ops __read_mostly = {
86916+static struct rtnl_link_ops sit_link_ops = {
86917 .kind = "sit",
86918 .maxtype = IFLA_IPTUN_MAX,
86919 .policy = ipip6_policy,
86920diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
86921index e85c48b..b8268d3 100644
86922--- a/net/ipv6/sysctl_net_ipv6.c
86923+++ b/net/ipv6/sysctl_net_ipv6.c
86924@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
86925
86926 static int __net_init ipv6_sysctl_net_init(struct net *net)
86927 {
86928- struct ctl_table *ipv6_table;
86929+ ctl_table_no_const *ipv6_table;
86930 struct ctl_table *ipv6_route_table;
86931 struct ctl_table *ipv6_icmp_table;
86932 int err;
86933diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
86934index 4f435371..5de9da7 100644
86935--- a/net/ipv6/tcp_ipv6.c
86936+++ b/net/ipv6/tcp_ipv6.c
86937@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
86938 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
86939 }
86940
86941+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86942+extern int grsec_enable_blackhole;
86943+#endif
86944+
86945 static void tcp_v6_hash(struct sock *sk)
86946 {
86947 if (sk->sk_state != TCP_CLOSE) {
86948@@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
86949 return 0;
86950
86951 reset:
86952+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86953+ if (!grsec_enable_blackhole)
86954+#endif
86955 tcp_v6_send_reset(sk, skb);
86956 discard:
86957 if (opt_skb)
86958@@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
86959 TCP_SKB_CB(skb)->sacked = 0;
86960
86961 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86962- if (!sk)
86963+ if (!sk) {
86964+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86965+ ret = 1;
86966+#endif
86967 goto no_tcp_socket;
86968+ }
86969
86970 process:
86971- if (sk->sk_state == TCP_TIME_WAIT)
86972+ if (sk->sk_state == TCP_TIME_WAIT) {
86973+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86974+ ret = 2;
86975+#endif
86976 goto do_time_wait;
86977+ }
86978
86979 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
86980 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86981@@ -1568,6 +1583,10 @@ no_tcp_socket:
86982 bad_packet:
86983 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86984 } else {
86985+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86986+ if (!grsec_enable_blackhole || (ret == 1 &&
86987+ (skb->dev->flags & IFF_LOOPBACK)))
86988+#endif
86989 tcp_v6_send_reset(NULL, skb);
86990 }
86991
86992diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
86993index fb08329..2d6919e 100644
86994--- a/net/ipv6/udp.c
86995+++ b/net/ipv6/udp.c
86996@@ -51,6 +51,10 @@
86997 #include <trace/events/skb.h>
86998 #include "udp_impl.h"
86999
87000+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87001+extern int grsec_enable_blackhole;
87002+#endif
87003+
87004 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
87005 {
87006 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
87007@@ -395,7 +399,7 @@ try_again:
87008 if (unlikely(err)) {
87009 trace_kfree_skb(skb, udpv6_recvmsg);
87010 if (!peeked) {
87011- atomic_inc(&sk->sk_drops);
87012+ atomic_inc_unchecked(&sk->sk_drops);
87013 if (is_udp4)
87014 UDP_INC_STATS_USER(sock_net(sk),
87015 UDP_MIB_INERRORS,
87016@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87017 return rc;
87018 drop:
87019 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87020- atomic_inc(&sk->sk_drops);
87021+ atomic_inc_unchecked(&sk->sk_drops);
87022 kfree_skb(skb);
87023 return -1;
87024 }
87025@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87026 if (likely(skb1 == NULL))
87027 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87028 if (!skb1) {
87029- atomic_inc(&sk->sk_drops);
87030+ atomic_inc_unchecked(&sk->sk_drops);
87031 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87032 IS_UDPLITE(sk));
87033 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87034@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87035 goto discard;
87036
87037 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87038+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87039+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87040+#endif
87041 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
87042
87043 kfree_skb(skb);
87044@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
87045 0,
87046 sock_i_ino(sp),
87047 atomic_read(&sp->sk_refcnt), sp,
87048- atomic_read(&sp->sk_drops));
87049+ atomic_read_unchecked(&sp->sk_drops));
87050 }
87051
87052 int udp6_seq_show(struct seq_file *seq, void *v)
87053diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
87054index a68c88c..d55b0c5 100644
87055--- a/net/irda/ircomm/ircomm_tty.c
87056+++ b/net/irda/ircomm/ircomm_tty.c
87057@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87058 add_wait_queue(&port->open_wait, &wait);
87059
87060 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
87061- __FILE__, __LINE__, tty->driver->name, port->count);
87062+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87063
87064 spin_lock_irqsave(&port->lock, flags);
87065 if (!tty_hung_up_p(filp)) {
87066 extra_count = 1;
87067- port->count--;
87068+ atomic_dec(&port->count);
87069 }
87070 spin_unlock_irqrestore(&port->lock, flags);
87071 port->blocked_open++;
87072@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87073 }
87074
87075 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
87076- __FILE__, __LINE__, tty->driver->name, port->count);
87077+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87078
87079 schedule();
87080 }
87081@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87082 if (extra_count) {
87083 /* ++ is not atomic, so this should be protected - Jean II */
87084 spin_lock_irqsave(&port->lock, flags);
87085- port->count++;
87086+ atomic_inc(&port->count);
87087 spin_unlock_irqrestore(&port->lock, flags);
87088 }
87089 port->blocked_open--;
87090
87091 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
87092- __FILE__, __LINE__, tty->driver->name, port->count);
87093+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87094
87095 if (!retval)
87096 port->flags |= ASYNC_NORMAL_ACTIVE;
87097@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
87098
87099 /* ++ is not atomic, so this should be protected - Jean II */
87100 spin_lock_irqsave(&self->port.lock, flags);
87101- self->port.count++;
87102+ atomic_inc(&self->port.count);
87103 spin_unlock_irqrestore(&self->port.lock, flags);
87104 tty_port_tty_set(&self->port, tty);
87105
87106 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
87107- self->line, self->port.count);
87108+ self->line, atomic_read(&self->port.count));
87109
87110 /* Not really used by us, but lets do it anyway */
87111 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
87112@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
87113 tty_kref_put(port->tty);
87114 }
87115 port->tty = NULL;
87116- port->count = 0;
87117+ atomic_set(&port->count, 0);
87118 spin_unlock_irqrestore(&port->lock, flags);
87119
87120 wake_up_interruptible(&port->open_wait);
87121@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
87122 seq_putc(m, '\n');
87123
87124 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
87125- seq_printf(m, "Open count: %d\n", self->port.count);
87126+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
87127 seq_printf(m, "Max data size: %d\n", self->max_data_size);
87128 seq_printf(m, "Max header size: %d\n", self->max_header_size);
87129
87130diff --git a/net/irda/iriap.c b/net/irda/iriap.c
87131index e71e85b..29340a9 100644
87132--- a/net/irda/iriap.c
87133+++ b/net/irda/iriap.c
87134@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
87135 /* case CS_ISO_8859_9: */
87136 /* case CS_UNICODE: */
87137 default:
87138- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
87139- __func__, ias_charset_types[charset]);
87140+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
87141+ __func__, charset,
87142+ charset < ARRAY_SIZE(ias_charset_types) ?
87143+ ias_charset_types[charset] :
87144+ "(unknown)");
87145
87146 /* Aborting, close connection! */
87147 iriap_disconnect_request(self);
87148diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
87149index cd6f7a9..e63fe89 100644
87150--- a/net/iucv/af_iucv.c
87151+++ b/net/iucv/af_iucv.c
87152@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
87153
87154 write_lock_bh(&iucv_sk_list.lock);
87155
87156- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
87157+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
87158 while (__iucv_get_sock_by_name(name)) {
87159 sprintf(name, "%08x",
87160- atomic_inc_return(&iucv_sk_list.autobind_name));
87161+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
87162 }
87163
87164 write_unlock_bh(&iucv_sk_list.lock);
87165diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
87166index df08250..02021fe 100644
87167--- a/net/iucv/iucv.c
87168+++ b/net/iucv/iucv.c
87169@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
87170 return NOTIFY_OK;
87171 }
87172
87173-static struct notifier_block __refdata iucv_cpu_notifier = {
87174+static struct notifier_block iucv_cpu_notifier = {
87175 .notifier_call = iucv_cpu_notify,
87176 };
87177
87178diff --git a/net/key/af_key.c b/net/key/af_key.c
87179index 5b426a6..970032b 100644
87180--- a/net/key/af_key.c
87181+++ b/net/key/af_key.c
87182@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
87183 static u32 get_acqseq(void)
87184 {
87185 u32 res;
87186- static atomic_t acqseq;
87187+ static atomic_unchecked_t acqseq;
87188
87189 do {
87190- res = atomic_inc_return(&acqseq);
87191+ res = atomic_inc_return_unchecked(&acqseq);
87192 } while (!res);
87193 return res;
87194 }
87195diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
87196index 716605c..044e9e1 100644
87197--- a/net/l2tp/l2tp_ppp.c
87198+++ b/net/l2tp/l2tp_ppp.c
87199@@ -355,6 +355,7 @@ static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msgh
87200 l2tp_xmit_skb(session, skb, session->hdr_len);
87201
87202 sock_put(ps->tunnel_sock);
87203+ sock_put(sk);
87204
87205 return error;
87206
87207diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
87208index 0479c64..d031db6 100644
87209--- a/net/mac80211/cfg.c
87210+++ b/net/mac80211/cfg.c
87211@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
87212 ret = ieee80211_vif_use_channel(sdata, chandef,
87213 IEEE80211_CHANCTX_EXCLUSIVE);
87214 }
87215- } else if (local->open_count == local->monitors) {
87216+ } else if (local_read(&local->open_count) == local->monitors) {
87217 local->_oper_channel = chandef->chan;
87218 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
87219 ieee80211_hw_config(local, 0);
87220@@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
87221 else
87222 local->probe_req_reg--;
87223
87224- if (!local->open_count)
87225+ if (!local_read(&local->open_count))
87226 break;
87227
87228 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
87229diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
87230index 2ed065c..948177f 100644
87231--- a/net/mac80211/ieee80211_i.h
87232+++ b/net/mac80211/ieee80211_i.h
87233@@ -28,6 +28,7 @@
87234 #include <net/ieee80211_radiotap.h>
87235 #include <net/cfg80211.h>
87236 #include <net/mac80211.h>
87237+#include <asm/local.h>
87238 #include "key.h"
87239 #include "sta_info.h"
87240 #include "debug.h"
87241@@ -909,7 +910,7 @@ struct ieee80211_local {
87242 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
87243 spinlock_t queue_stop_reason_lock;
87244
87245- int open_count;
87246+ local_t open_count;
87247 int monitors, cooked_mntrs;
87248 /* number of interfaces with corresponding FIF_ flags */
87249 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
87250diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
87251index 8be854e..ad72a69 100644
87252--- a/net/mac80211/iface.c
87253+++ b/net/mac80211/iface.c
87254@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87255 break;
87256 }
87257
87258- if (local->open_count == 0) {
87259+ if (local_read(&local->open_count) == 0) {
87260 res = drv_start(local);
87261 if (res)
87262 goto err_del_bss;
87263@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87264 break;
87265 }
87266
87267- if (local->monitors == 0 && local->open_count == 0) {
87268+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
87269 res = ieee80211_add_virtual_monitor(local);
87270 if (res)
87271 goto err_stop;
87272@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87273 mutex_unlock(&local->mtx);
87274
87275 if (coming_up)
87276- local->open_count++;
87277+ local_inc(&local->open_count);
87278
87279 if (hw_reconf_flags)
87280 ieee80211_hw_config(local, hw_reconf_flags);
87281@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
87282 err_del_interface:
87283 drv_remove_interface(local, sdata);
87284 err_stop:
87285- if (!local->open_count)
87286+ if (!local_read(&local->open_count))
87287 drv_stop(local);
87288 err_del_bss:
87289 sdata->bss = NULL;
87290@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87291 }
87292
87293 if (going_down)
87294- local->open_count--;
87295+ local_dec(&local->open_count);
87296
87297 switch (sdata->vif.type) {
87298 case NL80211_IFTYPE_AP_VLAN:
87299@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87300
87301 ieee80211_recalc_ps(local, -1);
87302
87303- if (local->open_count == 0) {
87304+ if (local_read(&local->open_count) == 0) {
87305 if (local->ops->napi_poll)
87306 napi_disable(&local->napi);
87307 ieee80211_clear_tx_pending(local);
87308@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
87309 }
87310 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
87311
87312- if (local->monitors == local->open_count && local->monitors > 0)
87313+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
87314 ieee80211_add_virtual_monitor(local);
87315 }
87316
87317diff --git a/net/mac80211/main.c b/net/mac80211/main.c
87318index 1b087ff..bf600e9 100644
87319--- a/net/mac80211/main.c
87320+++ b/net/mac80211/main.c
87321@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
87322 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
87323 IEEE80211_CONF_CHANGE_POWER);
87324
87325- if (changed && local->open_count) {
87326+ if (changed && local_read(&local->open_count)) {
87327 ret = drv_config(local, changed);
87328 /*
87329 * Goal:
87330diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
87331index 79a48f3..5e185c9 100644
87332--- a/net/mac80211/pm.c
87333+++ b/net/mac80211/pm.c
87334@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87335 struct sta_info *sta;
87336 struct ieee80211_chanctx *ctx;
87337
87338- if (!local->open_count)
87339+ if (!local_read(&local->open_count))
87340 goto suspend;
87341
87342 ieee80211_scan_cancel(local);
87343@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87344 cancel_work_sync(&local->dynamic_ps_enable_work);
87345 del_timer_sync(&local->dynamic_ps_timer);
87346
87347- local->wowlan = wowlan && local->open_count;
87348+ local->wowlan = wowlan && local_read(&local->open_count);
87349 if (local->wowlan) {
87350 int err = drv_suspend(local, wowlan);
87351 if (err < 0) {
87352@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
87353 mutex_unlock(&local->chanctx_mtx);
87354
87355 /* stop hardware - this must stop RX */
87356- if (local->open_count)
87357+ if (local_read(&local->open_count))
87358 ieee80211_stop_device(local);
87359
87360 suspend:
87361diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
87362index dd88381..eef4dd6 100644
87363--- a/net/mac80211/rate.c
87364+++ b/net/mac80211/rate.c
87365@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
87366
87367 ASSERT_RTNL();
87368
87369- if (local->open_count)
87370+ if (local_read(&local->open_count))
87371 return -EBUSY;
87372
87373 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
87374diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
87375index c97a065..ff61928 100644
87376--- a/net/mac80211/rc80211_pid_debugfs.c
87377+++ b/net/mac80211/rc80211_pid_debugfs.c
87378@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
87379
87380 spin_unlock_irqrestore(&events->lock, status);
87381
87382- if (copy_to_user(buf, pb, p))
87383+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
87384 return -EFAULT;
87385
87386 return p;
87387diff --git a/net/mac80211/util.c b/net/mac80211/util.c
87388index f11e8c5..08d0013 100644
87389--- a/net/mac80211/util.c
87390+++ b/net/mac80211/util.c
87391@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
87392 }
87393 #endif
87394 /* everything else happens only if HW was up & running */
87395- if (!local->open_count)
87396+ if (!local_read(&local->open_count))
87397 goto wake_up;
87398
87399 /*
87400diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
87401index 49e96df..63a51c3 100644
87402--- a/net/netfilter/Kconfig
87403+++ b/net/netfilter/Kconfig
87404@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
87405
87406 To compile it as a module, choose M here. If unsure, say N.
87407
87408+config NETFILTER_XT_MATCH_GRADM
87409+ tristate '"gradm" match support'
87410+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
87411+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
87412+ ---help---
87413+ The gradm match allows to match on grsecurity RBAC being enabled.
87414+ It is useful when iptables rules are applied early on bootup to
87415+ prevent connections to the machine (except from a trusted host)
87416+ while the RBAC system is disabled.
87417+
87418 config NETFILTER_XT_MATCH_HASHLIMIT
87419 tristate '"hashlimit" match support'
87420 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
87421diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
87422index 3259697..54d5393 100644
87423--- a/net/netfilter/Makefile
87424+++ b/net/netfilter/Makefile
87425@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
87426 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
87427 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
87428 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
87429+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
87430 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
87431 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
87432 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
87433diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
87434index 6d6d8f2..a676749 100644
87435--- a/net/netfilter/ipset/ip_set_core.c
87436+++ b/net/netfilter/ipset/ip_set_core.c
87437@@ -1800,7 +1800,7 @@ done:
87438 return ret;
87439 }
87440
87441-static struct nf_sockopt_ops so_set __read_mostly = {
87442+static struct nf_sockopt_ops so_set = {
87443 .pf = PF_INET,
87444 .get_optmin = SO_IP_SET,
87445 .get_optmax = SO_IP_SET + 1,
87446diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
87447index 30e764a..c3b6a9d 100644
87448--- a/net/netfilter/ipvs/ip_vs_conn.c
87449+++ b/net/netfilter/ipvs/ip_vs_conn.c
87450@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
87451 /* Increase the refcnt counter of the dest */
87452 atomic_inc(&dest->refcnt);
87453
87454- conn_flags = atomic_read(&dest->conn_flags);
87455+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
87456 if (cp->protocol != IPPROTO_UDP)
87457 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
87458 flags = cp->flags;
87459@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
87460 atomic_set(&cp->refcnt, 1);
87461
87462 atomic_set(&cp->n_control, 0);
87463- atomic_set(&cp->in_pkts, 0);
87464+ atomic_set_unchecked(&cp->in_pkts, 0);
87465
87466 atomic_inc(&ipvs->conn_count);
87467 if (flags & IP_VS_CONN_F_NO_CPORT)
87468@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
87469
87470 /* Don't drop the entry if its number of incoming packets is not
87471 located in [0, 8] */
87472- i = atomic_read(&cp->in_pkts);
87473+ i = atomic_read_unchecked(&cp->in_pkts);
87474 if (i > 8 || i < 0) return 0;
87475
87476 if (!todrop_rate[i]) return 0;
87477diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
87478index 47edf5a..235b07d 100644
87479--- a/net/netfilter/ipvs/ip_vs_core.c
87480+++ b/net/netfilter/ipvs/ip_vs_core.c
87481@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
87482 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
87483 /* do not touch skb anymore */
87484
87485- atomic_inc(&cp->in_pkts);
87486+ atomic_inc_unchecked(&cp->in_pkts);
87487 ip_vs_conn_put(cp);
87488 return ret;
87489 }
87490@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
87491 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
87492 pkts = sysctl_sync_threshold(ipvs);
87493 else
87494- pkts = atomic_add_return(1, &cp->in_pkts);
87495+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87496
87497 if (ipvs->sync_state & IP_VS_STATE_MASTER)
87498 ip_vs_sync_conn(net, cp, pkts);
87499diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
87500index ec664cb..7f34a77 100644
87501--- a/net/netfilter/ipvs/ip_vs_ctl.c
87502+++ b/net/netfilter/ipvs/ip_vs_ctl.c
87503@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
87504 ip_vs_rs_hash(ipvs, dest);
87505 write_unlock_bh(&ipvs->rs_lock);
87506 }
87507- atomic_set(&dest->conn_flags, conn_flags);
87508+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
87509
87510 /* bind the service */
87511 if (!dest->svc) {
87512@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
87513 * align with netns init in ip_vs_control_net_init()
87514 */
87515
87516-static struct ctl_table vs_vars[] = {
87517+static ctl_table_no_const vs_vars[] __read_only = {
87518 {
87519 .procname = "amemthresh",
87520 .maxlen = sizeof(int),
87521@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
87522 " %-7s %-6d %-10d %-10d\n",
87523 &dest->addr.in6,
87524 ntohs(dest->port),
87525- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
87526+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
87527 atomic_read(&dest->weight),
87528 atomic_read(&dest->activeconns),
87529 atomic_read(&dest->inactconns));
87530@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
87531 "%-7s %-6d %-10d %-10d\n",
87532 ntohl(dest->addr.ip),
87533 ntohs(dest->port),
87534- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
87535+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
87536 atomic_read(&dest->weight),
87537 atomic_read(&dest->activeconns),
87538 atomic_read(&dest->inactconns));
87539@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
87540
87541 entry.addr = dest->addr.ip;
87542 entry.port = dest->port;
87543- entry.conn_flags = atomic_read(&dest->conn_flags);
87544+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
87545 entry.weight = atomic_read(&dest->weight);
87546 entry.u_threshold = dest->u_threshold;
87547 entry.l_threshold = dest->l_threshold;
87548@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
87549 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
87550 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
87551 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
87552- (atomic_read(&dest->conn_flags) &
87553+ (atomic_read_unchecked(&dest->conn_flags) &
87554 IP_VS_CONN_F_FWD_MASK)) ||
87555 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
87556 atomic_read(&dest->weight)) ||
87557@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
87558 {
87559 int idx;
87560 struct netns_ipvs *ipvs = net_ipvs(net);
87561- struct ctl_table *tbl;
87562+ ctl_table_no_const *tbl;
87563
87564 atomic_set(&ipvs->dropentry, 0);
87565 spin_lock_init(&ipvs->dropentry_lock);
87566diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
87567index fdd89b9..bd96aa9 100644
87568--- a/net/netfilter/ipvs/ip_vs_lblc.c
87569+++ b/net/netfilter/ipvs/ip_vs_lblc.c
87570@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
87571 * IPVS LBLC sysctl table
87572 */
87573 #ifdef CONFIG_SYSCTL
87574-static ctl_table vs_vars_table[] = {
87575+static ctl_table_no_const vs_vars_table[] __read_only = {
87576 {
87577 .procname = "lblc_expiration",
87578 .data = NULL,
87579diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
87580index c03b6a3..8ce3681 100644
87581--- a/net/netfilter/ipvs/ip_vs_lblcr.c
87582+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
87583@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
87584 * IPVS LBLCR sysctl table
87585 */
87586
87587-static ctl_table vs_vars_table[] = {
87588+static ctl_table_no_const vs_vars_table[] __read_only = {
87589 {
87590 .procname = "lblcr_expiration",
87591 .data = NULL,
87592diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
87593index 44fd10c..2a163b3 100644
87594--- a/net/netfilter/ipvs/ip_vs_sync.c
87595+++ b/net/netfilter/ipvs/ip_vs_sync.c
87596@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
87597 cp = cp->control;
87598 if (cp) {
87599 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
87600- pkts = atomic_add_return(1, &cp->in_pkts);
87601+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87602 else
87603 pkts = sysctl_sync_threshold(ipvs);
87604 ip_vs_sync_conn(net, cp->control, pkts);
87605@@ -758,7 +758,7 @@ control:
87606 if (!cp)
87607 return;
87608 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
87609- pkts = atomic_add_return(1, &cp->in_pkts);
87610+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
87611 else
87612 pkts = sysctl_sync_threshold(ipvs);
87613 goto sloop;
87614@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
87615
87616 if (opt)
87617 memcpy(&cp->in_seq, opt, sizeof(*opt));
87618- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
87619+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
87620 cp->state = state;
87621 cp->old_state = cp->state;
87622 /*
87623diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
87624index ee6b7a9..f9a89f6 100644
87625--- a/net/netfilter/ipvs/ip_vs_xmit.c
87626+++ b/net/netfilter/ipvs/ip_vs_xmit.c
87627@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
87628 else
87629 rc = NF_ACCEPT;
87630 /* do not touch skb anymore */
87631- atomic_inc(&cp->in_pkts);
87632+ atomic_inc_unchecked(&cp->in_pkts);
87633 goto out;
87634 }
87635
87636@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
87637 else
87638 rc = NF_ACCEPT;
87639 /* do not touch skb anymore */
87640- atomic_inc(&cp->in_pkts);
87641+ atomic_inc_unchecked(&cp->in_pkts);
87642 goto out;
87643 }
87644
87645diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
87646index 7df424e..a527b02 100644
87647--- a/net/netfilter/nf_conntrack_acct.c
87648+++ b/net/netfilter/nf_conntrack_acct.c
87649@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
87650 #ifdef CONFIG_SYSCTL
87651 static int nf_conntrack_acct_init_sysctl(struct net *net)
87652 {
87653- struct ctl_table *table;
87654+ ctl_table_no_const *table;
87655
87656 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
87657 GFP_KERNEL);
87658diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
87659index e4a0c4f..c263f28 100644
87660--- a/net/netfilter/nf_conntrack_core.c
87661+++ b/net/netfilter/nf_conntrack_core.c
87662@@ -1529,6 +1529,10 @@ err_extend:
87663 #define DYING_NULLS_VAL ((1<<30)+1)
87664 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
87665
87666+#ifdef CONFIG_GRKERNSEC_HIDESYM
87667+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
87668+#endif
87669+
87670 static int nf_conntrack_init_net(struct net *net)
87671 {
87672 int ret;
87673@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
87674 goto err_stat;
87675 }
87676
87677+#ifdef CONFIG_GRKERNSEC_HIDESYM
87678+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
87679+#else
87680 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
87681+#endif
87682 if (!net->ct.slabname) {
87683 ret = -ENOMEM;
87684 goto err_slabname;
87685diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
87686index faa978f..1afb18f 100644
87687--- a/net/netfilter/nf_conntrack_ecache.c
87688+++ b/net/netfilter/nf_conntrack_ecache.c
87689@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
87690 #ifdef CONFIG_SYSCTL
87691 static int nf_conntrack_event_init_sysctl(struct net *net)
87692 {
87693- struct ctl_table *table;
87694+ ctl_table_no_const *table;
87695
87696 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
87697 GFP_KERNEL);
87698diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
87699index 884f2b3..d53b33a 100644
87700--- a/net/netfilter/nf_conntrack_helper.c
87701+++ b/net/netfilter/nf_conntrack_helper.c
87702@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
87703
87704 static int nf_conntrack_helper_init_sysctl(struct net *net)
87705 {
87706- struct ctl_table *table;
87707+ ctl_table_no_const *table;
87708
87709 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
87710 GFP_KERNEL);
87711diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
87712index 51e928d..72a413a 100644
87713--- a/net/netfilter/nf_conntrack_proto.c
87714+++ b/net/netfilter/nf_conntrack_proto.c
87715@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
87716
87717 static void
87718 nf_ct_unregister_sysctl(struct ctl_table_header **header,
87719- struct ctl_table **table,
87720+ ctl_table_no_const **table,
87721 unsigned int users)
87722 {
87723 if (users > 0)
87724diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
87725index e7185c6..4ad6c9c 100644
87726--- a/net/netfilter/nf_conntrack_standalone.c
87727+++ b/net/netfilter/nf_conntrack_standalone.c
87728@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
87729
87730 static int nf_conntrack_standalone_init_sysctl(struct net *net)
87731 {
87732- struct ctl_table *table;
87733+ ctl_table_no_const *table;
87734
87735 if (net_eq(net, &init_net)) {
87736 nf_ct_netfilter_header =
87737diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
87738index 7ea8026..bc9512d 100644
87739--- a/net/netfilter/nf_conntrack_timestamp.c
87740+++ b/net/netfilter/nf_conntrack_timestamp.c
87741@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
87742 #ifdef CONFIG_SYSCTL
87743 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
87744 {
87745- struct ctl_table *table;
87746+ ctl_table_no_const *table;
87747
87748 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
87749 GFP_KERNEL);
87750diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
87751index 9e31269..bc4c1b7 100644
87752--- a/net/netfilter/nf_log.c
87753+++ b/net/netfilter/nf_log.c
87754@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
87755
87756 #ifdef CONFIG_SYSCTL
87757 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
87758-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
87759+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
87760 static struct ctl_table_header *nf_log_dir_header;
87761
87762 static int nf_log_proc_dostring(ctl_table *table, int write,
87763@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
87764 rcu_assign_pointer(nf_loggers[tindex], logger);
87765 mutex_unlock(&nf_log_mutex);
87766 } else {
87767+ ctl_table_no_const nf_log_table = *table;
87768+
87769 mutex_lock(&nf_log_mutex);
87770 logger = rcu_dereference_protected(nf_loggers[tindex],
87771 lockdep_is_held(&nf_log_mutex));
87772 if (!logger)
87773- table->data = "NONE";
87774+ nf_log_table.data = "NONE";
87775 else
87776- table->data = logger->name;
87777- r = proc_dostring(table, write, buffer, lenp, ppos);
87778+ nf_log_table.data = logger->name;
87779+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
87780 mutex_unlock(&nf_log_mutex);
87781 }
87782
87783diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
87784index f042ae5..30ea486 100644
87785--- a/net/netfilter/nf_sockopt.c
87786+++ b/net/netfilter/nf_sockopt.c
87787@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
87788 }
87789 }
87790
87791- list_add(&reg->list, &nf_sockopts);
87792+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
87793 out:
87794 mutex_unlock(&nf_sockopt_mutex);
87795 return ret;
87796@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
87797 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
87798 {
87799 mutex_lock(&nf_sockopt_mutex);
87800- list_del(&reg->list);
87801+ pax_list_del((struct list_head *)&reg->list);
87802 mutex_unlock(&nf_sockopt_mutex);
87803 }
87804 EXPORT_SYMBOL(nf_unregister_sockopt);
87805diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
87806index 92fd8ec..3f6ea4b 100644
87807--- a/net/netfilter/nfnetlink_log.c
87808+++ b/net/netfilter/nfnetlink_log.c
87809@@ -72,7 +72,7 @@ struct nfulnl_instance {
87810 };
87811
87812 static DEFINE_SPINLOCK(instances_lock);
87813-static atomic_t global_seq;
87814+static atomic_unchecked_t global_seq;
87815
87816 #define INSTANCE_BUCKETS 16
87817 static struct hlist_head instance_table[INSTANCE_BUCKETS];
87818@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
87819 /* global sequence number */
87820 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
87821 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
87822- htonl(atomic_inc_return(&global_seq))))
87823+ htonl(atomic_inc_return_unchecked(&global_seq))))
87824 goto nla_put_failure;
87825
87826 if (data_len) {
87827diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
87828new file mode 100644
87829index 0000000..c566332
87830--- /dev/null
87831+++ b/net/netfilter/xt_gradm.c
87832@@ -0,0 +1,51 @@
87833+/*
87834+ * gradm match for netfilter
87835